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 <xrpl/beast/utility/Journal.h>
33#include <xrpl/beast/utility/instrumentation.h>
34
35#include <stack>
36#include <vector>
37
38namespace ripple {
39
40class SHAMapNodeID;
41class SHAMapSyncFilter;
42
44enum class SHAMapState {
49 Modifying = 0,
50
55 Immutable = 1,
56
61 Synching = 2,
62
67 Invalid = 3,
68};
69
93class SHAMap
94{
95private:
98
101
104
108 bool backed_ = true; // Map is backed by the database
109 mutable bool full_ = false; // Map is believed complete in database
110
111public:
114 static inline constexpr unsigned int branchFactor =
116
118 static inline constexpr unsigned int leafDepth = 64;
119
121 boost::intrusive_ptr<SHAMapItem const>,
122 boost::intrusive_ptr<SHAMapItem const>>;
124
125 SHAMap() = delete;
126 SHAMap(SHAMap const&) = delete;
127 SHAMap&
128 operator=(SHAMap const&) = delete;
129
130 // Take a snapshot of the given map:
131 SHAMap(SHAMap const& other, bool isMutable);
132
133 // build new map
134 SHAMap(SHAMapType t, Family& f);
135
136 SHAMap(SHAMapType t, uint256 const& hash, Family& f);
137
138 ~SHAMap() = default;
139
140 Family const&
141 family() const
142 {
143 return f_;
144 }
145
146 Family&
148 {
149 return f_;
150 }
151
152 //--------------------------------------------------------------------------
153
158 class const_iterator;
159
161 begin() const;
163 end() const;
164
165 //--------------------------------------------------------------------------
166
167 // Returns a new map that's a snapshot of this one.
168 // Handles copy on write for mutable snapshots.
170 snapShot(bool isMutable) const;
171
172 /* Mark this SHAMap as "should be full", indicating
173 that the local server wants all the corresponding nodes
174 in durable storage.
175 */
176 void
177 setFull();
178
179 void
181
182 bool
183 fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter);
184
185 // normal hash access functions
186
188 bool
189 hasItem(uint256 const& id) const;
190
191 bool
192 delItem(uint256 const& id);
193
194 bool
195 addItem(SHAMapNodeType type, boost::intrusive_ptr<SHAMapItem const> item);
196
198 getHash() const;
199
200 // save a copy if you have a temporary anyway
201 bool
203 SHAMapNodeType type,
204 boost::intrusive_ptr<SHAMapItem const> item);
205
206 bool
208 SHAMapNodeType type,
209 boost::intrusive_ptr<SHAMapItem const> item);
210
211 // Save a copy if you need to extend the life
212 // of the SHAMapItem beyond this SHAMap
213 boost::intrusive_ptr<SHAMapItem const> const&
214 peekItem(uint256 const& id) const;
215 boost::intrusive_ptr<SHAMapItem const> const&
216 peekItem(uint256 const& id, SHAMapHash& hash) const;
217
218 // traverse functions
226 upper_bound(uint256 const& id) const;
227
235 lower_bound(uint256 const& id) const;
236
242 void
243 visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const;
244
251 void
253 SHAMap const* have,
254 std::function<bool(SHAMapTreeNode const&)> const&) const;
255
260 void
263 void(boost::intrusive_ptr<SHAMapItem const> const&)> const&) const;
264
265 // comparison/sync functions
266
278 getMissingNodes(int maxNodes, SHAMapSyncFilter* filter);
279
280 bool
282 SHAMapNodeID const& wanted,
284 bool fatLeaves,
285 std::uint32_t depth) const;
286
294 getProofPath(uint256 const& key) const;
295
303 static bool
305 uint256 const& rootHash,
306 uint256 const& key,
307 std::vector<Blob> const& path);
308
310 void
311 serializeRoot(Serializer& s) const;
312
315 SHAMapHash const& hash,
316 Slice const& rootNode,
317 SHAMapSyncFilter* filter);
320 SHAMapNodeID const& nodeID,
321 Slice const& rawNode,
322 SHAMapSyncFilter* filter);
323
324 // status functions
325 void
326 setImmutable();
327 bool
328 isSynching() const;
329 void
330 setSynching();
331 void
333 bool
334 isValid() const;
335
336 // caution: otherMap must be accessed only by this function
337 // return value: true=successfully completed, false=too different
338 bool
339 compare(SHAMap const& otherMap, Delta& differences, int maxCount) const;
340
342 int
343 unshare();
344
346 int
348
349 void
350 walkMap(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
351 bool
353 std::vector<SHAMapMissingNode>& missingNodes,
354 int maxMissing) const;
355 bool
356 deepCompare(SHAMap& other) const; // Intended for debug/test only
357
358 void
359 setUnbacked();
360
361 void
362 dump(bool withHashes = false) const;
363 void
364 invariants() const;
365
366private:
370 boost::intrusive_ptr<SHAMapItem const>,
371 boost::intrusive_ptr<SHAMapItem const>>;
372
373 // tree node cache operations
375 cacheLookup(SHAMapHash const& hash) const;
376 void
378 const;
379
380 // database operations
382 fetchNodeFromDB(SHAMapHash const& hash) const;
384 fetchNodeNT(SHAMapHash const& hash) const;
386 fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
388 fetchNode(SHAMapHash const& hash) const;
390 checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
391
393 void
394 dirtyUp(
395 SharedPtrNodeStack& stack,
396 uint256 const& target,
398
403 walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack = nullptr)
404 const;
407 findKey(uint256 const& id) const;
408
410 template <class Node>
413
415 template <class Node>
418
422
423 // returns the first item at or below this node
427 SharedPtrNodeStack& stack,
428 int branch = 0) const;
429
430 // returns the last item at or below this node
432 lastBelow(
434 SharedPtrNodeStack& stack,
435 int branch = branchFactor) const;
436
437 // helper function for firstBelow and lastBelow
441 SharedPtrNodeStack& stack,
442 int branch,
444 int,
445 std::function<bool(int)>,
446 std::function<void(int&)>> const& loopParams) const;
447
448 // Simple descent
449 // Get a child of the specified node
451 descend(SHAMapInnerNode*, int branch) const;
453 descendThrow(SHAMapInnerNode*, int branch) const;
455 descend(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
457 descendThrow(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
458
459 // Descend with filter
460 // If pending, callback is called as if it called fetchNodeNT
465 SHAMapInnerNode* parent,
466 int branch,
467 SHAMapSyncFilter* filter,
468 bool& pending,
469 descendCallback&&) const;
470
472 descend(
473 SHAMapInnerNode* parent,
474 SHAMapNodeID const& parentID,
475 int branch,
476 SHAMapSyncFilter* filter) const;
477
478 // Non-storing
479 // Does not hook the returned node to its parent
481 descendNoStore(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
482
484 boost::intrusive_ptr<SHAMapItem const> const&
486
487 bool
488 hasInnerNode(SHAMapNodeID const& nodeID, SHAMapHash const& hash) const;
489 bool
490 hasLeafNode(uint256 const& tag, SHAMapHash const& hash) const;
491
492 SHAMapLeafNode const*
493 peekFirstItem(SharedPtrNodeStack& stack) const;
494 SHAMapLeafNode const*
495 peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const;
496 bool
498 SHAMapTreeNode* node,
499 boost::intrusive_ptr<SHAMapItem const> const& otherMapItem,
500 bool isFirstMap,
501 Delta& differences,
502 int& maxCount) const;
503 int
504 walkSubTree(bool doWrite, NodeObjectType t);
505
506 // Structure to track information about call to
507 // getMissingNodes while it's in progress
509 {
510 MissingNodes() = delete;
511 MissingNodes(const MissingNodes&) = delete;
513 operator=(const MissingNodes&) = delete;
514
515 // basic parameters
516 int max_;
518 int const maxDefer_;
520
521 // nodes we have discovered to be missing
524
525 // nodes we are in the process of traversing
527 SHAMapInnerNode*, // pointer to the node
528 SHAMapNodeID, // the node's ID
529 int, // while child we check first
530 int, // which child we check next
531 bool>; // whether we've found any missing children yet
532
533 // We explicitly choose to specify the use of std::deque here, because
534 // we need to ensure that pointers and/or references to existing
535 // elements will not be invalidated during the course of element
536 // insertion and removal. Containers that do not offer this guarantee,
537 // such as std::vector, can't be used here.
539
540 // nodes we may have acquired from deferred reads
542 SHAMapInnerNode*, // parent node
543 SHAMapNodeID, // parent node ID
544 int, // branch
546
551
552 // nodes we need to resume after we get their children from deferred
553 // reads
555
557 int max,
558 SHAMapSyncFilter* filter,
559 int maxDefer,
560 std::uint32_t generation)
561 : max_(max)
562 , filter_(filter)
563 , maxDefer_(maxDefer)
564 , generation_(generation)
565 , deferred_(0)
566 {
567 missingNodes_.reserve(max);
568 finishedReads_.reserve(maxDefer);
569 }
570 };
571
572 // getMissingNodes helper functions
573 void
574 gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node);
575 void
576 gmn_ProcessDeferredReads(MissingNodes&);
577
578 // fetch from DB helper function
581 SHAMapHash const& hash,
582 std::shared_ptr<NodeObject> const& object) const;
583};
584
585inline void
587{
588 full_ = true;
589}
590
591inline void
593{
594 ledgerSeq_ = lseq;
595}
596
597inline void
599{
600 XRPL_ASSERT(
602 "ripple::SHAMap::setImmutable : state is valid");
604}
605
606inline bool
608{
610}
611
612inline void
614{
616}
617
618inline void
620{
622}
623
624inline bool
626{
628}
629
630inline void
632{
633 backed_ = false;
634}
635
636//------------------------------------------------------------------------------
637
639{
640public:
644 using reference = value_type const&;
645 using pointer = value_type const*;
646
647private:
649 SHAMap const* map_ = nullptr;
650 pointer item_ = nullptr;
651
652public:
653 const_iterator() = delete;
654
655 const_iterator(const_iterator const& other) = default;
657 operator=(const_iterator const& other) = default;
658
659 ~const_iterator() = default;
660
662 operator*() const;
663 pointer
664 operator->() const;
665
667 operator++();
669 operator++(int);
670
671private:
672 explicit const_iterator(SHAMap const* map);
674 const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack);
675
676 friend bool
677 operator==(const_iterator const& x, const_iterator const& y);
678 friend class SHAMap;
679};
680
681inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map)
682{
683 XRPL_ASSERT(
684 map_,
685 "ripple::SHAMap::const_iterator::const_iterator : non-null input");
686
687 if (auto temp = map_->peekFirstItem(stack_))
688 item_ = temp->peekItem().get();
689}
690
692 : map_(map)
693{
694}
695
697 SHAMap const* map,
698 pointer item,
699 SharedPtrNodeStack&& stack)
700 : stack_(std::move(stack)), map_(map), item_(item)
701{
702}
703
706{
707 return *item_;
708}
709
712{
713 return item_;
714}
715
718{
719 if (auto temp = map_->peekNextItem(item_->key(), stack_))
720 item_ = temp->peekItem().get();
721 else
722 item_ = nullptr;
723 return *this;
724}
725
728{
729 auto tmp = *this;
730 ++(*this);
731 return tmp;
732}
733
734inline bool
736{
737 XRPL_ASSERT(
738 x.map_ == y.map_,
739 "ripple::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : "
740 "inputs map do match");
741 return x.item_ == y.item_;
742}
743
744inline bool
746{
747 return !(x == y);
748}
749
750inline SHAMap::const_iterator
752{
753 return const_iterator(this);
754}
755
758{
759 return const_iterator(this, nullptr);
760}
761
762} // namespace ripple
763
764#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: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:645
SharedPtrNodeStack stack_
Definition: SHAMap.h:648
const_iterator(const_iterator const &other)=default
const_iterator & operator++()
Definition: SHAMap.h:717
reference operator*() const
Definition: SHAMap.h:705
value_type const & reference
Definition: SHAMap.h:644
friend bool operator==(const_iterator const &x, const_iterator const &y)
Definition: SHAMap.h:735
const_iterator & operator=(const_iterator const &other)=default
pointer operator->() const
Definition: SHAMap.h:711
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition: SHAMap.h:94
Family & family()
Definition: SHAMap.h:147
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:108
std::shared_ptr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
Definition: SHAMap.cpp:214
beast::Journal journal_
Definition: SHAMap.h:97
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
Definition: SHAMap.h:118
void dump(bool withHashes=false) const
Definition: SHAMap.cpp:1172
void setUnbacked()
Definition: SHAMap.h:631
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:123
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:107
bool isSynching() const
Definition: SHAMap.h:607
SHAMapState state_
Definition: SHAMap.h:106
bool full_
Definition: SHAMap.h:109
Family const & family() const
Definition: SHAMap.h:141
Family & f_
Definition: SHAMap.h:96
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:619
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:105
void setImmutable()
Definition: SHAMap.h:598
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:592
const_iterator end() const
Definition: SHAMap.h:757
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:586
~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:100
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:625
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:751
void setSynching()
Definition: SHAMap.h:613
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
Definition: SHAMap.h:103
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:114
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: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:44
@ 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:523
std::stack< StackEntry, std::deque< StackEntry > > stack_
Definition: SHAMap.h:538
std::condition_variable deferCondVar_
Definition: SHAMap.h:549
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
Definition: SHAMap.h:531
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
Definition: SHAMap.h:556
MissingNodes(const MissingNodes &)=delete
std::uint32_t generation_
Definition: SHAMap.h:519
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
Definition: SHAMap.h:522
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
Definition: SHAMap.h:554
MissingNodes & operator=(const MissingNodes &)=delete
SHAMapSyncFilter * filter_
Definition: SHAMap.h:517
std::vector< DeferredNode > finishedReads_
Definition: SHAMap.h:550