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<
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 
199  SHAMapHash
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
209  addGiveItem(
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
263  visitLeaves(
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
283  getNodeFat(
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 
316  addRootNode(
317  SHAMapHash const& hash,
318  Slice const& rootNode,
319  SHAMapSyncFilter* filter);
321  addKnownNode(
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
334  clearSynching();
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 
368 private:
369  using SharedPtrNodeStack =
371  using DeltaRef = std::pair<
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
427  firstBelow(
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
441  belowHelper(
443  SharedPtrNodeStack& stack,
444  int branch,
445  std::tuple<
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
463  using descendCallback =
466  descendAsync(
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&
487  onlyBelow(SHAMapTreeNode*) 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
499  walkBranch(
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;
514  MissingNodes&
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
528  using StackEntry = std::tuple<
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
543  using DeferredNode = std::tuple<
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
582  finishFetch(
583  SHAMapHash const& hash,
584  std::shared_ptr<NodeObject> const& object) const;
585 };
586 
587 inline void
589 {
590  full_ = true;
591 }
592 
593 inline void
595 {
596  ledgerSeq_ = lseq;
597 }
598 
599 inline void
601 {
602  assert(state_ != SHAMapState::Invalid);
604 }
605 
606 inline bool
608 {
609  return state_ == SHAMapState::Synching;
610 }
611 
612 inline void
614 {
616 }
617 
618 inline void
620 {
622 }
623 
624 inline bool
626 {
627  return state_ != SHAMapState::Invalid;
628 }
629 
630 inline void
632 {
633  backed_ = false;
634 }
635 
636 //------------------------------------------------------------------------------
637 
639 {
640 public:
644  using reference = value_type const&;
645  using pointer = value_type const*;
646 
647 private:
649  SHAMap const* map_ = nullptr;
650  pointer item_ = nullptr;
651 
652 public:
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 
661  reference
662  operator*() const;
663  pointer
664  operator->() const;
665 
667  operator++();
669  operator++(int);
670 
671 private:
672  explicit const_iterator(SHAMap const* map);
673  const_iterator(SHAMap const* map, std::nullptr_t);
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 
681 inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map)
682 {
683  assert(map_ != nullptr);
684 
685  if (auto temp = map_->peekFirstItem(stack_))
686  item_ = temp->peekItem().get();
687 }
688 
690  : map_(map)
691 {
692 }
693 
695  SHAMap const* map,
696  pointer item,
697  SharedPtrNodeStack&& stack)
698  : stack_(std::move(stack)), map_(map), item_(item)
699 {
700 }
701 
704 {
705  return *item_;
706 }
707 
710 {
711  return item_;
712 }
713 
716 {
717  if (auto temp = map_->peekNextItem(item_->key(), stack_))
718  item_ = temp->peekItem().get();
719  else
720  item_ = nullptr;
721  return *this;
722 }
723 
726 {
727  auto tmp = *this;
728  ++(*this);
729  return tmp;
730 }
731 
732 inline bool
734 {
735  assert(x.map_ == y.map_);
736  return x.item_ == y.item_;
737 }
738 
739 inline bool
741 {
742  return !(x == y);
743 }
744 
745 inline SHAMap::const_iterator
747 {
748  return const_iterator(this);
749 }
750 
752 SHAMap::end() const
753 {
754  return const_iterator(this, nullptr);
755 }
756 
757 } // namespace ripple
758 
759 #endif
ripple::SHAMap::MissingNodes
Definition: SHAMap.h:510
ripple::SHAMapAddNode
Definition: SHAMapAddNode.h:28
ripple::SHAMap::invariants
void invariants() const
Definition: SHAMap.cpp:1188
ripple::SHAMap::clearSynching
void clearSynching()
Definition: SHAMap.h:619
ripple::SHAMap::isValid
bool isValid() const
Definition: SHAMap.h:625
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:346
ripple::SHAMap::MissingNodes::deferLock_
std::mutex deferLock_
Definition: SHAMap.h:550
ripple::SHAMap::peekNextItem
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:563
ripple::Dir::const_iterator
Definition: Directory.h:49
std::shared_ptr
STL class.
ripple::SHAMap::getHash
SHAMapHash getHash() const
Definition: SHAMap.cpp:852
ripple::SHAMap::backed_
bool backed_
Definition: SHAMap.h:110
ripple::SHAMap::type_
const SHAMapType type_
Definition: SHAMap.h:109
ripple::SHAMap::updateGiveItem
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:864
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:540
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:549
ripple::SHAMap::family
Family const & family() const
Definition: SHAMap.h:143
ripple::SHAMap::peekItem
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition: SHAMap.cpp:592
ripple::SHAMap::fetchNodeFromDB
std::shared_ptr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
Definition: SHAMap.cpp:163
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:558
ripple::SHAMap::walkSubTree
int walkSubTree(bool doWrite, NodeObjectType t)
Definition: SHAMap.cpp:999
ripple::SHAMap::dump
void dump(bool withHashes=false) const
Definition: SHAMap.cpp:1124
ripple::SHAMap::const_iterator::stack_
SharedPtrNodeStack stack_
Definition: SHAMap.h:648
vector
ripple::NodeObjectType
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
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:46
ripple::SHAMap::MissingNodes::maxDefer_
const int maxDefer_
Definition: SHAMap.h:520
ripple::SHAMap::MissingNodes::generation_
std::uint32_t generation_
Definition: SHAMap.h:521
stack
ripple::SHAMap::serializeRoot
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
Definition: SHAMapSync.cpp:522
ripple::SHAMap::fetchNode
std::shared_ptr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
Definition: SHAMap.cpp:278
std::forward_iterator_tag
ripple::SHAMap::fetchNodeNT
std::shared_ptr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
Definition: SHAMap.cpp:266
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:46
ripple::SHAMap::belowHelper
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:446
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:746
ripple::SHAMap::visitDifferences
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
ripple::SHAMap::MissingNodes::finishedReads_
std::vector< DeferredNode > finishedReads_
Definition: SHAMap.h:552
std::function
ripple::SHAMapNodeID
Identifies a node inside a SHAMap.
Definition: SHAMapNodeID.h:33
ripple::SHAMap::MissingNodes::filter_
SHAMapSyncFilter * filter_
Definition: SHAMap.h:519
ripple::SHAMap::snapShot
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
Definition: SHAMap.cpp:88
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:24
ripple::SHAMap::cacheLookup
std::shared_ptr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
Definition: SHAMap.cpp:1167
ripple::SHAMap::const_iterator::operator->
pointer operator->() const
Definition: SHAMap.h:709
ripple::SHAMapLeafNode
Definition: SHAMapLeafNode.h:32
ripple::SHAMap::addItem
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:844
ripple::SHAMap::setFull
void setFull()
Definition: SHAMap.h:588
ripple::SHAMapHash
Definition: SHAMapHash.h:32
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:165
ripple::SHAMap::f_
Family & f_
Definition: SHAMap.h:98
ripple::SHAMap::lastBelow
SHAMapLeafNode * lastBelow(std::shared_ptr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch=branchFactor) const
Definition: SHAMap.cpp:487
ripple::base_uint< 256 >
std::nullptr_t
ripple::SHAMap::MissingNodes::resumes_
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
Definition: SHAMap.h:556
ripple::SHAMap::hasItem
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition: SHAMap.cpp:690
ripple::SHAMap::const_iterator::operator==
friend bool operator==(const_iterator const &x, const_iterator const &y)
Definition: SHAMap.h:733
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:41
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:549
ripple::SHAMap::MissingNodes::max_
int max_
Definition: SHAMap.h:518
ripple::SHAMap::addGiveItem
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:774
ripple::SHAMap::onlyBelow
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
Definition: SHAMap.cpp:513
ripple::SHAMapItem
Definition: SHAMapItem.h:34
ripple::SHAMap::isSynching
bool isSynching() const
Definition: SHAMap.h:607
ripple::SHAMap::const_iterator
Definition: SHAMap.h:638
ripple::SHAMap::firstBelow
SHAMapLeafNode * firstBelow(std::shared_ptr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
Definition: SHAMap.cpp:499
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:715
ripple::operator!=
bool operator!=(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:175
ripple::SHAMap::MissingNodes::StackEntry
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
Definition: SHAMap.h:533
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:53
ripple::SHAMap::descendThrow
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:289
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:1175
ripple::SHAMap::walkBranch
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
Definition: SHAMapDelta.cpp:38
ripple::SHAMap::MissingNodes::missingHashes_
std::set< SHAMapHash > missingHashes_
Definition: SHAMap.h:525
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:650
std::uint32_t
std::map
STL class.
ripple::SHAMap::setLedgerSeq
void setLedgerSeq(std::uint32_t lseq)
Definition: SHAMap.h:594
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:317
ripple::SHAMap::const_iterator::map_
SHAMap const * map_
Definition: SHAMap.h:649
ripple::SHAMap::fetchRoot
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition: SHAMap.cpp:904
ripple::SHAMap::walkMap
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
Definition: SHAMapDelta.cpp:236
ripple::Serializer
Definition: Serializer.h:39
ripple::SHAMap::upper_bound
const_iterator upper_bound(uint256 const &id) const
Find the first item after the given item.
Definition: SHAMap.cpp:615
ripple::SHAMap::const_iterator::operator*
reference operator*() const
Definition: SHAMap.h:703
ripple::SHAMap::setImmutable
void setImmutable()
Definition: SHAMap.h:600
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::walkMapParallel
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
Definition: SHAMapDelta.cpp:278
ripple::SHAMap::checkFilter
std::shared_ptr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
Definition: SHAMap.cpp:210
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:631
ripple::SHAMap::MissingNodes::deferCondVar_
std::condition_variable deferCondVar_
Definition: SHAMap.h:551
ripple::SHAMap::findKey
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
Definition: SHAMap.cpp:154
ripple::SHAMap::const_iterator::const_iterator
const_iterator()=delete
ripple::SHAMap::end
const_iterator end() const
Definition: SHAMap.h:752
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::unshare
int unshare()
Convert any modified nodes to shared.
Definition: SHAMap.cpp:985
ripple::SHAMap::descendAsync
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
Definition: SHAMap.cpp:386
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:950
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:370
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::getNodeFat
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob >> &data, bool fatLeaves, std::uint32_t depth) const
Definition: SHAMapSync.cpp:427
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:645
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:969
ripple::SHAMap::addKnownNode
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
Definition: SHAMapSync.cpp:570
ripple::SHAMap::flushDirty
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
Definition: SHAMap.cpp:992
ripple::SHAMap::lower_bound
const_iterator lower_bound(uint256 const &id) const
Find the object with the greatest object id smaller than the input id.
Definition: SHAMap.cpp:652
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:430
ripple::SHAMap::descend
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:312
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:528
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::SHAMapSyncFilter
Definition: SHAMapSyncFilter.h:30
ripple::SHAMap::SHAMap
SHAMap()=delete
ripple::SHAMap::MissingNodes::missingNodes_
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
Definition: SHAMap.h:524
ripple::SHAMap::delItem
bool delItem(uint256 const &id)
Definition: SHAMap.cpp:696
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:613
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::visitLeaves
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
Definition: SHAMapSync.cpp:27
ripple::SHAMap::family
Family & family()
Definition: SHAMap.h:149
ripple::SHAMap::const_iterator::reference
value_type const & reference
Definition: SHAMap.h:644