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/FullBelowCache.h>
27#include <xrpld/shamap/SHAMapAddNode.h>
28#include <xrpld/shamap/SHAMapInnerNode.h>
29#include <xrpld/shamap/SHAMapItem.h>
30#include <xrpld/shamap/SHAMapLeafNode.h>
31#include <xrpld/shamap/SHAMapMissingNode.h>
32#include <xrpld/shamap/SHAMapTreeNode.h>
33#include <xrpld/shamap/TreeNodeCache.h>
34#include <xrpl/basics/UnorderedContainers.h>
35#include <xrpl/beast/utility/Journal.h>
36#include <xrpl/beast/utility/instrumentation.h>
37#include <stack>
38#include <vector>
39
40namespace ripple {
41
42class SHAMapNodeID;
43class SHAMapSyncFilter;
44
46enum class SHAMapState {
51 Modifying = 0,
52
57 Immutable = 1,
58
63 Synching = 2,
64
69 Invalid = 3,
70};
71
95class SHAMap
96{
97private:
100
103
106
110 bool backed_ = true; // Map is backed by the database
111 mutable bool full_ = false; // Map is believed complete in database
112
113public:
116 static inline constexpr unsigned int branchFactor =
118
120 static inline constexpr unsigned int leafDepth = 64;
121
123 boost::intrusive_ptr<SHAMapItem const>,
124 boost::intrusive_ptr<SHAMapItem const>>;
126
127 SHAMap() = delete;
128 SHAMap(SHAMap const&) = delete;
129 SHAMap&
130 operator=(SHAMap const&) = delete;
131
132 // Take a snapshot of the given map:
133 SHAMap(SHAMap const& other, bool isMutable);
134
135 // build new map
136 SHAMap(SHAMapType t, Family& f);
137
138 SHAMap(SHAMapType t, uint256 const& hash, Family& f);
139
140 ~SHAMap() = default;
141
142 Family const&
143 family() const
144 {
145 return f_;
146 }
147
148 Family&
150 {
151 return f_;
152 }
153
154 //--------------------------------------------------------------------------
155
160 class const_iterator;
161
163 begin() const;
165 end() const;
166
167 //--------------------------------------------------------------------------
168
169 // Returns a new map that's a snapshot of this one.
170 // Handles copy on write for mutable snapshots.
172 snapShot(bool isMutable) const;
173
174 /* Mark this SHAMap as "should be full", indicating
175 that the local server wants all the corresponding nodes
176 in durable storage.
177 */
178 void
179 setFull();
180
181 void
183
184 bool
185 fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter);
186
187 // normal hash access functions
188
190 bool
191 hasItem(uint256 const& id) const;
192
193 bool
194 delItem(uint256 const& id);
195
196 bool
197 addItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem const> item);
198
200 getHash() const;
201
202 // save a copy if you have a temporary anyway
203 bool
205 SHAMapNodeType type,
206 boost::intrusive_ptr<SHAMapItem const> item);
207
208 bool
210 SHAMapNodeType type,
211 boost::intrusive_ptr<SHAMapItem const> item);
212
213 // Save a copy if you need to extend the life
214 // of the SHAMapItem beyond this SHAMap
215 boost::intrusive_ptr<SHAMapItem const> const&
216 peekItem(uint256 const& id) const;
217 boost::intrusive_ptr<SHAMapItem const> const&
218 peekItem(uint256 const& id, SHAMapHash& hash) const;
219
220 // traverse functions
228 upper_bound(uint256 const& id) const;
229
237 lower_bound(uint256 const& id) const;
238
244 void
245 visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const;
246
253 void
255 SHAMap const* have,
256 std::function<bool(SHAMapTreeNode const&)> const&) const;
257
262 void
265 void(boost::intrusive_ptr<SHAMapItem const> const&)> const&) const;
266
267 // comparison/sync functions
268
280 getMissingNodes(int maxNodes, SHAMapSyncFilter* filter);
281
282 bool
284 SHAMapNodeID const& wanted,
286 bool fatLeaves,
287 std::uint32_t depth) const;
288
296 getProofPath(uint256 const& key) const;
297
305 static bool
307 uint256 const& rootHash,
308 uint256 const& key,
309 std::vector<Blob> const& path);
310
312 void
313 serializeRoot(Serializer& s) const;
314
317 SHAMapHash const& hash,
318 Slice const& rootNode,
319 SHAMapSyncFilter* filter);
322 SHAMapNodeID const& nodeID,
323 Slice const& rawNode,
324 SHAMapSyncFilter* filter);
325
326 // status functions
327 void
328 setImmutable();
329 bool
330 isSynching() const;
331 void
332 setSynching();
333 void
335 bool
336 isValid() const;
337
338 // caution: otherMap must be accessed only by this function
339 // return value: true=successfully completed, false=too different
340 bool
341 compare(SHAMap const& otherMap, Delta& differences, int maxCount) const;
342
344 int
345 unshare();
346
348 int
350
351 void
352 walkMap(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
353 bool
355 std::vector<SHAMapMissingNode>& missingNodes,
356 int maxMissing) const;
357 bool
358 deepCompare(SHAMap& other) const; // Intended for debug/test only
359
360 void
361 setUnbacked();
362
363 void
364 dump(bool withHashes = false) const;
365 void
366 invariants() const;
367
368private:
372 boost::intrusive_ptr<SHAMapItem const>,
373 boost::intrusive_ptr<SHAMapItem const>>;
374
375 // tree node cache operations
377 cacheLookup(SHAMapHash const& hash) const;
378 void
380 const;
381
382 // database operations
384 fetchNodeFromDB(SHAMapHash const& hash) const;
386 fetchNodeNT(SHAMapHash const& hash) const;
388 fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
390 fetchNode(SHAMapHash const& hash) const;
392 checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
393
395 void
396 dirtyUp(
397 SharedPtrNodeStack& stack,
398 uint256 const& target,
400
405 walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack = nullptr)
406 const;
409 findKey(uint256 const& id) const;
410
412 template <class Node>
415
417 template <class Node>
420
424
425 // returns the first item at or below this node
429 SharedPtrNodeStack& stack,
430 int branch = 0) const;
431
432 // returns the last item at or below this node
434 lastBelow(
436 SharedPtrNodeStack& stack,
437 int branch = branchFactor) const;
438
439 // helper function for firstBelow and lastBelow
443 SharedPtrNodeStack& stack,
444 int branch,
446 int,
447 std::function<bool(int)>,
448 std::function<void(int&)>> const& loopParams) const;
449
450 // Simple descent
451 // Get a child of the specified node
453 descend(SHAMapInnerNode*, int branch) const;
455 descendThrow(SHAMapInnerNode*, int branch) const;
457 descend(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
459 descendThrow(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
460
461 // Descend with filter
462 // If pending, callback is called as if it called fetchNodeNT
467 SHAMapInnerNode* parent,
468 int branch,
469 SHAMapSyncFilter* filter,
470 bool& pending,
471 descendCallback&&) const;
472
474 descend(
475 SHAMapInnerNode* parent,
476 SHAMapNodeID const& parentID,
477 int branch,
478 SHAMapSyncFilter* filter) const;
479
480 // Non-storing
481 // Does not hook the returned node to its parent
483 descendNoStore(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
484
486 boost::intrusive_ptr<SHAMapItem const> const&
488
489 bool
490 hasInnerNode(SHAMapNodeID const& nodeID, SHAMapHash const& hash) const;
491 bool
492 hasLeafNode(uint256 const& tag, SHAMapHash const& hash) const;
493
494 SHAMapLeafNode const*
495 peekFirstItem(SharedPtrNodeStack& stack) const;
496 SHAMapLeafNode const*
497 peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const;
498 bool
500 SHAMapTreeNode* node,
501 boost::intrusive_ptr<SHAMapItem const> const& otherMapItem,
502 bool isFirstMap,
503 Delta& differences,
504 int& maxCount) const;
505 int
506 walkSubTree(bool doWrite, NodeObjectType t);
507
508 // Structure to track information about call to
509 // getMissingNodes while it's in progress
511 {
512 MissingNodes() = delete;
513 MissingNodes(const MissingNodes&) = delete;
515 operator=(const MissingNodes&) = delete;
516
517 // basic parameters
518 int max_;
520 int const maxDefer_;
522
523 // nodes we have discovered to be missing
526
527 // nodes we are in the process of traversing
529 SHAMapInnerNode*, // pointer to the node
530 SHAMapNodeID, // the node's ID
531 int, // while child we check first
532 int, // which child we check next
533 bool>; // whether we've found any missing children yet
534
535 // We explicitly choose to specify the use of std::deque here, because
536 // we need to ensure that pointers and/or references to existing
537 // elements will not be invalidated during the course of element
538 // insertion and removal. Containers that do not offer this guarantee,
539 // such as std::vector, can't be used here.
541
542 // nodes we may have acquired from deferred reads
544 SHAMapInnerNode*, // parent node
545 SHAMapNodeID, // parent node ID
546 int, // branch
548
553
554 // nodes we need to resume after we get their children from deferred
555 // reads
557
559 int max,
560 SHAMapSyncFilter* filter,
561 int maxDefer,
562 std::uint32_t generation)
563 : max_(max)
564 , filter_(filter)
565 , maxDefer_(maxDefer)
566 , generation_(generation)
567 , deferred_(0)
568 {
569 missingNodes_.reserve(max);
570 finishedReads_.reserve(maxDefer);
571 }
572 };
573
574 // getMissingNodes helper functions
575 void
576 gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node);
577 void
578 gmn_ProcessDeferredReads(MissingNodes&);
579
580 // fetch from DB helper function
583 SHAMapHash const& hash,
584 std::shared_ptr<NodeObject> const& object) const;
585};
586
587inline void
589{
590 full_ = true;
591}
592
593inline void
595{
596 ledgerSeq_ = lseq;
597}
598
599inline void
601{
602 XRPL_ASSERT(
604 "ripple::SHAMap::setImmutable : state is valid");
606}
607
608inline bool
610{
612}
613
614inline void
616{
618}
619
620inline void
622{
624}
625
626inline bool
628{
630}
631
632inline void
634{
635 backed_ = false;
636}
637
638//------------------------------------------------------------------------------
639
641{
642public:
646 using reference = value_type const&;
647 using pointer = value_type const*;
648
649private:
651 SHAMap const* map_ = nullptr;
652 pointer item_ = nullptr;
653
654public:
655 const_iterator() = delete;
656
657 const_iterator(const_iterator const& other) = default;
659 operator=(const_iterator const& other) = default;
660
661 ~const_iterator() = default;
662
664 operator*() const;
665 pointer
666 operator->() const;
667
669 operator++();
671 operator++(int);
672
673private:
674 explicit const_iterator(SHAMap const* map);
676 const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack);
677
678 friend bool
679 operator==(const_iterator const& x, const_iterator const& y);
680 friend class SHAMap;
681};
682
683inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map)
684{
685 XRPL_ASSERT(
686 map_,
687 "ripple::SHAMap::const_iterator::const_iterator : non-null input");
688
689 if (auto temp = map_->peekFirstItem(stack_))
690 item_ = temp->peekItem().get();
691}
692
694 : map_(map)
695{
696}
697
699 SHAMap const* map,
700 pointer item,
701 SharedPtrNodeStack&& stack)
702 : stack_(std::move(stack)), map_(map), item_(item)
703{
704}
705
708{
709 return *item_;
710}
711
714{
715 return item_;
716}
717
720{
721 if (auto temp = map_->peekNextItem(item_->key(), stack_))
722 item_ = temp->peekItem().get();
723 else
724 item_ = nullptr;
725 return *this;
726}
727
730{
731 auto tmp = *this;
732 ++(*this);
733 return tmp;
734}
735
736inline bool
738{
739 XRPL_ASSERT(
740 x.map_ == y.map_,
741 "ripple::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : "
742 "inputs map do match");
743 return x.item_ == y.item_;
744}
745
746inline bool
748{
749 return !(x == y);
750}
751
752inline SHAMap::const_iterator
754{
755 return const_iterator(this);
756}
757
760{
761 return const_iterator(this, nullptr);
762}
763
764} // namespace ripple
765
766#endif
A generic endpoint for log messages.
Definition: Journal.h:59
const_iterator(ReadView const &view, Keylet const &root, Keylet const &page)
Definition: Dir.h:115
reference operator*() const
Definition: Dir.cpp:70
value_type const & reference
Definition: Dir.h:66
const_iterator & operator++()
Definition: Dir.cpp:81
value_type const * pointer
Definition: Dir.h:65
pointer operator->() const
Definition: Dir.h:83
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:647
SharedPtrNodeStack stack_
Definition: SHAMap.h:650
const_iterator(const_iterator const &other)=default
const_iterator & operator++()
Definition: SHAMap.h:719
reference operator*() const
Definition: SHAMap.h:707
value_type const & reference
Definition: SHAMap.h:646
friend bool operator==(const_iterator const &x, const_iterator const &y)
Definition: SHAMap.h:737
const_iterator & operator=(const_iterator const &other)=default
pointer operator->() const
Definition: SHAMap.h:713
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition: SHAMap.h:96
Family & family()
Definition: SHAMap.h:149
std::shared_ptr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
Definition: SHAMap.cpp:270
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
Definition: SHAMap.cpp:395
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition: SHAMap.cpp:715
bool backed_
Definition: SHAMap.h:110
std::shared_ptr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
Definition: SHAMap.cpp:214
beast::Journal journal_
Definition: SHAMap.h:99
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
Definition: SHAMap.h:120
void dump(bool withHashes=false) const
Definition: SHAMap.cpp:1172
void setUnbacked()
Definition: SHAMap.h:633
SHAMapLeafNode * firstBelow(std::shared_ptr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
Definition: SHAMap.cpp:514
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
Definition: SHAMap.cpp:528
void gmn_ProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
Definition: SHAMapSync.cpp:172
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:293
std::map< uint256, DeltaItem > Delta
Definition: SHAMap.h:125
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, std::shared_ptr< SHAMapTreeNode > terminal)
Update hashes up to the root.
Definition: SHAMap.cpp:94
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition: SHAMap.cpp:617
SHAMapLeafNode * belowHelper(std::shared_ptr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch, std::tuple< int, std::function< bool(int)>, std::function< void(int &)> > const &loopParams) const
Definition: SHAMap.cpp:459
SHAMapLeafNode * lastBelow(std::shared_ptr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch=branchFactor) const
Definition: SHAMap.cpp:502
std::shared_ptr< SHAMapTreeNode > writeNode(NodeObjectType t, std::shared_ptr< SHAMapTreeNode > node) const
write and canonicalize modified node
Definition: SHAMap.cpp:990
SHAMapType const type_
Definition: SHAMap.h:109
bool isSynching() const
Definition: SHAMap.h:609
SHAMapState state_
Definition: SHAMap.h:108
bool full_
Definition: SHAMap.h:111
Family const & family() const
Definition: SHAMap.h:143
Family & f_
Definition: SHAMap.h:98
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) const
Definition: SHAMapSync.cpp:431
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:801
SHAMapLeafNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
Definition: SHAMap.cpp:130
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:316
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:581
void clearSynching()
Definition: SHAMap.h:621
std::shared_ptr< Node > preFlushNode(std::shared_ptr< Node > node) const
prepare a node to be modified before flushing
Definition: SHAMap.cpp:1010
std::shared_ptr< SHAMapTreeNode > root_
Definition: SHAMap.h:107
void setImmutable()
Definition: SHAMap.h:600
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:576
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:532
int walkSubTree(bool doWrite, NodeObjectType t)
Definition: SHAMap.cpp:1041
std::shared_ptr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
Definition: SHAMap.cpp:282
void setLedgerSeq(std::uint32_t lseq)
Definition: SHAMap.h:594
const_iterator end() const
Definition: SHAMap.h:759
void invariants() const
Definition: SHAMap.cpp:1242
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
Definition: SHAMapSync.cpp:526
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:880
const_iterator upper_bound(uint256 const &id) const
Find the first item after the given item.
Definition: SHAMap.cpp:640
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
Definition: SHAMapSync.cpp:745
void setFull()
Definition: SHAMap.h:588
~SHAMap()=default
void gmn_ProcessDeferredReads(MissingNodes &)
Definition: SHAMapSync.cpp:263
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
Definition: SHAMap.h:102
SHAMapHash getHash() const
Definition: SHAMap.cpp:888
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
SHAMap()=delete
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:900
std::shared_ptr< SHAMapTreeNode > descendNoStore(std::shared_ptr< SHAMapInnerNode > const &, int branch) const
Definition: SHAMap.cpp:350
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:566
bool isValid() const
Definition: SHAMap.h:627
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
Definition: SHAMapSync.cpp:315
void visitNodes(std::function< bool(SHAMapTreeNode &)> const &function) const
Visit every node in this SHAMap.
Definition: SHAMapSync.cpp:39
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
Definition: SHAMapSync.cpp:769
std::shared_ptr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
Definition: SHAMap.cpp:1217
std::shared_ptr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
Definition: SHAMap.cpp:167
SHAMap & operator=(SHAMap const &)=delete
SHAMap(SHAMap const &)=delete
const_iterator begin() const
Definition: SHAMap.h:753
void setSynching()
Definition: SHAMap.h:615
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
Definition: SHAMap.h:105
void canonicalize(SHAMapHash const &hash, std::shared_ptr< SHAMapTreeNode > &) const
Definition: SHAMap.cpp:1227
bool delItem(uint256 const &id)
Definition: SHAMap.cpp:721
std::shared_ptr< Node > unshareNode(std::shared_ptr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
Definition: SHAMap.cpp:439
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition: SHAMap.cpp:942
const_iterator lower_bound(uint256 const &id) const
Find the object with the greatest object id smaller than the input id.
Definition: SHAMap.cpp:677
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:100
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
Definition: SHAMapSync.cpp:27
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
Definition: SHAMapDelta.cpp:38
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
Definition: SHAMap.cpp:88
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
Definition: SHAMap.cpp:1034
int unshare()
Convert any modified nodes to shared.
Definition: SHAMap.cpp:1027
bool deepCompare(SHAMap &other) const
Definition: SHAMapSync.cpp:673
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
Definition: SHAMapSync.cpp:832
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
Definition: SHAMap.cpp:158
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
Definition: SHAMap.h:116
std::shared_ptr< SHAMapTreeNode > finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
Definition: SHAMap.cpp:175
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
Definition: SHAMapSync.cpp:797
An immutable linear range of bytes.
Definition: Slice.h:45
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:232
SHAMapState
Describes the current state of a given SHAMap.
Definition: SHAMap.h:46
@ 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:584
STL namespace.
std::set< SHAMapHash > missingHashes_
Definition: SHAMap.h:525
std::stack< StackEntry, std::deque< StackEntry > > stack_
Definition: SHAMap.h:540
std::condition_variable deferCondVar_
Definition: SHAMap.h:551
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
Definition: SHAMap.h:533
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
Definition: SHAMap.h:558
MissingNodes(const MissingNodes &)=delete
std::uint32_t generation_
Definition: SHAMap.h:521
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
Definition: SHAMap.h:524
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
Definition: SHAMap.h:556
MissingNodes & operator=(const MissingNodes &)=delete
SHAMapSyncFilter * filter_
Definition: SHAMap.h:519
std::vector< DeferredNode > finishedReads_
Definition: SHAMap.h:552