20#ifndef RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
21#define RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
23#include <xrpld/nodestore/Database.h>
24#include <xrpld/nodestore/NodeObject.h>
25#include <xrpld/shamap/Family.h>
26#include <xrpld/shamap/FullBelowCache.h>
27#include <xrpld/shamap/SHAMapAddNode.h>
28#include <xrpld/shamap/SHAMapInnerNode.h>
29#include <xrpld/shamap/SHAMapItem.h>
30#include <xrpld/shamap/SHAMapLeafNode.h>
31#include <xrpld/shamap/SHAMapMissingNode.h>
32#include <xrpld/shamap/SHAMapTreeNode.h>
33#include <xrpld/shamap/TreeNodeCache.h>
34#include <xrpl/basics/UnorderedContainers.h>
35#include <xrpl/beast/utility/Journal.h>
36#include <xrpl/beast/utility/instrumentation.h>
43class SHAMapSyncFilter;
123 boost::intrusive_ptr<SHAMapItem const>,
124 boost::intrusive_ptr<SHAMapItem const>>;
206 boost::intrusive_ptr<SHAMapItem const> item);
211 boost::intrusive_ptr<SHAMapItem const> item);
215 boost::intrusive_ptr<SHAMapItem const>
const&
217 boost::intrusive_ptr<SHAMapItem const>
const&
265 void(boost::intrusive_ptr<SHAMapItem const>
const&)>
const&)
const;
318 Slice const& rootNode,
323 Slice const& rawNode,
341 compare(
SHAMap const& otherMap,
Delta& differences,
int maxCount)
const;
356 int maxMissing)
const;
364 dump(
bool withHashes =
false)
const;
372 boost::intrusive_ptr<SHAMapItem const>,
373 boost::intrusive_ptr<SHAMapItem const>>;
412 template <
class Node>
417 template <
class Node>
430 int branch = 0)
const;
486 boost::intrusive_ptr<SHAMapItem const>
const&
501 boost::intrusive_ptr<SHAMapItem const>
const& otherMapItem,
504 int& maxCount)
const;
604 "ripple::SHAMap::setImmutable : state is valid");
687 "ripple::SHAMap::const_iterator::const_iterator : non-null input");
690 item_ = temp->peekItem().get();
702 : stack_(
std::move(stack)), map_(map), item_(item)
721 if (
auto temp = map_->peekNextItem(item_->key(), stack_))
722 item_ = temp->peekItem().get();
741 "ripple::operator==(SHAMap::const_iterator, SHAMap::const_iterator) : "
742 "inputs map do match");
752inline 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.
std::shared_ptr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
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?
std::shared_ptr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
void dump(bool withHashes=false) const
SHAMapLeafNode * firstBelow(std::shared_ptr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) 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
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, std::shared_ptr< SHAMapTreeNode > terminal)
Update hashes up to the root.
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
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
SHAMapLeafNode * lastBelow(std::shared_ptr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch=branchFactor) const
std::shared_ptr< SHAMapTreeNode > writeNode(NodeObjectType t, std::shared_ptr< SHAMapTreeNode > node) const
write and canonicalize modified node
Family const & family() const
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) 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
std::shared_ptr< Node > preFlushNode(std::shared_ptr< Node > node) const
prepare a node to be modified before flushing
std::shared_ptr< SHAMapTreeNode > root_
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
int walkSubTree(bool doWrite, NodeObjectType t)
std::shared_ptr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
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?
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
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
std::shared_ptr< SHAMapTreeNode > descendNoStore(std::shared_ptr< SHAMapInnerNode > const &, int branch) const
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.
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?
std::shared_ptr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
std::shared_ptr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
SHAMap & operator=(SHAMap const &)=delete
SHAMap(SHAMap const &)=delete
const_iterator begin() const
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
void canonicalize(SHAMapHash const &hash, std::shared_ptr< SHAMapTreeNode > &) const
bool delItem(uint256 const &id)
std::shared_ptr< Node > unshareNode(std::shared_ptr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
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.
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.
bool deepCompare(SHAMap &other) const
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
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::shared_ptr< SHAMapTreeNode > finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
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)
MissingNodes(const MissingNodes &)=delete
std::uint32_t generation_
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
MissingNodes & operator=(const MissingNodes &)=delete
SHAMapSyncFilter * filter_
std::vector< DeferredNode > finishedReads_