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(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, boost::intrusive_ptr<SHAMapItem const> item);
194 
195  SHAMapHash
196  getHash() const;
197 
198  // save a copy if you have a temporary anyway
199  bool
201  SHAMapNodeType type,
202  boost::intrusive_ptr<SHAMapItem const> item);
203 
204  bool
205  addGiveItem(
206  SHAMapNodeType type,
207  boost::intrusive_ptr<SHAMapItem const> item);
208 
209  // Save a copy if you need to extend the life
210  // of the SHAMapItem beyond this SHAMap
211  boost::intrusive_ptr<SHAMapItem const> const&
212  peekItem(uint256 const& id) const;
213  boost::intrusive_ptr<SHAMapItem const> const&
214  peekItem(uint256 const& id, SHAMapHash& hash) const;
215 
216  // traverse functions
224  upper_bound(uint256 const& id) const;
225 
233  lower_bound(uint256 const& id) const;
234 
240  void
241  visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const;
242 
249  void
251  SHAMap const* have,
252  std::function<bool(SHAMapTreeNode const&)> const&) const;
253 
258  void
259  visitLeaves(
261  void(boost::intrusive_ptr<SHAMapItem const> const&)> const&) const;
262 
263  // comparison/sync functions
264 
276  getMissingNodes(int maxNodes, SHAMapSyncFilter* filter);
277 
278  bool
279  getNodeFat(
280  SHAMapNodeID const& wanted,
282  bool fatLeaves,
283  std::uint32_t depth) const;
284 
292  getProofPath(uint256 const& key) const;
293 
301  static bool
303  uint256 const& rootHash,
304  uint256 const& key,
305  std::vector<Blob> const& path);
306 
308  void
309  serializeRoot(Serializer& s) const;
310 
312  addRootNode(
313  SHAMapHash const& hash,
314  Slice const& rootNode,
315  SHAMapSyncFilter* filter);
317  addKnownNode(
318  SHAMapNodeID const& nodeID,
319  Slice const& rawNode,
320  SHAMapSyncFilter* filter);
321 
322  // status functions
323  void
324  setImmutable();
325  bool
326  isSynching() const;
327  void
328  setSynching();
329  void
330  clearSynching();
331  bool
332  isValid() const;
333 
334  // caution: otherMap must be accessed only by this function
335  // return value: true=successfully completed, false=too different
336  bool
337  compare(SHAMap const& otherMap, Delta& differences, int maxCount) const;
338 
340  int
341  unshare();
342 
344  int
346 
347  void
348  walkMap(std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
349  bool
351  std::vector<SHAMapMissingNode>& missingNodes,
352  int maxMissing) const;
353  bool
354  deepCompare(SHAMap& other) const; // Intended for debug/test only
355 
356  void
357  setUnbacked();
358 
359  void
360  dump(bool withHashes = false) const;
361  void
362  invariants() const;
363 
364 private:
365  using SharedPtrNodeStack =
367  using DeltaRef = std::pair<
368  boost::intrusive_ptr<SHAMapItem const>,
369  boost::intrusive_ptr<SHAMapItem const>>;
370 
371  // tree node cache operations
373  cacheLookup(SHAMapHash const& hash) const;
374  void
376  const;
377 
378  // database operations
380  fetchNodeFromDB(SHAMapHash const& hash) const;
382  fetchNodeNT(SHAMapHash const& hash) const;
384  fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
386  fetchNode(SHAMapHash const& hash) const;
388  checkFilter(SHAMapHash const& hash, SHAMapSyncFilter* filter) const;
389 
391  void
392  dirtyUp(
393  SharedPtrNodeStack& stack,
394  uint256 const& target,
396 
401  walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack = nullptr)
402  const;
405  findKey(uint256 const& id) const;
406 
408  template <class Node>
411 
413  template <class Node>
416 
420 
421  // returns the first item at or below this node
423  firstBelow(
425  SharedPtrNodeStack& stack,
426  int branch = 0) const;
427 
428  // returns the last item at or below this node
430  lastBelow(
432  SharedPtrNodeStack& stack,
433  int branch = branchFactor) const;
434 
435  // helper function for firstBelow and lastBelow
437  belowHelper(
439  SharedPtrNodeStack& stack,
440  int branch,
441  std::tuple<
442  int,
443  std::function<bool(int)>,
444  std::function<void(int&)>> const& loopParams) const;
445 
446  // Simple descent
447  // Get a child of the specified node
449  descend(SHAMapInnerNode*, int branch) const;
451  descendThrow(SHAMapInnerNode*, int branch) const;
453  descend(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
455  descendThrow(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
456 
457  // Descend with filter
458  // If pending, callback is called as if it called fetchNodeNT
459  using descendCallback =
462  descendAsync(
463  SHAMapInnerNode* parent,
464  int branch,
465  SHAMapSyncFilter* filter,
466  bool& pending,
467  descendCallback&&) const;
468 
470  descend(
471  SHAMapInnerNode* parent,
472  SHAMapNodeID const& parentID,
473  int branch,
474  SHAMapSyncFilter* filter) const;
475 
476  // Non-storing
477  // Does not hook the returned node to its parent
479  descendNoStore(std::shared_ptr<SHAMapInnerNode> const&, int branch) const;
480 
482  boost::intrusive_ptr<SHAMapItem const> const&
483  onlyBelow(SHAMapTreeNode*) const;
484 
485  bool
486  hasInnerNode(SHAMapNodeID const& nodeID, SHAMapHash const& hash) const;
487  bool
488  hasLeafNode(uint256 const& tag, SHAMapHash const& hash) const;
489 
490  SHAMapLeafNode const*
491  peekFirstItem(SharedPtrNodeStack& stack) const;
492  SHAMapLeafNode const*
493  peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const;
494  bool
495  walkBranch(
496  SHAMapTreeNode* node,
497  boost::intrusive_ptr<SHAMapItem const> const& otherMapItem,
498  bool isFirstMap,
499  Delta& differences,
500  int& maxCount) const;
501  int
502  walkSubTree(bool doWrite, NodeObjectType t);
503 
504  // Structure to track information about call to
505  // getMissingNodes while it's in progress
507  {
508  MissingNodes() = delete;
509  MissingNodes(const MissingNodes&) = delete;
510  MissingNodes&
511  operator=(const MissingNodes&) = delete;
512 
513  // basic parameters
514  int max_;
516  int const maxDefer_;
518 
519  // nodes we have discovered to be missing
522 
523  // nodes we are in the process of traversing
524  using StackEntry = std::tuple<
525  SHAMapInnerNode*, // pointer to the node
526  SHAMapNodeID, // the node's ID
527  int, // while child we check first
528  int, // which child we check next
529  bool>; // whether we've found any missing children yet
530 
531  // We explicitly choose to specify the use of std::deque here, because
532  // we need to ensure that pointers and/or references to existing
533  // elements will not be invalidated during the course of element
534  // insertion and removal. Containers that do not offer this guarantee,
535  // such as std::vector, can't be used here.
537 
538  // nodes we may have acquired from deferred reads
539  using DeferredNode = std::tuple<
540  SHAMapInnerNode*, // parent node
541  SHAMapNodeID, // parent node ID
542  int, // branch
544 
549 
550  // nodes we need to resume after we get their children from deferred
551  // reads
553 
555  int max,
556  SHAMapSyncFilter* filter,
557  int maxDefer,
558  std::uint32_t generation)
559  : max_(max)
560  , filter_(filter)
561  , maxDefer_(maxDefer)
562  , generation_(generation)
563  , deferred_(0)
564  {
565  missingNodes_.reserve(max);
566  finishedReads_.reserve(maxDefer);
567  }
568  };
569 
570  // getMissingNodes helper functions
571  void
572  gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node);
573  void
574  gmn_ProcessDeferredReads(MissingNodes&);
575 
576  // fetch from DB helper function
578  finishFetch(
579  SHAMapHash const& hash,
580  std::shared_ptr<NodeObject> const& object) const;
581 };
582 
583 inline void
585 {
586  full_ = true;
587 }
588 
589 inline void
591 {
592  ledgerSeq_ = lseq;
593 }
594 
595 inline void
597 {
598  assert(state_ != SHAMapState::Invalid);
600 }
601 
602 inline bool
604 {
605  return state_ == SHAMapState::Synching;
606 }
607 
608 inline void
610 {
612 }
613 
614 inline void
616 {
618 }
619 
620 inline bool
622 {
623  return state_ != SHAMapState::Invalid;
624 }
625 
626 inline void
628 {
629  backed_ = false;
630 }
631 
632 //------------------------------------------------------------------------------
633 
635 {
636 public:
640  using reference = value_type const&;
641  using pointer = value_type const*;
642 
643 private:
645  SHAMap const* map_ = nullptr;
646  pointer item_ = nullptr;
647 
648 public:
649  const_iterator() = delete;
650 
651  const_iterator(const_iterator const& other) = default;
653  operator=(const_iterator const& other) = default;
654 
655  ~const_iterator() = default;
656 
657  reference
658  operator*() const;
659  pointer
660  operator->() const;
661 
663  operator++();
665  operator++(int);
666 
667 private:
668  explicit const_iterator(SHAMap const* map);
669  const_iterator(SHAMap const* map, std::nullptr_t);
670  const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack);
671 
672  friend bool
673  operator==(const_iterator const& x, const_iterator const& y);
674  friend class SHAMap;
675 };
676 
677 inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map)
678 {
679  assert(map_ != nullptr);
680 
681  if (auto temp = map_->peekFirstItem(stack_))
682  item_ = temp->peekItem().get();
683 }
684 
686  : map_(map)
687 {
688 }
689 
691  SHAMap const* map,
692  pointer item,
693  SharedPtrNodeStack&& stack)
694  : stack_(std::move(stack)), map_(map), item_(item)
695 {
696 }
697 
700 {
701  return *item_;
702 }
703 
706 {
707  return item_;
708 }
709 
712 {
713  if (auto temp = map_->peekNextItem(item_->key(), stack_))
714  item_ = temp->peekItem().get();
715  else
716  item_ = nullptr;
717  return *this;
718 }
719 
722 {
723  auto tmp = *this;
724  ++(*this);
725  return tmp;
726 }
727 
728 inline bool
730 {
731  assert(x.map_ == y.map_);
732  return x.item_ == y.item_;
733 }
734 
735 inline bool
737 {
738  return !(x == y);
739 }
740 
741 inline SHAMap::const_iterator
743 {
744  return const_iterator(this);
745 }
746 
748 SHAMap::end() const
749 {
750  return const_iterator(this, nullptr);
751 }
752 
753 } // namespace ripple
754 
755 #endif
ripple::SHAMap::MissingNodes
Definition: SHAMap.h:506
ripple::SHAMapAddNode
Definition: SHAMapAddNode.h:28
ripple::SHAMap::invariants
void invariants() const
Definition: SHAMap.cpp:1193
ripple::SHAMap::clearSynching
void clearSynching()
Definition: SHAMap.h:615
ripple::SHAMap::isValid
bool isValid() const
Definition: SHAMap.h:621
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:351
ripple::SHAMap::SHAMap
SHAMap(SHAMap const &)=delete
ripple::SHAMap::MissingNodes::deferLock_
std::mutex deferLock_
Definition: SHAMap.h:546
ripple::SHAMap::peekNextItem
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
Definition: SHAMap.cpp:568
ripple::Dir::const_iterator
Definition: Directory.h:49
std::shared_ptr
STL class.
ripple::SHAMap::getHash
SHAMapHash getHash() const
Definition: SHAMap.cpp:857
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:869
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:536
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:545
ripple::SHAMap::family
Family const & family() const
Definition: SHAMap.h:139
ripple::SHAMap::peekItem
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition: SHAMap.cpp:597
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:554
ripple::SHAMap::walkSubTree
int walkSubTree(bool doWrite, NodeObjectType t)
Definition: SHAMap.cpp:1004
ripple::SHAMap::dump
void dump(bool withHashes=false) const
Definition: SHAMap.cpp:1129
ripple::SHAMap::const_iterator::stack_
SharedPtrNodeStack stack_
Definition: SHAMap.h:644
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:516
ripple::SHAMap::MissingNodes::generation_
std::uint32_t generation_
Definition: SHAMap.h:517
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:283
std::forward_iterator_tag
ripple::SHAMap::fetchNodeNT
std::shared_ptr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
Definition: SHAMap.cpp:271
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:451
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:742
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:548
std::function
ripple::SHAMapNodeID
Identifies a node inside a SHAMap.
Definition: SHAMapNodeID.h:33
ripple::SHAMap::MissingNodes::filter_
SHAMapSyncFilter * filter_
Definition: SHAMap.h:515
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:24
ripple::SHAMap::cacheLookup
std::shared_ptr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
Definition: SHAMap.cpp:1172
ripple::SHAMap::const_iterator::operator->
pointer operator->() const
Definition: SHAMap.h:705
ripple::SHAMapLeafNode
Definition: SHAMapLeafNode.h:32
ripple::SHAMap::addItem
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:849
ripple::SHAMap::setFull
void setFull()
Definition: SHAMap.h:584
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:492
ripple::base_uint< 256 >
std::nullptr_t
ripple::SHAMap::MissingNodes::resumes_
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
Definition: SHAMap.h:552
ripple::SHAMap::hasItem
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition: SHAMap.cpp:695
ripple::SHAMap::const_iterator::operator==
friend bool operator==(const_iterator const &x, const_iterator const &y)
Definition: SHAMap.h:729
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:554
ripple::SHAMap::MissingNodes::max_
int max_
Definition: SHAMap.h:514
ripple::SHAMap::addGiveItem
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:779
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:518
ripple::SHAMapItem
Definition: SHAMapItem.h:34
ripple::SHAMap::isSynching
bool isSynching() const
Definition: SHAMap.h:603
ripple::SHAMap::const_iterator
Definition: SHAMap.h:634
ripple::SHAMap::firstBelow
SHAMapLeafNode * firstBelow(std::shared_ptr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
Definition: SHAMap.cpp:504
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:711
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:529
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:53
ripple::SHAMap::descendThrow
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:294
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:1180
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:521
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:646
std::uint32_t
std::map
STL class.
ripple::SHAMap::setLedgerSeq
void setLedgerSeq(std::uint32_t lseq)
Definition: SHAMap.h:590
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:645
ripple::SHAMap::fetchRoot
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition: SHAMap.cpp:909
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:620
ripple::SHAMap::const_iterator::operator*
reference operator*() const
Definition: SHAMap.h:699
ripple::SHAMap::setImmutable
void setImmutable()
Definition: SHAMap.h:596
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:215
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:627
ripple::SHAMap::MissingNodes::deferCondVar_
std::condition_variable deferCondVar_
Definition: SHAMap.h:547
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:748
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:990
ripple::SHAMap::descendAsync
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
Definition: SHAMap.cpp:391
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:955
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:366
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:641
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:974
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:997
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:657
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:435
ripple::SHAMap::descend
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
Definition: SHAMap.cpp:317
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::MissingNodes::missingNodes_
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
Definition: SHAMap.h:520
ripple::SHAMap::delItem
bool delItem(uint256 const &id)
Definition: SHAMap.cpp:701
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:609
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:145
ripple::SHAMap::const_iterator::reference
value_type const & reference
Definition: SHAMap.h:640