Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <limits>
5#include <utility>
6#include <variant>
7
14
15namespace bb::world_state {
16
17using namespace bb::crypto::merkle_tree;
18
26
27const uint64_t CANONICAL_FORK_ID = 0;
28const uint64_t NUM_TREES = 5;
29
30std::string getMerkleTreeName(MerkleTreeId id);
31
33using StateReference = std::unordered_map<MerkleTreeId, TreeStateReference>;
34
36 // Sentinel value for `blockNumber` indicating "not pinned to any historical block;
37 // use the latest committed state of the underlying tree". This is distinct from
38 // `blockNumber == 0`, which means "pin to block 0 (the initial / genesis state)".
39 // We use the maximum uint32_t rather than 0 because 0 is a valid historical block
40 // number (the genesis header), and overloading 0 caused silent regressions where
41 // genesis-anchored witnesses would return the current tip instead of genesis.
42 static constexpr block_number_t LATEST = std::numeric_limits<block_number_t>::max();
43
46 bool includeUncommitted{ false };
47
49
52
53 // True when the revision is pinned to a specific historical block rather than the latest state.
54 bool is_historical() const { return blockNumber != LATEST; }
55
56 bool operator==(const WorldStateRevision& other) const = default;
57};
58
65
77 WorldStateStatusSummary(WorldStateStatusSummary&& other) noexcept { *this = std::move(other); }
78
80 {
81 if (this != &other) {
82 *this = other;
83 }
84 return *this;
85 }
86
88
90
97
98 friend std::ostream& operator<<(std::ostream& os, const WorldStateStatusSummary& status)
99 {
100 os << "unfinalizedBlockNumber: " << status.unfinalizedBlockNumber
101 << ", finalizedBlockNumber: " << status.finalizedBlockNumber
102 << ", oldestHistoricalBlock: " << status.oldestHistoricalBlock
103 << ", treesAreSynched: " << status.treesAreSynched;
104 return os;
105 }
106};
107
114
117
118 WorldStateDBStats() = default;
119 WorldStateDBStats(const TreeDBStats& noteHashStats,
120 const TreeDBStats& messageStats,
121 const TreeDBStats& archiveStats,
122 const TreeDBStats& publicDataStats,
123 const TreeDBStats& nullifierStats)
124 : noteHashTreeStats(noteHashStats)
125 , messageTreeStats(messageStats)
126 , archiveTreeStats(archiveStats)
127 , publicDataTreeStats(publicDataStats)
128 , nullifierTreeStats(nullifierStats)
129 {}
130 WorldStateDBStats(const WorldStateDBStats& other) = default;
131 WorldStateDBStats(WorldStateDBStats&& other) noexcept { *this = std::move(other); }
132
134 {
135 if (this != &other) {
136 noteHashTreeStats = std::move(other.noteHashTreeStats);
137 messageTreeStats = std::move(other.messageTreeStats);
138 archiveTreeStats = std::move(other.archiveTreeStats);
139 publicDataTreeStats = std::move(other.publicDataTreeStats);
140 nullifierTreeStats = std::move(other.nullifierTreeStats);
141 }
142 return *this;
143 }
144
146
153
155
156 friend std::ostream& operator<<(std::ostream& os, const WorldStateDBStats& stats)
157 {
158 os << "Note hash tree stats " << stats.noteHashTreeStats << ", Message tree stats " << stats.messageTreeStats
159 << ", Archive tree stats " << stats.archiveTreeStats << ", Public Data tree stats "
160 << stats.publicDataTreeStats << ", Nullifier tree stats " << stats.nullifierTreeStats;
161 return os;
162 }
163};
164
171
173
174 WorldStateMeta() = default;
175 WorldStateMeta(const TreeMeta& noteHashMeta,
176 const TreeMeta& messageMeta,
177 const TreeMeta& archiveMeta,
178 const TreeMeta& publicDataMeta,
179 const TreeMeta& nullifierMeta)
180 : noteHashTreeMeta(noteHashMeta)
181 , messageTreeMeta(messageMeta)
182 , archiveTreeMeta(archiveMeta)
183 , publicDataTreeMeta(publicDataMeta)
184 , nullifierTreeMeta(nullifierMeta)
185 {}
186 WorldStateMeta(const WorldStateMeta& other) = default;
187 WorldStateMeta(WorldStateMeta&& other) noexcept { *this = std::move(other); }
188
190 {
191 if (this != &other) {
192 noteHashTreeMeta = std::move(other.noteHashTreeMeta);
193 messageTreeMeta = std::move(other.messageTreeMeta);
194 archiveTreeMeta = std::move(other.archiveTreeMeta);
195 publicDataTreeMeta = std::move(other.publicDataTreeMeta);
196 nullifierTreeMeta = std::move(other.nullifierTreeMeta);
197 }
198 return *this;
199 }
200
201 ~WorldStateMeta() = default;
202
203 bool operator==(const WorldStateMeta& other) const
204 {
208 }
209
210 WorldStateMeta& operator=(const WorldStateMeta& other) = default;
211
212 friend std::ostream& operator<<(std::ostream& os, const WorldStateMeta& stats)
213 {
214 os << "Note hash tree meta " << stats.noteHashTreeMeta << ", Message tree meta " << stats.messageTreeMeta
215 << ", Archive tree meta " << stats.archiveTreeMeta << ", Public Data tree meta " << stats.publicDataTreeMeta
216 << ", Nullifier tree meta " << stats.nullifierTreeMeta;
217 return os;
218 }
219};
220
225
227
237 WorldStateStatusFull(WorldStateStatusFull&& other) noexcept { *this = std::move(other); }
238
240 {
241 if (this != &other) {
242 summary = std::move(other.summary);
243 dbStats = std::move(other.dbStats);
244 meta = std::move(other.meta);
245 }
246 return *this;
247 }
248
250
252
253 bool operator==(const WorldStateStatusFull& other) const
254 {
255 return summary == other.summary && dbStats == other.dbStats && meta == other.meta;
256 }
257
258 friend std::ostream& operator<<(std::ostream& os, const WorldStateStatusFull& status)
259 {
260 os << "Summary: " << status.summary << ", DB Stats " << status.dbStats << ", Meta " << status.meta;
261 return os;
262 }
263};
264} // namespace bb::world_state
#define SERIALIZATION_FIELDS(...)
Definition msgpack.hpp:121
uint32_t block_number_t
Definition types.hpp:19
@ L1_TO_L2_MESSAGE_TREE
Definition types.hpp:23
std::pair< bb::fr, bb::crypto::merkle_tree::index_t > TreeStateReference
Definition types.hpp:32
const uint64_t CANONICAL_FORK_ID
Definition types.hpp:27
std::string getMerkleTreeName(MerkleTreeId id)
Definition types.cpp:6
std::unordered_map< MerkleTreeId, TreeStateReference > StateReference
Definition types.hpp:33
const uint64_t NUM_TREES
Definition types.hpp:28
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
WorldStateDBStats & operator=(const WorldStateDBStats &other)=default
WorldStateDBStats & operator=(WorldStateDBStats &&other) noexcept
Definition types.hpp:133
WorldStateDBStats(const TreeDBStats &noteHashStats, const TreeDBStats &messageStats, const TreeDBStats &archiveStats, const TreeDBStats &publicDataStats, const TreeDBStats &nullifierStats)
Definition types.hpp:119
bool operator==(const WorldStateDBStats &other) const
Definition types.hpp:147
WorldStateDBStats(WorldStateDBStats &&other) noexcept
Definition types.hpp:131
friend std::ostream & operator<<(std::ostream &os, const WorldStateDBStats &stats)
Definition types.hpp:156
WorldStateDBStats(const WorldStateDBStats &other)=default
SERIALIZATION_FIELDS(noteHashTreeStats, messageTreeStats, archiveTreeStats, publicDataTreeStats, nullifierTreeStats)
friend std::ostream & operator<<(std::ostream &os, const WorldStateMeta &stats)
Definition types.hpp:212
WorldStateMeta & operator=(WorldStateMeta &&other) noexcept
Definition types.hpp:189
WorldStateMeta(WorldStateMeta &&other) noexcept
Definition types.hpp:187
bool operator==(const WorldStateMeta &other) const
Definition types.hpp:203
WorldStateMeta(const WorldStateMeta &other)=default
SERIALIZATION_FIELDS(noteHashTreeMeta, messageTreeMeta, archiveTreeMeta, publicDataTreeMeta, nullifierTreeMeta)
WorldStateMeta & operator=(const WorldStateMeta &other)=default
WorldStateMeta(const TreeMeta &noteHashMeta, const TreeMeta &messageMeta, const TreeMeta &archiveMeta, const TreeMeta &publicDataMeta, const TreeMeta &nullifierMeta)
Definition types.hpp:175
static WorldStateRevision committed()
Definition types.hpp:50
bool operator==(const WorldStateRevision &other) const =default
static constexpr block_number_t LATEST
Definition types.hpp:42
static WorldStateRevision uncommitted()
Definition types.hpp:51
bool operator==(const WorldStateStatusFull &other) const
Definition types.hpp:253
SERIALIZATION_FIELDS(summary, dbStats, meta)
WorldStateStatusFull(const WorldStateStatusSummary &summary, const WorldStateDBStats &dbStats, const WorldStateMeta &meta)
Definition types.hpp:229
WorldStateStatusFull(WorldStateStatusFull &&other) noexcept
Definition types.hpp:237
WorldStateStatusSummary summary
Definition types.hpp:222
WorldStateStatusFull & operator=(const WorldStateStatusFull &other)=default
friend std::ostream & operator<<(std::ostream &os, const WorldStateStatusFull &status)
Definition types.hpp:258
WorldStateStatusFull & operator=(WorldStateStatusFull &&other) noexcept
Definition types.hpp:239
WorldStateStatusFull(const WorldStateStatusFull &other)=default
friend std::ostream & operator<<(std::ostream &os, const WorldStateStatusSummary &status)
Definition types.hpp:98
WorldStateStatusSummary(const WorldStateStatusSummary &other)=default
WorldStateStatusSummary & operator=(const WorldStateStatusSummary &other)=default
WorldStateStatusSummary(const index_t &unfinalizedBlockNumber, const index_t &finalizedBlockNumber, const index_t &oldestHistoricBlock, bool treesAreSynched)
Definition types.hpp:67
WorldStateStatusSummary(WorldStateStatusSummary &&other) noexcept
Definition types.hpp:77
SERIALIZATION_FIELDS(unfinalizedBlockNumber, finalizedBlockNumber, oldestHistoricalBlock, treesAreSynched)
WorldStateStatusSummary & operator=(WorldStateStatusSummary &&other) noexcept
Definition types.hpp:79
bool operator==(const WorldStateStatusSummary &other) const
Definition types.hpp:91