20 #ifndef RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
21 #define RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
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>
43 class 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,
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;
683 assert(
map_ !=
nullptr);
686 item_ = temp->peekItem().get();
698 : stack_(
std::move(stack)), map_(map), item_(item)
717 if (
auto temp = map_->peekNextItem(item_->key(), stack_))
718 item_ = temp->peekItem().get();
745 inline SHAMap::const_iterator
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
std::shared_ptr< SHAMapTreeNode > descendNoStore(std::shared_ptr< SHAMapInnerNode > const &, int branch) const
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
SHAMapHash getHash() const
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
bool deepCompare(SHAMap &other) const
std::stack< StackEntry, std::deque< StackEntry > > stack_
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
Family const & family() const
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
std::shared_ptr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
An immutable linear range of bytes.
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
int walkSubTree(bool doWrite, NodeObjectType t)
void dump(bool withHashes=false) const
SharedPtrNodeStack stack_
NodeObjectType
The types of node objects.
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
std::uint32_t generation_
void serializeRoot(Serializer &s) const
Serializes the root in a format appropriate for sending over the wire.
std::shared_ptr< SHAMapTreeNode > fetchNode(SHAMapHash const &hash) const
std::shared_ptr< SHAMapTreeNode > fetchNodeNT(SHAMapHash const &hash) const
std::map< uint256, DeltaItem > Delta
static constexpr unsigned int branchFactor
Each inner node has 16 children (the 'radix tree' part of the map)
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
@ Modifying
The map is in flux and objects can be added and removed.
const_iterator begin() const
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.
std::vector< DeferredNode > finishedReads_
Identifies a node inside a SHAMap.
SHAMapSyncFilter * filter_
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
value_type const * pointer
void gmn_ProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
Dir::const_iterator const_iterator
std::shared_ptr< SHAMapTreeNode > cacheLookup(SHAMapHash const &hash) const
pointer operator->() const
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
@ Synching
The map's hash is fixed but valid nodes may be missing and can be added.
bool operator==(Manifest const &lhs, Manifest const &rhs)
SHAMapLeafNode * lastBelow(std::shared_ptr< SHAMapTreeNode > node, SharedPtrNodeStack &stack, int branch=branchFactor) const
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
friend bool operator==(const_iterator const &x, const_iterator const &y)
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
SHAMap & operator=(SHAMap const &)=delete
~const_iterator()=default
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
boost::intrusive_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
SHAMapLeafNode * firstBelow(std::shared_ptr< SHAMapTreeNode >, SharedPtrNodeStack &stack, int branch=0) const
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
const_iterator & operator++()
bool operator!=(Manifest const &lhs, Manifest const &rhs)
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
SHAMapTreeNode * descendThrow(SHAMapInnerNode *, int branch) const
void canonicalize(SHAMapHash const &hash, std::shared_ptr< SHAMapTreeNode > &) const
bool walkBranch(SHAMapTreeNode *node, boost::intrusive_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
std::set< SHAMapHash > missingHashes_
A generic endpoint for log messages.
void setLedgerSeq(std::uint32_t lseq)
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
const_iterator upper_bound(uint256 const &id) const
Find the first item after the given item.
reference operator*() const
std::shared_ptr< SHAMapTreeNode > finishFetch(SHAMapHash const &hash, std::shared_ptr< NodeObject > const &object) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
std::shared_ptr< SHAMapTreeNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, std::shared_ptr< SHAMapTreeNode > terminal)
Update hashes up to the root.
std::condition_variable deferCondVar_
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
const_iterator end() const
SHAMapLeafNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
int unshare()
Convert any modified nodes to shared.
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending, descendCallback &&) const
std::shared_ptr< SHAMapTreeNode > writeNode(NodeObjectType t, std::shared_ptr< SHAMapTreeNode > node) const
write and canonicalize modified node
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
std::stack< std::pair< std::shared_ptr< SHAMapTreeNode >, SHAMapNodeID > > SharedPtrNodeStack
@ Immutable
The map is set in stone and cannot be changed.
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob >> &data, bool fatLeaves, std::uint32_t depth) const
void visitNodes(std::function< bool(SHAMapTreeNode &)> const &function) const
Visit every node in this SHAMap.
void gmn_ProcessDeferredReads(MissingNodes &)
@ Invalid
The map is known to not be valid.
value_type const * pointer
std::shared_ptr< Node > preFlushNode(std::shared_ptr< Node > node) const
prepare a node to be modified before flushing
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
const_iterator lower_bound(uint256 const &id) const
Find the object with the greatest object id smaller than the input id.
std::shared_ptr< Node > unshareNode(std::shared_ptr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
SHAMapTreeNode * descend(SHAMapInnerNode *, int branch) const
MissingNodes & operator=(const MissingNodes &)=delete
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
value_type const & reference
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
const_iterator & operator=(const_iterator const &other)=default
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
bool delItem(uint256 const &id)
std::uint32_t cowid_
ID to distinguish this map for all others we're sharing nodes with.
std::shared_ptr< SHAMapTreeNode > root_
SHAMapState
Describes the current state of a given SHAMap.
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
value_type const & reference