3#include <xrpl/basics/IntrusivePointer.h>
4#include <xrpl/basics/UnorderedContainers.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/nodestore/Database.h>
8#include <xrpl/nodestore/NodeObject.h>
9#include <xrpl/shamap/Family.h>
10#include <xrpl/shamap/SHAMapAddNode.h>
11#include <xrpl/shamap/SHAMapInnerNode.h>
12#include <xrpl/shamap/SHAMapItem.h>
13#include <xrpl/shamap/SHAMapLeafNode.h>
14#include <xrpl/shamap/SHAMapMissingNode.h>
15#include <xrpl/shamap/SHAMapTreeNode.h>
190 boost::intrusive_ptr<SHAMapItem const>
const&
192 boost::intrusive_ptr<SHAMapItem const>
const&
324 dump(
bool withHashes =
false)
const;
366 template <
class Node>
371 template <
class Node>
431 boost::intrusive_ptr<SHAMapItem const>
const&
446 boost::intrusive_ptr<SHAMapItem const>
const& otherMapItem,
449 int& maxCount)
const;
622 XRPL_ASSERT(
map_,
"xrpl::SHAMap::ConstIterator::ConstIterator : non-null input");
625 item_ = temp->peekItem().get();
657 item_ = temp->peekItem().get();
679 "xrpl::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : "
680 "inputs map do match");
690inline SHAMap::ConstIterator
A generic endpoint for log messages.
static constexpr unsigned int kBranchFactor
Each inner node has 16 children (the 'radix tree' part of the map).
Identifies a node inside a SHAMap.
pointer operator->() const
ConstIterator(ConstIterator const &other)=default
SharedPtrNodeStack stack_
value_type const & reference
ConstIterator & operator=(ConstIterator const &other)=default
friend bool operator==(ConstIterator const &x, ConstIterator const &y)
std::forward_iterator_tag iterator_category
ConstIterator & operator++()
value_type const * pointer
reference operator*() const
std::ptrdiff_t difference_type
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
SHAMapLeafNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter const *filter)
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Family const & family() const
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
ConstIterator lowerBound(uint256 const &id) const
Find the object with the greatest object id smaller than the input id.
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
SHAMapLeafNode * belowHelper(SHAMapTreeNodePtr node, SharedPtrNodeStack &stack, int branch, std::tuple< int, std::function< bool(int)>, std::function< void(int &)> > const &loopParams) const
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
SHAMapTreeNodePtr finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
void setLedgerSeq(std::uint32_t lseq)
static constexpr unsigned int kLeafDepth
The depth of the hash map: data is only present in the leaves.
SHAMapTreeNodePtr fetchNodeFromDB(SHAMapHash const &hash) const
std::map< uint256, DeltaItem > Delta
std::pair< boost::intrusive_ptr< SHAMapItem const >, boost::intrusive_ptr< SHAMapItem const > > DeltaItem
SHAMapTreeNodePtr cacheLookup(SHAMapHash const &hash) const
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter const *filter)
Check for nodes in the SHAMap not available.
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
static void gmnProcessDeferredReads(MissingNodes &)
static constexpr unsigned int kBranchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map).
std::pair< boost::intrusive_ptr< SHAMapItem const >, boost::intrusive_ptr< SHAMapItem const > > DeltaRef
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.
SHAMapTreeNodePtr fetchNode(SHAMapHash const &hash) const
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
SHAMapLeafNode * firstBelow(SHAMapTreeNodePtr node, SharedPtrNodeStack &stack, int branch=0) const
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
SHAMap(SHAMap const &)=delete
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
bool deepCompare(SHAMap &other) const
void gmnProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
SHAMap & operator=(SHAMap const &)=delete
void dump(bool withHashes=false) const
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
SHAMapLeafNode * lastBelow(SHAMapTreeNodePtr node, SharedPtrNodeStack &stack, int branch=kBranchFactor) const
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
int unshare()
Convert any modified nodes to shared.
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter const *filter, bool &pending, descendCallback &&) const
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, SHAMapTreeNodePtr terminal)
Update hashes up to the root.
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter const *filter)
std::stack< std::pair< SHAMapTreeNodePtr, SHAMapNodeID > > SharedPtrNodeStack
ConstIterator upperBound(uint256 const &id) const
Find the first item after the given item.
void canonicalize(SHAMapHash const &hash, SHAMapTreeNodePtr &) const
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
SHAMapTreeNodePtr fetchNodeNT(SHAMapHash const &hash) const
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) const
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter const *filter)
SHAMapTreeNodePtr descendNoStore(SHAMapInnerNode &, int branch) const
SHAMapTreeNodePtr checkFilter(SHAMapHash const &hash, SHAMapSyncFilter const *filter) const
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
ConstIterator end() const
SHAMapTreeNodePtr writeNode(NodeObjectType t, SHAMapTreeNodePtr node) const
write and canonicalize modified node
std::function< void(SHAMapTreeNodePtr, SHAMapHash const &)> descendCallback
intr_ptr::SharedPtr< Node > preFlushNode(intr_ptr::SharedPtr< Node > node) const
prepare a node to be modified before flushing
intr_ptr::SharedPtr< Node > unshareNode(intr_ptr::SharedPtr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
int walkSubTree(bool doWrite, NodeObjectType t)
SHAMapHash getHash() const
ConstIterator begin() const
void visitNodes(std::function< bool(SHAMapTreeNode &)> const &function) const
Visit every node in this SHAMap.
bool delItem(uint256 const &id)
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
An immutable linear range of bytes.
SharedIntrusive< T > SharedPtr
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
intr_ptr::SharedPtr< SHAMapTreeNode > SHAMapTreeNodePtr
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
NodeObjectType
The types of node objects.
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.
@ Invalid
Timely, but invalid signature.
std::set< SHAMapHash > missingHashes
std::vector< DeferredNode > finishedReads
MissingNodes & operator=(MissingNodes const &)=delete
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes
MissingNodes(int max, SHAMapSyncFilter const *filter, int maxDefer, std::uint32_t generation)
MissingNodes(MissingNodes const &)=delete
SHAMapSyncFilter const * filter
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
std::stack< StackEntry, std::deque< StackEntry > > stack
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, SHAMapTreeNodePtr > DeferredNode
std::condition_variable deferCondVar