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
33#include <xrpl/beast/utility/Journal.h>
34#include <xrpl/beast/utility/instrumentation.h>
35
36#include <stack>
37#include <vector>
38
39namespace ripple {
40
41class SHAMapNodeID;
42class SHAMapSyncFilter;
43
45enum class SHAMapState {
50 Modifying = 0,
51
56 Immutable = 1,
57
62 Synching = 2,
63
68 Invalid = 3,
69};
70
94class SHAMap
95{
96private:
99
102
105
109 bool backed_ = true; // Map is backed by the database
110 mutable bool full_ = false; // Map is believed complete in database
111
112public:
115 static inline constexpr unsigned int branchFactor =
117
119 static inline constexpr unsigned int leafDepth = 64;
120
122 boost::intrusive_ptr<SHAMapItem const>,
123 boost::intrusive_ptr<SHAMapItem const>>;
125
126 SHAMap() = delete;
127 SHAMap(SHAMap const&) = delete;
128 SHAMap&
129 operator=(SHAMap const&) = delete;
130
131 // Take a snapshot of the given map:
132 SHAMap(SHAMap const& other, bool isMutable);
133
134 // build new map
135 SHAMap(SHAMapType t, Family& f);
136
137 SHAMap(SHAMapType t, uint256 const& hash, Family& f);
138
139 ~SHAMap() = default;
140
141 Family const&
142 family() const
143 {
144 return f_;
145 }
146
147 Family&
149 {
150 return f_;
151 }
152
153 //--------------------------------------------------------------------------
154
159 class const_iterator;
160
162 begin() const;
164 end() const;
165
166 //--------------------------------------------------------------------------
167
168 // Returns a new map that's a snapshot of this one.
169 // Handles copy on write for mutable snapshots.
171 snapShot(bool isMutable) const;
172
173 /* Mark this SHAMap as "should be full", indicating
174 that the local server wants all the corresponding nodes
175 in durable storage.
176 */
177 void
178 setFull();
179
180 void
182
183 bool
184 fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter);
185
186 // normal hash access functions
187
189 bool
190 hasItem(uint256 const& id) const;
191
192 bool
193 delItem(uint256 const& id);
194
195 bool
196 addItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem const> item);
197
199 getHash() const;
200
201 // save a copy if you have a temporary anyway
202 bool
204 SHAMapNodeType type,
205 boost::intrusive_ptr<SHAMapItem const> item);
206
207 bool
209 SHAMapNodeType type,
210 boost::intrusive_ptr<SHAMapItem const> item);
211
212 // Save a copy if you need to extend the life
213 // of the SHAMapItem beyond this SHAMap
214 boost::intrusive_ptr<SHAMapItem const> const&
215 peekItem(uint256 const& id) const;
216 boost::intrusive_ptr<SHAMapItem const> const&
217 peekItem(uint256 const& id, SHAMapHash& hash) const;
218
219 // traverse functions
227 upper_bound(uint256 const& id) const;
228
236 lower_bound(uint256 const& id) const;
237
243 void
244 visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const;
245
252 void
254 SHAMap const* have,
255 std::function<bool(SHAMapTreeNode const&)> const&) const;
256
261 void
264 void(boost::intrusive_ptr<SHAMapItem const> const&)> const&) const;
265
266 // comparison/sync functions
267
279 getMissingNodes(int maxNodes, SHAMapSyncFilter* filter);
280
281 bool
283 SHAMapNodeID const& wanted,
285 bool fatLeaves,
286 std::uint32_t depth) const;
287
295 getProofPath(uint256 const& key) const;
296
304 static bool
306 uint256 const& rootHash,
307 uint256 const& key,
308 std::vector<Blob> const& path);
309
311 void
312 serializeRoot(Serializer& s) const;
313
316 SHAMapHash const& hash,
317 Slice const& rootNode,
318 SHAMapSyncFilter* filter);
321 SHAMapNodeID const& nodeID,
322 Slice const& rawNode,
323 SHAMapSyncFilter* filter);
324
325 // status functions
326 void
327 setImmutable();
328 bool
329 isSynching() const;
330 void
331 setSynching();
332 void
334 bool
335 isValid() const;
336
337 // caution: otherMap must be accessed only by this function
338 // return value: true=successfully completed, false=too different
339 bool
340 compare(SHAMap const& otherMap, Delta& differences, int maxCount) const;
341
343 int
344 unshare();
345
347 int
349
350 void
351 walkMap(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
352 bool
354 std::vector<SHAMapMissingNode>& missingNodes,
355 int maxMissing) const;
356 bool
357 deepCompare(SHAMap& other) const; // Intended for debug/test only
358
359 void
360 setUnbacked();
361
362 void
363 dump(bool withHashes = false) const;
364 void
365 invariants() const;
366
367private:
371 boost::intrusive_ptr<SHAMapItem const>,
372 boost::intrusive_ptr<SHAMapItem const>>;
373
374 // tree node cache operations
376 cacheLookup(SHAMapHash const& hash) const;
377 void
379 const;
380
381 // database operations
383 fetchNodeFromDB(SHAMapHash const& hash) const;
385 fetchNodeNT(SHAMapHash const& hash) const;
387 fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
389 fetchNode(SHAMapHash const& hash) const;
391 checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
392
394 void
395 dirtyUp(
396 SharedPtrNodeStack& stack,
397 uint256 const& target,
399
404 walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack = nullptr)
405 const;
408 findKey(uint256 const& id) const;
409
411 template <class Node>
414
416 template <class Node>
419
423
424 // returns the first item at or below this node
428 SharedPtrNodeStack& stack,
429 int branch = 0) const;
430
431 // returns the last item at or below this node
433 lastBelow(
435 SharedPtrNodeStack& stack,
436 int branch = branchFactor) const;
437
438 // helper function for firstBelow and lastBelow
442 SharedPtrNodeStack& stack,
443 int branch,
445 int,
446 std::function<bool(int)>,
447 std::function<void(int&)>> const& loopParams) const;
448
449 // Simple descent
450 // Get a child of the specified node
452 descend(SHAMapInnerNode*, int branch) const;
454 descendThrow(SHAMapInnerNode*, int branch) const;
456 descend(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
458 descendThrow(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
459
460 // Descend with filter
461 // If pending, callback is called as if it called fetchNodeNT
466 SHAMapInnerNode* parent,
467 int branch,
468 SHAMapSyncFilter* filter,
469 bool& pending,
470 descendCallback&&) const;
471
473 descend(
474 SHAMapInnerNode* parent,
475 SHAMapNodeID const& parentID,
476 int branch,
477 SHAMapSyncFilter* filter) const;
478
479 // Non-storing
480 // Does not hook the returned node to its parent
482 descendNoStore(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
483
485 boost::intrusive_ptr<SHAMapItem const> const&
487
488 bool
489 hasInnerNode(SHAMapNodeID const& nodeID, SHAMapHash const& hash) const;
490 bool
491 hasLeafNode(uint256 const& tag, SHAMapHash const& hash) const;
492
493 SHAMapLeafNode const*
494 peekFirstItem(SharedPtrNodeStack& stack) const;
495 SHAMapLeafNode const*
496 peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const;
497 bool
499 SHAMapTreeNode* node,
500 boost::intrusive_ptr<SHAMapItem const> const& otherMapItem,
501 bool isFirstMap,
502 Delta& differences,
503 int& maxCount) const;
504 int
505 walkSubTree(bool doWrite, NodeObjectType t);
506
507 // Structure to track information about call to
508 // getMissingNodes while it's in progress
510 {
511 MissingNodes() = delete;
512 MissingNodes(const MissingNodes&) = delete;
514 operator=(const MissingNodes&) = delete;
515
516 // basic parameters
517 int max_;
519 int const maxDefer_;
521
522 // nodes we have discovered to be missing
525
526 // nodes we are in the process of traversing
528 SHAMapInnerNode*, // pointer to the node
529 SHAMapNodeID, // the node's ID
530 int, // while child we check first
531 int, // which child we check next
532 bool>; // whether we've found any missing children yet
533
534 // We explicitly choose to specify the use of std::deque here, because
535 // we need to ensure that pointers and/or references to existing
536 // elements will not be invalidated during the course of element
537 // insertion and removal. Containers that do not offer this guarantee,
538 // such as std::vector, can't be used here.
540
541 // nodes we may have acquired from deferred reads
543 SHAMapInnerNode*, // parent node
544 SHAMapNodeID, // parent node ID
545 int, // branch
547
552
553 // nodes we need to resume after we get their children from deferred
554 // reads
556
558 int max,
559 SHAMapSyncFilter* filter,
560 int maxDefer,
561 std::uint32_t generation)
562 : max_(max)
563 , filter_(filter)
564 , maxDefer_(maxDefer)
565 , generation_(generation)
566 , deferred_(0)
567 {
568 missingNodes_.reserve(max);
569 finishedReads_.reserve(maxDefer);
570 }
571 };
572
573 // getMissingNodes helper functions
574 void
575 gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node);
576 void
577 gmn_ProcessDeferredReads(MissingNodes&);
578
579 // fetch from DB helper function
582 SHAMapHash const& hash,
583 std::shared_ptr<NodeObject> const& object) const;
584};
585
586inline void
588{
589 full_ = true;
590}
591
592inline void
594{
595 ledgerSeq_ = lseq;
596}
597
598inline void
600{
601 XRPL_ASSERT(
603 "ripple::SHAMap::setImmutable : state is valid");
605}
606
607inline bool
609{
611}
612
613inline void
615{
617}
618
619inline void
621{
623}
624
625inline bool
627{
629}
630
631inline void
633{
634 backed_ = false;
635}
636
637//------------------------------------------------------------------------------
638
640{
641public:
645 using reference = value_type const&;
646 using pointer = value_type const*;
647
648private:
650 SHAMap const* map_ = nullptr;
651 pointer item_ = nullptr;
652
653public:
654 const_iterator() = delete;
655
656 const_iterator(const_iterator const& other) = default;
658 operator=(const_iterator const& other) = default;
659
660 ~const_iterator() = default;
661
663 operator*() const;
664 pointer
665 operator->() const;
666
668 operator++();
670 operator++(int);
671
672private:
673 explicit const_iterator(SHAMap const* map);
675 const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack);
676
677 friend bool
678 operator==(const_iterator const& x, const_iterator const& y);
679 friend class SHAMap;
680};
681
682inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map)
683{
684 XRPL_ASSERT(
685 map_,
686 "ripple::SHAMap::const_iterator::const_iterator : non-null input");
687
688 if (auto temp = map_->peekFirstItem(stack_))
689 item_ = temp->peekItem().get();
690}
691
693 : map_(map)
694{
695}
696
698 SHAMap const* map,
699 pointer item,
700 SharedPtrNodeStack&& stack)
701 : stack_(std::move(stack)), map_(map), item_(item)
702{
703}
704
707{
708 return *item_;
709}
710
713{
714 return item_;
715}
716
719{
720 if (auto temp = map_->peekNextItem(item_->key(), stack_))
721 item_ = temp->peekItem().get();
722 else
723 item_ = nullptr;
724 return *this;
725}
726
729{
730 auto tmp = *this;
731 ++(*this);
732 return tmp;
733}
734
735inline bool
737{
738 XRPL_ASSERT(
739 x.map_ == y.map_,
740 "ripple::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : "
741 "inputs map do match");
742 return x.item_ == y.item_;
743}
744
745inline bool
747{
748 return !(x == y);
749}
750
751inline SHAMap::const_iterator
753{
754 return const_iterator(this);
755}
756
759{
760 return const_iterator(this, nullptr);
761}
762
763} // namespace ripple
764
765#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:646
SharedPtrNodeStack stack_
Definition: SHAMap.h:649
const_iterator(const_iterator const &other)=default
const_iterator & operator++()
Definition: SHAMap.h:718
reference operator*() const
Definition: SHAMap.h:706
value_type const & reference
Definition: SHAMap.h:645
friend bool operator==(const_iterator const &x, const_iterator const &y)
Definition: SHAMap.h:736
const_iterator & operator=(const_iterator const &other)=default
pointer operator->() const
Definition: SHAMap.h:712
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition: SHAMap.h:95
Family & family()
Definition: SHAMap.h:148
std::shared_ptr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
Definition: SHAMap.cpp:271
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
Definition: SHAMap.cpp:396
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition: SHAMap.cpp:716
bool backed_
Definition: SHAMap.h:109
std::shared_ptr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
Definition: SHAMap.cpp:215
beast::Journal journal_
Definition: SHAMap.h:98
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
Definition: SHAMap.h:119
void dump(bool withHashes=false) const
Definition: SHAMap.cpp:1173
void setUnbacked()
Definition: SHAMap.h:632
SHAMapLeafNode * firstBelow(std::shared_ptr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
Definition: SHAMap.cpp:515
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
Definition: SHAMap.cpp:529
void gmn_ProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
Definition: SHAMapSync.cpp:173
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:294
std::map< uint256, DeltaItem > Delta
Definition: SHAMap.h:124
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, std::shared_ptr< SHAMapTreeNode > terminal)
Update hashes up to the root.
Definition: SHAMap.cpp:95
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition: SHAMap.cpp:618
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:460
SHAMapLeafNode * lastBelow(std::shared_ptr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch=branchFactor) const
Definition: SHAMap.cpp:503
std::shared_ptr< SHAMapTreeNode > writeNode(NodeObjectType t, std::shared_ptr< SHAMapTreeNode > node) const
write and canonicalize modified node
Definition: SHAMap.cpp:991
SHAMapType const type_
Definition: SHAMap.h:108
bool isSynching() const
Definition: SHAMap.h:608
SHAMapState state_
Definition: SHAMap.h:107
bool full_
Definition: SHAMap.h:110
Family const & family() const
Definition: SHAMap.h:142
Family & f_
Definition: SHAMap.h:97
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) const
Definition: SHAMapSync.cpp:432
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:131
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:317
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:582
void clearSynching()
Definition: SHAMap.h:620
std::shared_ptr< Node > preFlushNode(std::shared_ptr< Node > node) const
prepare a node to be modified before flushing
Definition: SHAMap.cpp:1011
std::shared_ptr< SHAMapTreeNode > root_
Definition: SHAMap.h:106
void setImmutable()
Definition: SHAMap.h:599
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:577
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:533
int walkSubTree(bool doWrite, NodeObjectType t)
Definition: SHAMap.cpp:1042
std::shared_ptr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
Definition: SHAMap.cpp:283
void setLedgerSeq(std::uint32_t lseq)
Definition: SHAMap.h:593
const_iterator end() const
Definition: SHAMap.h:758
void invariants() const
Definition: SHAMap.cpp:1243
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
Definition: SHAMapSync.cpp:527
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:641
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
Definition: SHAMapSync.cpp:746
void setFull()
Definition: SHAMap.h:587
~SHAMap()=default
void gmn_ProcessDeferredReads(MissingNodes &)
Definition: SHAMapSync.cpp:264
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
Definition: SHAMap.h:101
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
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:901
std::shared_ptr< SHAMapTreeNode > descendNoStore(std::shared_ptr< SHAMapInnerNode > const &, int branch) const
Definition: SHAMap.cpp:351
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:567
bool isValid() const
Definition: SHAMap.h:626
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
Definition: SHAMapSync.cpp:316
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:770
std::shared_ptr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
Definition: SHAMap.cpp:1218
std::shared_ptr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
Definition: SHAMap.cpp:168
SHAMap & operator=(SHAMap const &)=delete
SHAMap(SHAMap const &)=delete
const_iterator begin() const
Definition: SHAMap.h:752
void setSynching()
Definition: SHAMap.h:614
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
Definition: SHAMap.h:104
void canonicalize(SHAMapHash const &hash, std::shared_ptr< SHAMapTreeNode > &) const
Definition: SHAMap.cpp:1228
bool delItem(uint256 const &id)
Definition: SHAMap.cpp:722
std::shared_ptr< Node > unshareNode(std::shared_ptr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
Definition: SHAMap.cpp:440
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition: SHAMap.cpp:943
const_iterator lower_bound(uint256 const &id) const
Find the object with the greatest object id smaller than the input id.
Definition: SHAMap.cpp:678
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:101
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
Definition: SHAMapSync.cpp:28
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
Definition: SHAMapDelta.cpp:39
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
Definition: SHAMap.cpp:89
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
Definition: SHAMap.cpp:1035
int unshare()
Convert any modified nodes to shared.
Definition: SHAMap.cpp:1028
bool deepCompare(SHAMap &other) const
Definition: SHAMapSync.cpp:674
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
Definition: SHAMapSync.cpp:833
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
Definition: SHAMap.cpp:159
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
Definition: SHAMap.h:115
std::shared_ptr< SHAMapTreeNode > finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
Definition: SHAMap.cpp:176
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
Definition: SHAMapSync.cpp:798
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:45
@ 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:524
std::stack< StackEntry, std::deque< StackEntry > > stack_
Definition: SHAMap.h:539
std::condition_variable deferCondVar_
Definition: SHAMap.h:550
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
Definition: SHAMap.h:532
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
Definition: SHAMap.h:557
MissingNodes(const MissingNodes &)=delete
std::uint32_t generation_
Definition: SHAMap.h:520
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
Definition: SHAMap.h:523
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
Definition: SHAMap.h:555
MissingNodes & operator=(const MissingNodes &)=delete
SHAMapSyncFilter * filter_
Definition: SHAMap.h:518
std::vector< DeferredNode > finishedReads_
Definition: SHAMap.h:551