20#ifndef RIPPLE_SHAMAP_SHAMAP_H_INCLUDED 
   21#define RIPPLE_SHAMAP_SHAMAP_H_INCLUDED 
   23#include <xrpl/basics/IntrusivePointer.h> 
   24#include <xrpl/basics/UnorderedContainers.h> 
   25#include <xrpl/beast/utility/Journal.h> 
   26#include <xrpl/beast/utility/instrumentation.h> 
   27#include <xrpl/nodestore/Database.h> 
   28#include <xrpl/nodestore/NodeObject.h> 
   29#include <xrpl/shamap/Family.h> 
   30#include <xrpl/shamap/SHAMapAddNode.h> 
   31#include <xrpl/shamap/SHAMapInnerNode.h> 
   32#include <xrpl/shamap/SHAMapItem.h> 
   33#include <xrpl/shamap/SHAMapLeafNode.h> 
   34#include <xrpl/shamap/SHAMapMissingNode.h> 
   35#include <xrpl/shamap/SHAMapTreeNode.h> 
   44class SHAMapSyncFilter;
 
  124        boost::intrusive_ptr<SHAMapItem const>,
 
  125        boost::intrusive_ptr<SHAMapItem const>>;
 
  207        boost::intrusive_ptr<SHAMapItem const> item);
 
  212        boost::intrusive_ptr<SHAMapItem const> item);
 
  216    boost::intrusive_ptr<SHAMapItem const> 
const&
 
  218    boost::intrusive_ptr<SHAMapItem const> 
const&
 
  266            void(boost::intrusive_ptr<SHAMapItem const> 
const&)> 
const&) 
const;
 
  319        Slice const& rootNode,
 
  324        Slice const& rawNode,
 
  342    compare(
SHAMap const& otherMap, 
Delta& differences, 
int maxCount) 
const;
 
  357        int maxMissing) 
const;
 
  365    dump(
bool withHashes = 
false) 
const;
 
  373        boost::intrusive_ptr<SHAMapItem const>,
 
  374        boost::intrusive_ptr<SHAMapItem const>>;
 
  414    template <
class Node>
 
  419    template <
class Node>
 
  432        int branch = 0) 
const;
 
  488    boost::intrusive_ptr<SHAMapItem const> 
const&
 
  503        boost::intrusive_ptr<SHAMapItem const> 
const& otherMapItem,
 
  506        int& maxCount) 
const;
 
 
  606        "ripple::SHAMap::setImmutable : state is valid");
 
 
  689        "ripple::SHAMap::const_iterator::const_iterator : non-null input");
 
  692        item_ = temp->peekItem().get();
 
 
  704    : stack_(
std::move(stack)), map_(map), item_(item)
 
 
  723    if (
auto temp = map_->peekNextItem(item_->key(), stack_))
 
  724        item_ = temp->peekItem().get();
 
 
  743        "ripple::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : " 
  744        "inputs map do match");
 
 
  754inline SHAMap::const_iterator
 
A generic endpoint for log messages.
 
const_iterator(ReadView const &view, Keylet const &root, Keylet const &page)
 
reference operator*() const
 
value_type const  & reference
 
const_iterator & operator++()
 
value_type const  * pointer
 
pointer operator->() const
 
static constexpr unsigned int branchFactor
Each inner node has 16 children (the 'radix tree' part of the map)
 
Identifies a node inside a SHAMap.
 
value_type const  * pointer
 
SharedPtrNodeStack stack_
 
const_iterator(const_iterator const &other)=default
 
const_iterator & operator++()
 
reference operator*() const
 
value_type const  & reference
 
~const_iterator()=default
 
friend bool operator==(const_iterator const &x, const_iterator const &y)
 
const_iterator & operator=(const_iterator const &other)=default
 
pointer operator->() const
 
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
 
intr_ptr::SharedPtr< Node > preFlushNode(intr_ptr::SharedPtr< Node > node) const
prepare a node to be modified before flushing
 
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
 
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
 
intr_ptr::SharedPtr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
 
intr_ptr::SharedPtr< Node > unshareNode(intr_ptr::SharedPtr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
 
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
 
void dump(bool withHashes=false) const
 
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
 
void gmn_ProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
 
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
 
std::map< uint256, DeltaItem > Delta
 
intr_ptr::SharedPtr< SHAMapTreeNode > root_
 
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
 
Family const & family() const
 
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) const
 
intr_ptr::SharedPtr< SHAMapTreeNode > finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
 
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
 
SHAMapLeafNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
 
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
 
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
 
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
 
void canonicalize(SHAMapHash const &hash, intr_ptr::SharedPtr< SHAMapTreeNode > &) const
 
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
 
int walkSubTree(bool doWrite, NodeObjectType t)
 
void setLedgerSeq(std::uint32_t lseq)
 
const_iterator end() const
 
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
 
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
 
const_iterator upper_bound(uint256 const &id) const
Find the first item after the given item.
 
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
 
intr_ptr::SharedPtr< SHAMapTreeNode > writeNode(NodeObjectType t, intr_ptr::SharedPtr< SHAMapTreeNode > node) const
write and canonicalize modified node
 
intr_ptr::SharedPtr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
 
void gmn_ProcessDeferredReads(MissingNodes &)
 
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
 
SHAMapHash getHash() const
 
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
 
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
 
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, intr_ptr::SharedPtr< SHAMapTreeNode > terminal)
Update hashes up to the root.
 
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
 
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
 
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
 
intr_ptr::SharedPtr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
 
void visitNodes(std::function< bool(SHAMapTreeNode &)> const &function) const
Visit every node in this SHAMap.
 
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
 
intr_ptr::SharedPtr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
 
SHAMap & operator=(SHAMap const &)=delete
 
SHAMap(SHAMap const &)=delete
 
const_iterator begin() const
 
intr_ptr::SharedPtr< SHAMapTreeNode > descendNoStore(SHAMapInnerNode &, int branch) const
 
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
 
bool delItem(uint256 const &id)
 
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
 
const_iterator lower_bound(uint256 const &id) const
Find the object with the greatest object id smaller than the input id.
 
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.
 
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
 
SHAMapLeafNode * lastBelow(intr_ptr::SharedPtr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch=branchFactor) const
 
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
 
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
 
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
 
int unshare()
Convert any modified nodes to shared.
 
intr_ptr::SharedPtr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
 
bool deepCompare(SHAMap &other) const
 
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
 
SHAMapLeafNode * belowHelper(intr_ptr::SharedPtr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch, std::tuple< int, std::function< bool(int)>, std::function< void(int &)> > const &loopParams) const
 
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
 
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
 
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
 
SHAMapLeafNode * firstBelow(intr_ptr::SharedPtr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
 
A shared intrusive pointer class that supports weak pointers.
 
An immutable linear range of bytes.
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
bool operator!=(Buffer const &lhs, Buffer const &rhs) noexcept
 
SHAMapState
Describes the current state of a given SHAMap.
 
@ 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.
 
@ pending
List will be valid in the future.
 
constexpr bool operator==(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
 
std::set< SHAMapHash > missingHashes_
 
std::stack< StackEntry, std::deque< StackEntry > > stack_
 
std::condition_variable deferCondVar_
 
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
 
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
 
std::uint32_t generation_
 
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
 
MissingNodes(MissingNodes const &)=delete
 
MissingNodes & operator=(MissingNodes const &)=delete
 
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
 
SHAMapSyncFilter * filter_
 
std::vector< DeferredNode > finishedReads_