rippled
Loading...
Searching...
No Matches
SHAMap.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
21#define RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
22
23#include <xrpld/nodestore/Database.h>
24#include <xrpld/nodestore/NodeObject.h>
25#include <xrpld/shamap/Family.h>
26#include <xrpld/shamap/SHAMapAddNode.h>
27#include <xrpld/shamap/SHAMapInnerNode.h>
28#include <xrpld/shamap/SHAMapItem.h>
29#include <xrpld/shamap/SHAMapLeafNode.h>
30#include <xrpld/shamap/SHAMapMissingNode.h>
31#include <xrpld/shamap/SHAMapTreeNode.h>
32#include <xrpld/shamap/TreeNodeCache.h>
33
34#include <xrpl/basics/IntrusivePointer.h>
35#include <xrpl/basics/UnorderedContainers.h>
36#include <xrpl/beast/utility/Journal.h>
37#include <xrpl/beast/utility/instrumentation.h>
38
39#include <stack>
40#include <vector>
41
42namespace ripple {
43
44class SHAMapNodeID;
45class SHAMapSyncFilter;
46
48enum class SHAMapState {
53 Modifying = 0,
54
59 Immutable = 1,
60
65 Synching = 2,
66
71 Invalid = 3,
72};
73
97class SHAMap
98{
99private:
102
105
108
112 bool backed_ = true; // Map is backed by the database
113 mutable bool full_ = false; // Map is believed complete in database
114
115public:
118 static inline constexpr unsigned int branchFactor =
120
122 static inline constexpr unsigned int leafDepth = 64;
123
125 boost::intrusive_ptr<SHAMapItem const>,
126 boost::intrusive_ptr<SHAMapItem const>>;
128
129 SHAMap() = delete;
130 SHAMap(SHAMap const&) = delete;
131 SHAMap&
132 operator=(SHAMap const&) = delete;
133
134 // Take a snapshot of the given map:
135 SHAMap(SHAMap const& other, bool isMutable);
136
137 // build new map
138 SHAMap(SHAMapType t, Family& f);
139
140 SHAMap(SHAMapType t, uint256 const& hash, Family& f);
141
142 ~SHAMap() = default;
143
144 Family const&
145 family() const
146 {
147 return f_;
148 }
149
150 Family&
152 {
153 return f_;
154 }
155
156 //--------------------------------------------------------------------------
157
162 class const_iterator;
163
165 begin() const;
167 end() const;
168
169 //--------------------------------------------------------------------------
170
171 // Returns a new map that's a snapshot of this one.
172 // Handles copy on write for mutable snapshots.
174 snapShot(bool isMutable) const;
175
176 /* Mark this SHAMap as "should be full", indicating
177 that the local server wants all the corresponding nodes
178 in durable storage.
179 */
180 void
181 setFull();
182
183 void
185
186 bool
187 fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter);
188
189 // normal hash access functions
190
192 bool
193 hasItem(uint256 const& id) const;
194
195 bool
196 delItem(uint256 const& id);
197
198 bool
199 addItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem const> item);
200
202 getHash() const;
203
204 // save a copy if you have a temporary anyway
205 bool
207 SHAMapNodeType type,
208 boost::intrusive_ptr<SHAMapItem const> item);
209
210 bool
212 SHAMapNodeType type,
213 boost::intrusive_ptr<SHAMapItem const> item);
214
215 // Save a copy if you need to extend the life
216 // of the SHAMapItem beyond this SHAMap
217 boost::intrusive_ptr<SHAMapItem const> const&
218 peekItem(uint256 const& id) const;
219 boost::intrusive_ptr<SHAMapItem const> const&
220 peekItem(uint256 const& id, SHAMapHash& hash) const;
221
222 // traverse functions
230 upper_bound(uint256 const& id) const;
231
239 lower_bound(uint256 const& id) const;
240
246 void
247 visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const;
248
255 void
257 SHAMap const* have,
258 std::function<bool(SHAMapTreeNode const&)> const&) const;
259
264 void
267 void(boost::intrusive_ptr<SHAMapItem const> const&)> const&) const;
268
269 // comparison/sync functions
270
282 getMissingNodes(int maxNodes, SHAMapSyncFilter* filter);
283
284 bool
286 SHAMapNodeID const& wanted,
288 bool fatLeaves,
289 std::uint32_t depth) const;
290
298 getProofPath(uint256 const& key) const;
299
307 static bool
309 uint256 const& rootHash,
310 uint256 const& key,
311 std::vector<Blob> const& path);
312
314 void
315 serializeRoot(Serializer& s) const;
316
319 SHAMapHash const& hash,
320 Slice const& rootNode,
321 SHAMapSyncFilter* filter);
324 SHAMapNodeID const& nodeID,
325 Slice const& rawNode,
326 SHAMapSyncFilter* filter);
327
328 // status functions
329 void
330 setImmutable();
331 bool
332 isSynching() const;
333 void
334 setSynching();
335 void
337 bool
338 isValid() const;
339
340 // caution: otherMap must be accessed only by this function
341 // return value: true=successfully completed, false=too different
342 bool
343 compare(SHAMap const& otherMap, Delta& differences, int maxCount) const;
344
346 int
347 unshare();
348
350 int
352
353 void
354 walkMap(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
355 bool
357 std::vector<SHAMapMissingNode>& missingNodes,
358 int maxMissing) const;
359 bool
360 deepCompare(SHAMap& other) const; // Intended for debug/test only
361
362 void
363 setUnbacked();
364
365 void
366 dump(bool withHashes = false) const;
367 void
368 invariants() const;
369
370private:
374 boost::intrusive_ptr<SHAMapItem const>,
375 boost::intrusive_ptr<SHAMapItem const>>;
376
377 // tree node cache operations
379 cacheLookup(SHAMapHash const& hash) const;
380
381 void
383 const;
384
385 // database operations
387 fetchNodeFromDB(SHAMapHash const& hash) const;
389 fetchNodeNT(SHAMapHash const& hash) const;
391 fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
393 fetchNode(SHAMapHash const& hash) const;
395 checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
396
398 void
399 dirtyUp(
400 SharedPtrNodeStack& stack,
401 uint256 const& target,
403
408 walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack = nullptr)
409 const;
412 findKey(uint256 const& id) const;
413
415 template <class Node>
418
420 template <class Node>
423
427
428 // returns the first item at or below this node
432 SharedPtrNodeStack& stack,
433 int branch = 0) const;
434
435 // returns the last item at or below this node
437 lastBelow(
439 SharedPtrNodeStack& stack,
440 int branch = branchFactor) const;
441
442 // helper function for firstBelow and lastBelow
446 SharedPtrNodeStack& stack,
447 int branch,
449 int,
450 std::function<bool(int)>,
451 std::function<void(int&)>> const& loopParams) const;
452
453 // Simple descent
454 // Get a child of the specified node
456 descend(SHAMapInnerNode*, int branch) const;
458 descendThrow(SHAMapInnerNode*, int branch) const;
460 descend(SHAMapInnerNode&, int branch) const;
462 descendThrow(SHAMapInnerNode&, int branch) const;
463
464 // Descend with filter
465 // If pending, callback is called as if it called fetchNodeNT
470 SHAMapInnerNode* parent,
471 int branch,
472 SHAMapSyncFilter* filter,
473 bool& pending,
474 descendCallback&&) const;
475
477 descend(
478 SHAMapInnerNode* parent,
479 SHAMapNodeID const& parentID,
480 int branch,
481 SHAMapSyncFilter* filter) const;
482
483 // Non-storing
484 // Does not hook the returned node to its parent
486 descendNoStore(SHAMapInnerNode&, int branch) const;
487
489 boost::intrusive_ptr<SHAMapItem const> const&
491
492 bool
493 hasInnerNode(SHAMapNodeID const& nodeID, SHAMapHash const& hash) const;
494 bool
495 hasLeafNode(uint256 const& tag, SHAMapHash const& hash) const;
496
497 SHAMapLeafNode const*
498 peekFirstItem(SharedPtrNodeStack& stack) const;
499 SHAMapLeafNode const*
500 peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const;
501 bool
503 SHAMapTreeNode* node,
504 boost::intrusive_ptr<SHAMapItem const> const& otherMapItem,
505 bool isFirstMap,
506 Delta& differences,
507 int& maxCount) const;
508 int
509 walkSubTree(bool doWrite, NodeObjectType t);
510
511 // Structure to track information about call to
512 // getMissingNodes while it's in progress
514 {
515 MissingNodes() = delete;
516 MissingNodes(MissingNodes const&) = delete;
518 operator=(MissingNodes const&) = delete;
519
520 // basic parameters
521 int max_;
523 int const maxDefer_;
525
526 // nodes we have discovered to be missing
529
530 // nodes we are in the process of traversing
532 SHAMapInnerNode*, // pointer to the node
533 SHAMapNodeID, // the node's ID
534 int, // while child we check first
535 int, // which child we check next
536 bool>; // whether we've found any missing children yet
537
538 // We explicitly choose to specify the use of std::deque here, because
539 // we need to ensure that pointers and/or references to existing
540 // elements will not be invalidated during the course of element
541 // insertion and removal. Containers that do not offer this guarantee,
542 // such as std::vector, can't be used here.
544
545 // nodes we may have acquired from deferred reads
547 SHAMapInnerNode*, // parent node
548 SHAMapNodeID, // parent node ID
549 int, // branch
551
556
557 // nodes we need to resume after we get their children from deferred
558 // reads
560
562 int max,
563 SHAMapSyncFilter* filter,
564 int maxDefer,
565 std::uint32_t generation)
566 : max_(max)
567 , filter_(filter)
568 , maxDefer_(maxDefer)
569 , generation_(generation)
570 , deferred_(0)
571 {
572 missingNodes_.reserve(max);
573 finishedReads_.reserve(maxDefer);
574 }
575 };
576
577 // getMissingNodes helper functions
578 void
579 gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node);
580 void
581 gmn_ProcessDeferredReads(MissingNodes&);
582
583 // fetch from DB helper function
586 SHAMapHash const& hash,
587 std::shared_ptr<NodeObject> const& object) const;
588};
589
590inline void
592{
593 full_ = true;
594}
595
596inline void
598{
599 ledgerSeq_ = lseq;
600}
601
602inline void
604{
605 XRPL_ASSERT(
607 "ripple::SHAMap::setImmutable : state is valid");
609}
610
611inline bool
613{
615}
616
617inline void
619{
621}
622
623inline void
625{
627}
628
629inline bool
631{
633}
634
635inline void
637{
638 backed_ = false;
639}
640
641//------------------------------------------------------------------------------
642
644{
645public:
649 using reference = value_type const&;
650 using pointer = value_type const*;
651
652private:
654 SHAMap const* map_ = nullptr;
655 pointer item_ = nullptr;
656
657public:
658 const_iterator() = delete;
659
660 const_iterator(const_iterator const& other) = default;
662 operator=(const_iterator const& other) = default;
663
664 ~const_iterator() = default;
665
667 operator*() const;
668 pointer
669 operator->() const;
670
672 operator++();
674 operator++(int);
675
676private:
677 explicit const_iterator(SHAMap const* map);
679 const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack);
680
681 friend bool
682 operator==(const_iterator const& x, const_iterator const& y);
683 friend class SHAMap;
684};
685
686inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map)
687{
688 XRPL_ASSERT(
689 map_,
690 "ripple::SHAMap::const_iterator::const_iterator : non-null input");
691
692 if (auto temp = map_->peekFirstItem(stack_))
693 item_ = temp->peekItem().get();
694}
695
697 : map_(map)
698{
699}
700
702 SHAMap const* map,
703 pointer item,
704 SharedPtrNodeStack&& stack)
705 : stack_(std::move(stack)), map_(map), item_(item)
706{
707}
708
711{
712 return *item_;
713}
714
717{
718 return item_;
719}
720
723{
724 if (auto temp = map_->peekNextItem(item_->key(), stack_))
725 item_ = temp->peekItem().get();
726 else
727 item_ = nullptr;
728 return *this;
729}
730
733{
734 auto tmp = *this;
735 ++(*this);
736 return tmp;
737}
738
739inline bool
741{
742 XRPL_ASSERT(
743 x.map_ == y.map_,
744 "ripple::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : "
745 "inputs map do match");
746 return x.item_ == y.item_;
747}
748
749inline bool
751{
752 return !(x == y);
753}
754
755inline SHAMap::const_iterator
757{
758 return const_iterator(this);
759}
760
763{
764 return const_iterator(this, nullptr);
765}
766
767} // namespace ripple
768
769#endif
A generic endpoint for log messages.
Definition: Journal.h:60
const_iterator(ReadView const &view, Keylet const &root, Keylet const &page)
Definition: Dir.h:116
reference operator*() const
Definition: Dir.cpp:70
value_type const & reference
Definition: Dir.h:67
const_iterator & operator++()
Definition: Dir.cpp:81
value_type const * pointer
Definition: Dir.h:66
pointer operator->() const
Definition: Dir.h:84
static constexpr unsigned int branchFactor
Each inner node has 16 children (the 'radix tree' part of the map)
Identifies a node inside a SHAMap.
Definition: SHAMapNodeID.h:34
value_type const * pointer
Definition: SHAMap.h:650
SharedPtrNodeStack stack_
Definition: SHAMap.h:653
const_iterator(const_iterator const &other)=default
const_iterator & operator++()
Definition: SHAMap.h:722
reference operator*() const
Definition: SHAMap.h:710
value_type const & reference
Definition: SHAMap.h:649
friend bool operator==(const_iterator const &x, const_iterator const &y)
Definition: SHAMap.h:740
const_iterator & operator=(const_iterator const &other)=default
pointer operator->() const
Definition: SHAMap.h:716
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition: SHAMap.h:98
intr_ptr::SharedPtr< Node > preFlushNode(intr_ptr::SharedPtr< Node > node) const
prepare a node to be modified before flushing
Definition: SHAMap.cpp:1013
Family & family()
Definition: SHAMap.h:151
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
Definition: SHAMap.cpp:394
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition: SHAMap.cpp:714
bool backed_
Definition: SHAMap.h:112
intr_ptr::SharedPtr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
Definition: SHAMap.cpp:1220
intr_ptr::SharedPtr< Node > unshareNode(intr_ptr::SharedPtr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
Definition: SHAMap.cpp:438
beast::Journal journal_
Definition: SHAMap.h:101
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
Definition: SHAMap.h:122
void dump(bool withHashes=false) const
Definition: SHAMap.cpp:1175
void setUnbacked()
Definition: SHAMap.h:636
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
Definition: SHAMap.cpp:527
void gmn_ProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
Definition: SHAMapSync.cpp:174
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:296
std::map< uint256, DeltaItem > Delta
Definition: SHAMap.h:127
intr_ptr::SharedPtr< SHAMapTreeNode > root_
Definition: SHAMap.h:109
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition: SHAMap.cpp:616
SHAMapType const type_
Definition: SHAMap.h:111
bool isSynching() const
Definition: SHAMap.h:612
SHAMapState state_
Definition: SHAMap.h:110
bool full_
Definition: SHAMap.h:113
Family const & family() const
Definition: SHAMap.h:145
Family & f_
Definition: SHAMap.h:100
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) const
Definition: SHAMapSync.cpp:434
intr_ptr::SharedPtr< SHAMapTreeNode > finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
Definition: SHAMap.cpp:178
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:802
SHAMapLeafNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
Definition: SHAMap.cpp:132
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:318
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:580
void clearSynching()
Definition: SHAMap.h:624
void setImmutable()
Definition: SHAMap.h:603
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:579
void canonicalize(SHAMapHash const &hash, intr_ptr::SharedPtr< SHAMapTreeNode > &) const
Definition: SHAMap.cpp:1230
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:535
int walkSubTree(bool doWrite, NodeObjectType t)
Definition: SHAMap.cpp:1044
void setLedgerSeq(std::uint32_t lseq)
Definition: SHAMap.h:597
const_iterator end() const
Definition: SHAMap.h:762
void invariants() const
Definition: SHAMap.cpp:1245
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
Definition: SHAMapSync.cpp:529
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:881
const_iterator upper_bound(uint256 const &id) const
Find the first item after the given item.
Definition: SHAMap.cpp:639
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
Definition: SHAMapSync.cpp:748
intr_ptr::SharedPtr< SHAMapTreeNode > writeNode(NodeObjectType t, intr_ptr::SharedPtr< SHAMapTreeNode > node) const
write and canonicalize modified node
Definition: SHAMap.cpp:992
void setFull()
Definition: SHAMap.h:591
intr_ptr::SharedPtr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
Definition: SHAMap.cpp:273
~SHAMap()=default
void gmn_ProcessDeferredReads(MissingNodes &)
Definition: SHAMapSync.cpp:266
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
Definition: SHAMap.h:104
SHAMapHash getHash() const
Definition: SHAMap.cpp:889
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
SHAMap()=delete
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, intr_ptr::SharedPtr< SHAMapTreeNode > terminal)
Update hashes up to the root.
Definition: SHAMap.cpp:96
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:901
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:565
bool isValid() const
Definition: SHAMap.h:630
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
Definition: SHAMapSync.cpp:318
intr_ptr::SharedPtr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
Definition: SHAMap.cpp:285
void visitNodes(std::function< bool(SHAMapTreeNode &)> const &function) const
Visit every node in this SHAMap.
Definition: SHAMapSync.cpp:40
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
Definition: SHAMapSync.cpp:772
intr_ptr::SharedPtr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
Definition: SHAMap.cpp:170
SHAMap & operator=(SHAMap const &)=delete
SHAMap(SHAMap const &)=delete
const_iterator begin() const
Definition: SHAMap.h:756
intr_ptr::SharedPtr< SHAMapTreeNode > descendNoStore(SHAMapInnerNode &, int branch) const
Definition: SHAMap.cpp:351
void setSynching()
Definition: SHAMap.h:618
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
Definition: SHAMap.h:107
bool delItem(uint256 const &id)
Definition: SHAMap.cpp:720
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition: SHAMap.cpp:944
const_iterator lower_bound(uint256 const &id) const
Find the object with the greatest object id smaller than the input id.
Definition: SHAMap.cpp:676
void visitDifferences(SHAMap const *have, std::function< bool(SHAMapTreeNode const &)> const &) const
Visit every node in this SHAMap that is not present in the specified SHAMap.
Definition: SHAMapSync.cpp:102
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
Definition: SHAMapSync.cpp:28
SHAMapLeafNode * lastBelow(intr_ptr::SharedPtr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch=branchFactor) const
Definition: SHAMap.cpp:501
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
Definition: SHAMapDelta.cpp:40
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
Definition: SHAMap.cpp:90
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
Definition: SHAMap.cpp:1037
int unshare()
Convert any modified nodes to shared.
Definition: SHAMap.cpp:1030
intr_ptr::SharedPtr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
Definition: SHAMap.cpp:217
bool deepCompare(SHAMap &other) const
Definition: SHAMapSync.cpp:676
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
Definition: SHAMapSync.cpp:836
SHAMapLeafNode * belowHelper(intr_ptr::SharedPtr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch, std::tuple< int, std::function< bool(int)>, std::function< void(int &)> > const &loopParams) const
Definition: SHAMap.cpp:458
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
Definition: SHAMap.cpp:161
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
Definition: SHAMap.h:118
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
Definition: SHAMapSync.cpp:800
SHAMapLeafNode * firstBelow(intr_ptr::SharedPtr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
Definition: SHAMap.cpp:513
A shared intrusive pointer class that supports weak pointers.
An immutable linear range of bytes.
Definition: Slice.h:46
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool operator!=(Buffer const &lhs, Buffer const &rhs) noexcept
Definition: Buffer.h:231
SHAMapState
Describes the current state of a given SHAMap.
Definition: SHAMap.h:48
@ Immutable
The map is set in stone and cannot be changed.
@ Invalid
The map is known to not be valid.
@ Synching
The map's hash is fixed but valid nodes may be missing and can be added.
@ Modifying
The map is in flux and objects can be added and removed.
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
@ pending
List will be valid in the future.
constexpr bool operator==(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition: base_uint.h:585
STL namespace.
std::set< SHAMapHash > missingHashes_
Definition: SHAMap.h:528
std::stack< StackEntry, std::deque< StackEntry > > stack_
Definition: SHAMap.h:543
std::condition_variable deferCondVar_
Definition: SHAMap.h:554
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
Definition: SHAMap.h:536
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
Definition: SHAMap.h:561
std::uint32_t generation_
Definition: SHAMap.h:524
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
Definition: SHAMap.h:527
MissingNodes(MissingNodes const &)=delete
MissingNodes & operator=(MissingNodes const &)=delete
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
Definition: SHAMap.h:559
SHAMapSyncFilter * filter_
Definition: SHAMap.h:522
std::vector< DeferredNode > finishedReads_
Definition: SHAMap.h:555