rippled
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 <ripple/basics/UnorderedContainers.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/nodestore/Database.h>
26 #include <ripple/nodestore/NodeObject.h>
27 #include <ripple/shamap/Family.h>
28 #include <ripple/shamap/FullBelowCache.h>
29 #include <ripple/shamap/SHAMapAddNode.h>
30 #include <ripple/shamap/SHAMapInnerNode.h>
31 #include <ripple/shamap/SHAMapItem.h>
32 #include <ripple/shamap/SHAMapLeafNode.h>
33 #include <ripple/shamap/SHAMapMissingNode.h>
34 #include <ripple/shamap/SHAMapTreeNode.h>
35 #include <ripple/shamap/TreeNodeCache.h>
36 #include <cassert>
37 #include <stack>
38 #include <vector>
39 
40 namespace ripple {
41 
42 class SHAMapNodeID;
43 class SHAMapSyncFilter;
44 
46 enum class SHAMapState {
51  Modifying = 0,
52 
57  Immutable = 1,
58 
63  Synching = 2,
64 
69  Invalid = 3,
70 };
71 
95 class SHAMap
96 {
97 private:
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 
113 public:
116  static inline constexpr unsigned int branchFactor =
118 
120  static inline constexpr unsigned int leafDepth = 64;
121 
122  using DeltaItem = std::pair<
126 
127  SHAMap(SHAMap const&) = delete;
128  SHAMap&
129  operator=(SHAMap const&) = delete;
130 
131  // build new map
132  SHAMap(SHAMapType t, Family& f);
133 
134  SHAMap(SHAMapType t, uint256 const& hash, Family& f);
135 
136  ~SHAMap() = default;
137 
138  Family const&
139  family() const
140  {
141  return f_;
142  }
143 
144  Family&
146  {
147  return f_;
148  }
149 
150  //--------------------------------------------------------------------------
151 
156  class const_iterator;
157 
159  begin() const;
161  end() const;
162 
163  //--------------------------------------------------------------------------
164 
165  // Returns a new map that's a snapshot of this one.
166  // Handles copy on write for mutable snapshots.
168  snapShot(bool isMutable) const;
169 
170  /* Mark this SHAMap as "should be full", indicating
171  that the local server wants all the corresponding nodes
172  in durable storage.
173  */
174  void
175  setFull();
176 
177  void
179 
180  bool
181  fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter);
182 
183  // normal hash access functions
184 
186  bool
187  hasItem(uint256 const& id) const;
188 
189  bool
190  delItem(uint256 const& id);
191 
192  bool
193  addItem(SHAMapNodeType type, SHAMapItem&& i);
194 
195  SHAMapHash
196  getHash() const;
197 
198  // save a copy if you have a temporary anyway
199  bool
201 
202  bool
204 
205  // Save a copy if you need to extend the life
206  // of the SHAMapItem beyond this SHAMap
208  peekItem(uint256 const& id) const;
210  peekItem(uint256 const& id, SHAMapHash& hash) const;
211 
212  // traverse functions
214  upper_bound(uint256 const& id) const;
215 
221  void
222  visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const;
223 
230  void
232  SHAMap const* have,
233  std::function<bool(SHAMapTreeNode const&)>) const;
234 
239  void
240  visitLeaves(
242  const;
243 
244  // comparison/sync functions
245 
257  getMissingNodes(int maxNodes, SHAMapSyncFilter* filter);
258 
259  bool
260  getNodeFat(
261  SHAMapNodeID const& wanted,
262  std::vector<SHAMapNodeID>& nodeIDs,
263  std::vector<Blob>& rawNodes,
264  bool fatLeaves,
265  std::uint32_t depth) const;
266 
274  getProofPath(uint256 const& key) const;
275 
283  static bool
285  uint256 const& rootHash,
286  uint256 const& key,
287  std::vector<Blob> const& path);
288 
290  void
291  serializeRoot(Serializer& s) const;
292 
294  addRootNode(
295  SHAMapHash const& hash,
296  Slice const& rootNode,
297  SHAMapSyncFilter* filter);
299  addKnownNode(
300  SHAMapNodeID const& nodeID,
301  Slice const& rawNode,
302  SHAMapSyncFilter* filter);
303 
304  // status functions
305  void
306  setImmutable();
307  bool
308  isSynching() const;
309  void
310  setSynching();
311  void
312  clearSynching();
313  bool
314  isValid() const;
315 
316  // caution: otherMap must be accessed only by this function
317  // return value: true=successfully completed, false=too different
318  bool
319  compare(SHAMap const& otherMap, Delta& differences, int maxCount) const;
320 
322  int
323  unshare();
324 
326  int
328 
329  void
330  walkMap(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
331  bool
332  deepCompare(SHAMap& other) const; // Intended for debug/test only
333 
334  void
335  setUnbacked();
336 
337  void
338  dump(bool withHashes = false) const;
339  void
340  invariants() const;
341 
342 private:
343  using SharedPtrNodeStack =
345  using DeltaRef = std::pair<
348 
349  // tree node cache operations
351  cacheLookup(SHAMapHash const& hash) const;
352  void
354  const;
355 
356  // database operations
358  fetchNodeFromDB(SHAMapHash const& hash) const;
360  fetchNodeNT(SHAMapHash const& hash) const;
362  fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
364  fetchNode(SHAMapHash const& hash) const;
366  checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
367 
369  void
370  dirtyUp(
371  SharedPtrNodeStack& stack,
372  uint256 const& target,
374 
379  walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack = nullptr)
380  const;
383  findKey(uint256 const& id) const;
384 
386  template <class Node>
389 
391  template <class Node>
394 
398 
400  firstBelow(
402  SharedPtrNodeStack& stack,
403  int branch = 0) const;
404 
405  // Simple descent
406  // Get a child of the specified node
408  descend(SHAMapInnerNode*, int branch) const;
410  descendThrow(SHAMapInnerNode*, int branch) const;
412  descend(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
414  descendThrow(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
415 
416  // Descend with filter
417  // If pending, callback is called as if it called fetchNodeNT
418  using descendCallback =
421  descendAsync(
422  SHAMapInnerNode* parent,
423  int branch,
424  SHAMapSyncFilter* filter,
425  bool& pending,
426  descendCallback&&) const;
427 
429  descend(
430  SHAMapInnerNode* parent,
431  SHAMapNodeID const& parentID,
432  int branch,
433  SHAMapSyncFilter* filter) const;
434 
435  // Non-storing
436  // Does not hook the returned node to its parent
438  descendNoStore(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
439 
442  onlyBelow(SHAMapTreeNode*) const;
443 
444  bool
445  hasInnerNode(SHAMapNodeID const& nodeID, SHAMapHash const& hash) const;
446  bool
447  hasLeafNode(uint256 const& tag, SHAMapHash const& hash) const;
448 
449  SHAMapLeafNode const*
450  peekFirstItem(SharedPtrNodeStack& stack) const;
451  SHAMapLeafNode const*
452  peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const;
453  bool
454  walkBranch(
455  SHAMapTreeNode* node,
456  std::shared_ptr<SHAMapItem const> const& otherMapItem,
457  bool isFirstMap,
458  Delta& differences,
459  int& maxCount) const;
460  int
461  walkSubTree(bool doWrite, NodeObjectType t);
462 
463  // Structure to track information about call to
464  // getMissingNodes while it's in progress
466  {
467  MissingNodes() = delete;
468  MissingNodes(const MissingNodes&) = delete;
469  MissingNodes&
470  operator=(const MissingNodes&) = delete;
471 
472  // basic parameters
473  int max_;
475  int const maxDefer_;
477 
478  // nodes we have discovered to be missing
481 
482  // nodes we are in the process of traversing
483  using StackEntry = std::tuple<
484  SHAMapInnerNode*, // pointer to the node
485  SHAMapNodeID, // the node's ID
486  int, // while child we check first
487  int, // which child we check next
488  bool>; // whether we've found any missing children yet
489 
490  // We explicitly choose to specify the use of std::deque here, because
491  // we need to ensure that pointers and/or references to existing
492  // elements will not be invalidated during the course of element
493  // insertion and removal. Containers that do not offer this guarantee,
494  // such as std::vector, can't be used here.
496 
497  // nodes we may have acquired from deferred reads
498  using DeferredNode = std::tuple<
499  SHAMapInnerNode*, // parent node
500  SHAMapNodeID, // parent node ID
501  int, // branch
503 
508 
509  // nodes we need to resume after we get their children from deferred
510  // reads
512 
514  int max,
515  SHAMapSyncFilter* filter,
516  int maxDefer,
517  std::uint32_t generation)
518  : max_(max)
519  , filter_(filter)
520  , maxDefer_(maxDefer)
521  , generation_(generation)
522  , deferred_(0)
523  {
524  missingNodes_.reserve(max);
525  finishedReads_.reserve(maxDefer);
526  }
527  };
528 
529  // getMissingNodes helper functions
530  void
531  gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node);
532  void
533  gmn_ProcessDeferredReads(MissingNodes&);
534 
535  // fetch from DB helper function
537  finishFetch(
538  SHAMapHash const& hash,
539  std::shared_ptr<NodeObject> const& object) const;
540 };
541 
542 inline void
544 {
545  full_ = true;
546 }
547 
548 inline void
550 {
551  ledgerSeq_ = lseq;
552 }
553 
554 inline void
556 {
557  assert(state_ != SHAMapState::Invalid);
559 }
560 
561 inline bool
563 {
564  return state_ == SHAMapState::Synching;
565 }
566 
567 inline void
569 {
571 }
572 
573 inline void
575 {
577 }
578 
579 inline bool
581 {
582  return state_ != SHAMapState::Invalid;
583 }
584 
585 inline void
587 {
588  backed_ = false;
589 }
590 
591 //------------------------------------------------------------------------------
592 
594 {
595 public:
599  using reference = value_type const&;
600  using pointer = value_type const*;
601 
602 private:
604  SHAMap const* map_ = nullptr;
605  pointer item_ = nullptr;
606 
607 public:
608  const_iterator() = delete;
609 
610  const_iterator(const_iterator const& other) = default;
612  operator=(const_iterator const& other) = default;
613 
614  ~const_iterator() = default;
615 
616  reference
617  operator*() const;
618  pointer
619  operator->() const;
620 
622  operator++();
624  operator++(int);
625 
626 private:
627  explicit const_iterator(SHAMap const* map);
628  const_iterator(SHAMap const* map, std::nullptr_t);
629  const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack);
630 
631  friend bool
632  operator==(const_iterator const& x, const_iterator const& y);
633  friend class SHAMap;
634 };
635 
636 inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map)
637 {
638  assert(map_ != nullptr);
639 
640  if (auto temp = map_->peekFirstItem(stack_))
641  item_ = temp->peekItem().get();
642 }
643 
645  : map_(map)
646 {
647 }
648 
650  SHAMap const* map,
651  pointer item,
652  SharedPtrNodeStack&& stack)
653  : stack_(std::move(stack)), map_(map), item_(item)
654 {
655 }
656 
659 {
660  return *item_;
661 }
662 
665 {
666  return item_;
667 }
668 
671 {
672  if (auto temp = map_->peekNextItem(item_->key(), stack_))
673  item_ = temp->peekItem().get();
674  else
675  item_ = nullptr;
676  return *this;
677 }
678 
681 {
682  auto tmp = *this;
683  ++(*this);
684  return tmp;
685 }
686 
687 inline bool
689 {
690  assert(x.map_ == y.map_);
691  return x.item_ == y.item_;
692 }
693 
694 inline bool
696 {
697  return !(x == y);
698 }
699 
700 inline SHAMap::const_iterator
702 {
703  return const_iterator(this);
704 }
705 
707 SHAMap::end() const
708 {
709  return const_iterator(this, nullptr);
710 }
711 
712 } // namespace ripple
713 
714 #endif
ripple::SHAMap::MissingNodes
Definition: SHAMap.h:465
ripple::SHAMapAddNode
Definition: SHAMapAddNode.h:28
ripple::SHAMap::visitDifferences
void visitDifferences(SHAMap const *have, std::function< bool(SHAMapTreeNode const &)>) const
Visit every node in this SHAMap that is not present in the specified SHAMap.
Definition: SHAMapSync.cpp:100
ripple::SHAMap::invariants
void invariants() const
Definition: SHAMap.cpp:1119
ripple::SHAMap::clearSynching
void clearSynching()
Definition: SHAMap.h:574
ripple::SHAMap::isValid
bool isValid() const
Definition: SHAMap.h:580
ripple::SHAMap::branchFactor
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
Definition: SHAMap.h:116
ripple::SHAMap::descendNoStore
std::shared_ptr< SHAMapTreeNode > descendNoStore(std::shared_ptr< SHAMapInnerNode > const &, int branch) const
Definition: SHAMap.cpp:340
ripple::SHAMap::SHAMap
SHAMap(SHAMap const &)=delete
ripple::SHAMap::MissingNodes::deferLock_
std::mutex deferLock_
Definition: SHAMap.h:505
ripple::SHAMap::peekNextItem
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:532
ripple::Dir::const_iterator
Definition: Directory.h:49
std::shared_ptr
STL class.
ripple::SHAMap::getHash
SHAMapHash getHash() const
Definition: SHAMap.cpp:783
ripple::SHAMap::backed_
bool backed_
Definition: SHAMap.h:110
ripple::SHAMap::type_
const SHAMapType type_
Definition: SHAMap.h:109
ripple::SHAMap::deepCompare
bool deepCompare(SHAMap &other) const
Definition: SHAMapSync.cpp:667
ripple::SHAMap::MissingNodes::stack_
std::stack< StackEntry, std::deque< StackEntry > > stack_
Definition: SHAMap.h:495
ripple::SHAMap::hasInnerNode
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
Definition: SHAMapSync.cpp:739
ripple::SHAMap::MissingNodes::deferred_
int deferred_
Definition: SHAMap.h:504
ripple::SHAMap::family
Family const & family() const
Definition: SHAMap.h:139
ripple::SHAMap::fetchNodeFromDB
std::shared_ptr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
Definition: SHAMap.cpp:163
ripple::SHAMap::addItem
bool addItem(SHAMapNodeType type, SHAMapItem &&i)
Definition: SHAMap.cpp:777
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
std::pair
ripple::SHAMap::MissingNodes::MissingNodes
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
Definition: SHAMap.h:513
ripple::SHAMap::walkSubTree
int walkSubTree(bool doWrite, NodeObjectType t)
Definition: SHAMap.cpp:930
ripple::SHAMap::dump
void dump(bool withHashes=false) const
Definition: SHAMap.cpp:1055
ripple::SHAMap::const_iterator::stack_
SharedPtrNodeStack stack_
Definition: SHAMap.h:603
vector
ripple::NodeObjectType
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
ripple::SHAMap::onlyBelow
std::shared_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
Definition: SHAMap.cpp:482
ripple::SHAMap::getProofPath
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
Definition: SHAMapSync.cpp:791
ripple::SHAMapNodeType
SHAMapNodeType
Definition: SHAMapTreeNode.h:127
ripple::SHAMap::MissingNodes::maxDefer_
const int maxDefer_
Definition: SHAMap.h:475
ripple::SHAMap::MissingNodes::generation_
std::uint32_t generation_
Definition: SHAMap.h:476
stack
ripple::SHAMap::peekItem
std::shared_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition: SHAMap.cpp:561
ripple::SHAMap::serializeRoot
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
Definition: SHAMapSync.cpp:523
ripple::SHAMap::fetchNode
std::shared_ptr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
Definition: SHAMap.cpp:272
std::forward_iterator_tag
ripple::SHAMap::fetchNodeNT
std::shared_ptr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
Definition: SHAMap.cpp:260
ripple::SHAMap::Delta
std::map< uint256, DeltaItem > Delta
Definition: SHAMap.h:125
ripple::SHAMapInnerNode::branchFactor
static constexpr unsigned int branchFactor
Each inner node has 16 children (the 'radix tree' part of the map)
Definition: SHAMapInnerNode.h:44
std::tuple
ripple::SHAMapState::Modifying
@ Modifying
The map is in flux and objects can be added and removed.
ripple::SHAMap::begin
const_iterator begin() const
Definition: SHAMap.h:701
ripple::SHAMap::MissingNodes::finishedReads_
std::vector< DeferredNode > finishedReads_
Definition: SHAMap.h:507
std::function
ripple::SHAMapNodeID
Identifies a node inside a SHAMap.
Definition: SHAMapNodeID.h:33
ripple::SHAMap::MissingNodes::filter_
SHAMapSyncFilter * filter_
Definition: SHAMap.h:474
ripple::SHAMap::snapShot
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
Definition: SHAMap.cpp:70
ripple::Dir::const_iterator::pointer
value_type const * pointer
Definition: Directory.h:53
ripple::SHAMap::gmn_ProcessNodes
void gmn_ProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
Definition: SHAMapSync.cpp:172
ripple::const_iterator
Dir::const_iterator const_iterator
Definition: Directory.cpp:25
ripple::SHAMap::cacheLookup
std::shared_ptr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
Definition: SHAMap.cpp:1098
ripple::SHAMap::const_iterator::operator->
pointer operator->() const
Definition: SHAMap.h:664
ripple::SHAMapLeafNode
Definition: SHAMapLeafNode.h:32
ripple::SHAMap::setFull
void setFull()
Definition: SHAMap.h:543
ripple::SHAMapHash
Definition: SHAMapTreeNode.h:48
ripple::SHAMapState::Synching
@ Synching
The map's hash is fixed but valid nodes may be missing and can be added.
ripple::operator==
bool operator==(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:159
ripple::SHAMap::f_
Family & f_
Definition: SHAMap.h:98
ripple::base_uint< 256 >
std::nullptr_t
ripple::SHAMap::MissingNodes::resumes_
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
Definition: SHAMap.h:511
ripple::SHAMap::hasItem
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition: SHAMap.cpp:624
ripple::SHAMap::const_iterator::operator==
friend bool operator==(const_iterator const &x, const_iterator const &y)
Definition: SHAMap.h:688
ripple::SHAMap::hasLeafNode
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
Definition: SHAMapSync.cpp:763
ripple::SHAMap::operator=
SHAMap & operator=(SHAMap const &)=delete
ripple::SHAMap::const_iterator::~const_iterator
~const_iterator()=default
ripple::SHAMapInnerNode
Definition: SHAMapInnerNode.h:39
ripple::SHAMap::verifyProofPath
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
Definition: SHAMapSync.cpp:826
ripple::SHAMap::peekFirstItem
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:518
ripple::SHAMap::MissingNodes::max_
int max_
Definition: SHAMap.h:473
ripple::SHAMap::visitLeaves
void visitLeaves(std::function< void(std::shared_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
Definition: SHAMapSync.cpp:27
ripple::SHAMapItem
Definition: SHAMapItem.h:31
ripple::SHAMap::isSynching
bool isSynching() const
Definition: SHAMap.h:562
ripple::SHAMap::const_iterator
Definition: SHAMap.h:593
ripple::SHAMap::firstBelow
SHAMapLeafNode * firstBelow(std::shared_ptr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
Definition: SHAMap.cpp:440
ripple::SHAMap
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition: SHAMap.h:95
ripple::SHAMap::const_iterator::operator++
const_iterator & operator++()
Definition: SHAMap.h:670
ripple::operator!=
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:169
ripple::SHAMap::MissingNodes::StackEntry
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
Definition: SHAMap.h:488
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:134
ripple::SHAMap::descendThrow
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:283
ripple::SHAMap::~SHAMap
~SHAMap()=default
ripple::SHAMap::journal_
beast::Journal journal_
Definition: SHAMap.h:99
ripple::SHAMap::canonicalize
void canonicalize(SHAMapHash const &hash, std::shared_ptr< SHAMapTreeNode > &) const
Definition: SHAMap.cpp:1106
ripple::SHAMap::MissingNodes::missingHashes_
std::set< SHAMapHash > missingHashes_
Definition: SHAMap.h:480
ripple::Family
Definition: Family.h:32
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::SHAMap::const_iterator::item_
pointer item_
Definition: SHAMap.h:605
std::uint32_t
std::map
STL class.
ripple::SHAMap::setLedgerSeq
void setLedgerSeq(std::uint32_t lseq)
Definition: SHAMap.h:549
ripple::SHAMap::getMissingNodes
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
Definition: SHAMapSync.cpp:316
ripple::SHAMap::const_iterator::map_
SHAMap const * map_
Definition: SHAMap.h:604
ripple::SHAMap::fetchRoot
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition: SHAMap.cpp:835
ripple::SHAMap::walkMap
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
Definition: SHAMapDelta.cpp:248
ripple::Serializer
Definition: Serializer.h:39
ripple::SHAMap::upper_bound
const_iterator upper_bound(uint256 const &id) const
Definition: SHAMap.cpp:584
ripple::SHAMap::const_iterator::operator*
reference operator*() const
Definition: SHAMap.h:658
ripple::SHAMap::setImmutable
void setImmutable()
Definition: SHAMap.h:555
ripple::SHAMap::finishFetch
std::shared_ptr< SHAMapTreeNode > finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
Definition: SHAMap.cpp:171
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SHAMap::full_
bool full_
Definition: SHAMap.h:111
ripple::SHAMap::checkFilter
std::shared_ptr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
Definition: SHAMap.cpp:204
ripple::SHAMap::dirtyUp
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, std::shared_ptr< SHAMapTreeNode > terminal)
Update hashes up to the root.
Definition: SHAMap.cpp:94
ripple::SHAMap::setUnbacked
void setUnbacked()
Definition: SHAMap.h:586
ripple::SHAMap::MissingNodes::deferCondVar_
std::condition_variable deferCondVar_
Definition: SHAMap.h:506
ripple::SHAMap::findKey
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
Definition: SHAMap.cpp:154
ripple::SHAMap::updateGiveItem
bool updateGiveItem(SHAMapNodeType type, std::shared_ptr< SHAMapItem const >)
Definition: SHAMap.cpp:795
ripple::SHAMap::const_iterator::const_iterator
const_iterator()=delete
ripple::SHAMap::end
const_iterator end() const
Definition: SHAMap.h:707
ripple::SHAMap::walkTowardsKey
SHAMapLeafNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
Definition: SHAMap.cpp:128
std
STL namespace.
cassert
ripple::SHAMap::addGiveItem
bool addGiveItem(SHAMapNodeType type, std::shared_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:708
ripple::SHAMap::unshare
int unshare()
Convert any modified nodes to shared.
Definition: SHAMap.cpp:916
ripple::SHAMap::descendAsync
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
Definition: SHAMap.cpp:380
std::condition_variable
ripple::SHAMap::writeNode
std::shared_ptr< SHAMapTreeNode > writeNode(NodeObjectType t, std::shared_ptr< SHAMapTreeNode > node) const
write and canonicalize modified node
Definition: SHAMap.cpp:881
ripple::SHAMap::leafDepth
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
Definition: SHAMap.h:120
ripple::SHAMap::SharedPtrNodeStack
std::stack< std::pair< std::shared_ptr< SHAMapTreeNode >, SHAMapNodeID > > SharedPtrNodeStack
Definition: SHAMap.h:344
std::ptrdiff_t
ripple::SHAMapState::Immutable
@ Immutable
The map is set in stone and cannot be changed.
ripple::SHAMap::compare
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
Definition: SHAMapDelta.cpp:124
ripple::SHAMapType
SHAMapType
Definition: SHAMapMissingNode.h:32
ripple::SHAMap::visitNodes
void visitNodes(std::function< bool(SHAMapTreeNode &)> const &function) const
Visit every node in this SHAMap.
Definition: SHAMapSync.cpp:39
ripple::SHAMap::gmn_ProcessDeferredReads
void gmn_ProcessDeferredReads(MissingNodes &)
Definition: SHAMapSync.cpp:265
std::optional
std::mutex
STL class.
ripple::SHAMapState::Invalid
@ Invalid
The map is known to not be valid.
ripple::SHAMap::const_iterator::pointer
value_type const * pointer
Definition: SHAMap.h:600
ripple::SHAMap::preFlushNode
std::shared_ptr< Node > preFlushNode(std::shared_ptr< Node > node) const
prepare a node to be modified before flushing
Definition: SHAMap.cpp:900
ripple::SHAMap::addKnownNode
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:571
ripple::SHAMap::flushDirty
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
Definition: SHAMap.cpp:923
ripple::SHAMap::unshareNode
std::shared_ptr< Node > unshareNode(std::shared_ptr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
Definition: SHAMap.cpp:424
ripple::SHAMap::descend
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:306
ripple::SHAMap::MissingNodes::operator=
MissingNodes & operator=(const MissingNodes &)=delete
ripple::SHAMap::addRootNode
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:529
ripple::SHAMap::walkBranch
bool walkBranch(SHAMapTreeNode *node, std::shared_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
Definition: SHAMapDelta.cpp:34
ripple::Dir::const_iterator::reference
value_type const & reference
Definition: Directory.h:54
ripple::SHAMap::ledgerSeq_
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
Definition: SHAMap.h:105
ripple::SHAMap::const_iterator::operator=
const_iterator & operator=(const_iterator const &other)=default
ripple::SHAMap::getNodeFat
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< SHAMapNodeID > &nodeIDs, std::vector< Blob > &rawNodes, bool fatLeaves, std::uint32_t depth) const
Definition: SHAMapSync.cpp:426
ripple::SHAMapSyncFilter
Definition: SHAMapSyncFilter.h:30
ripple::SHAMap::MissingNodes::missingNodes_
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
Definition: SHAMap.h:479
ripple::SHAMap::delItem
bool delItem(uint256 const &id)
Definition: SHAMap.cpp:630
ripple::SHAMap::cowid_
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
Definition: SHAMap.h:102
ripple::SHAMap::MissingNodes::MissingNodes
MissingNodes()=delete
ripple::SHAMap::state_
SHAMapState state_
Definition: SHAMap.h:108
std::set
STL class.
ripple::SHAMap::setSynching
void setSynching()
Definition: SHAMap.h:568
ripple::SHAMap::root_
std::shared_ptr< SHAMapTreeNode > root_
Definition: SHAMap.h:107
ripple::SHAMapState
SHAMapState
Describes the current state of a given SHAMap.
Definition: SHAMap.h:46
ripple::SHAMap::family
Family & family()
Definition: SHAMap.h:145
ripple::SHAMap::const_iterator::reference
value_type const & reference
Definition: SHAMap.h:599