Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
11#include "lmdb.h"
12#include <cstdint>
13#include <optional>
15
16using namespace bb::lmdblib;
17
18using index_t = uint64_t;
19using block_number_t = uint32_t;
20using LeafIndexKeyType = uint64_t;
21using BlockMetaKeyType = uint64_t;
23using MetaKeyType = uint8_t;
24
31
32template <typename LeafType> fr preimage_to_key(const LeafType& leaf)
33{
34 return leaf.get_key();
35}
36
37inline fr preimage_to_key(const fr& leaf)
38{
39 return leaf;
40}
41
42template <typename LeafType> bool is_empty(const LeafType& leaf)
43{
44 return leaf.is_empty();
45}
46
47inline bool is_empty(const fr& leaf)
48{
49 return leaf == fr::zero();
50}
51
52template <typename LeafType> constexpr bool requires_preimage_for_key()
53{
54 return true;
55}
56
57template <> constexpr bool requires_preimage_for_key<fr>()
58{
59 return false;
60}
61
62const std::string BLOCKS_DB = "blocks";
63const std::string NODES_DB = "nodes";
64const std::string LEAF_PREIMAGES_DB = "leaf preimages";
65const std::string LEAF_INDICES_DB = "leaf indices";
66const std::string BLOCK_INDICES_DB = "block indices";
67
69 uint64_t mapSize;
76
77 TreeDBStats() = default;
83 uint64_t physicalFileSize,
84 const DBStats& blockStats,
85 const DBStats& nodesStats,
87 const DBStats& leafIndicesStats,
88 const DBStats& blockIndicesStats)
91 , blocksDBStats(blockStats)
92 , nodesDBStats(nodesStats)
94 , leafIndicesDBStats(leafIndicesStats)
95 , blockIndicesDBStats(blockIndicesStats)
96 {}
97 TreeDBStats(const TreeDBStats& other) = default;
98 TreeDBStats(TreeDBStats&& other) noexcept { *this = std::move(other); }
99
100 ~TreeDBStats() = default;
101
109
110 bool operator==(const TreeDBStats& other) const
111 {
112 return mapSize == other.mapSize && physicalFileSize == other.physicalFileSize &&
116 }
117
118 TreeDBStats& operator=(TreeDBStats&& other) noexcept
119 {
120 if (this != &other) {
121 mapSize = other.mapSize;
122 physicalFileSize = other.physicalFileSize;
123 blocksDBStats = std::move(other.blocksDBStats);
124 nodesDBStats = std::move(other.nodesDBStats);
125 leafPreimagesDBStats = std::move(other.leafPreimagesDBStats);
126 leafIndicesDBStats = std::move(other.leafIndicesDBStats);
127 blockIndicesDBStats = std::move(other.blockIndicesDBStats);
128 }
129 return *this;
130 }
131
132 TreeDBStats& operator=(const TreeDBStats& other) = default;
133
134 friend std::ostream& operator<<(std::ostream& os, const TreeDBStats& stats)
135 {
136 os << "Map Size: " << stats.mapSize << ", Physical File Size: " << stats.physicalFileSize << " Blocks DB "
137 << stats.blocksDBStats << ", Nodes DB " << stats.nodesDBStats << ", Leaf Pre-images DB "
138 << stats.leafPreimagesDBStats << ", Leaf Indices DB " << stats.leafIndicesDBStats << ", Block Indices DB "
139 << stats.blockIndicesDBStats;
140 return os;
141 }
142};
143
144std::ostream& operator<<(std::ostream& os, const TreeDBStats& stats);
145} // namespace bb::crypto::merkle_tree
const std::string LEAF_PREIMAGES_DB
Definition types.hpp:64
const std::string NODES_DB
Definition types.hpp:63
uint32_t block_number_t
Definition types.hpp:19
fr preimage_to_key(const LeafType &leaf)
Definition types.hpp:32
uint64_t BlockMetaKeyType
Definition types.hpp:21
bool is_empty(const LeafType &leaf)
Definition types.hpp:42
const std::string BLOCK_INDICES_DB
Definition types.hpp:66
constexpr bool requires_preimage_for_key()
Definition types.hpp:52
uint64_t LeafIndexKeyType
Definition types.hpp:20
const std::string BLOCKS_DB
Definition types.hpp:62
constexpr bool requires_preimage_for_key< fr >()
Definition types.hpp:57
std::ostream & operator<<(std::ostream &os, const BlockPayload &block)
const std::string LEAF_INDICES_DB
Definition types.hpp:65
bool operator==(ecdsa_signature const &lhs, ecdsa_signature const &rhs)
Definition ecdsa.hpp:45
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::optional< index_t > maxIndex
Definition types.hpp:29
std::optional< block_number_t > blockNumber
Definition types.hpp:27
TreeDBStats(uint64_t mapSize, uint64_t physicalFileSize)
Definition types.hpp:78
MSGPACK_FIELDS(mapSize, physicalFileSize, blocksDBStats, nodesDBStats, leafPreimagesDBStats, leafIndicesDBStats, blockIndicesDBStats) bool operator
TreeDBStats(uint64_t mapSize, uint64_t physicalFileSize, const DBStats &blockStats, const DBStats &nodesStats, const DBStats &leafPreimagesDBStats, const DBStats &leafIndicesStats, const DBStats &blockIndicesStats)
Definition types.hpp:82
TreeDBStats(const TreeDBStats &other)=default
TreeDBStats(TreeDBStats &&other) noexcept
Definition types.hpp:98
friend std::ostream & operator<<(std::ostream &os, const TreeDBStats &stats)
Definition types.hpp:134
static constexpr field zero()