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;
272 Slice const& rootNode,
277 Slice const& rawNode,
314 dump(
bool withHashes =
false)
const;
362 template <
class Node>
367 template <
class Node>
379 int branch = 0)
const;
398 bool& pending)
const;
431 int& maxCount)
const;
588 : map_(map), item_(nullptr)
592 item_ = temp->peekItem().get();
596 : map_(map), item_(item)
604 : stack_(
std::move(stack)), map_(map), item_(item)
623 auto temp = map_->peekNextItem(item_->key(), stack_);
625 item_ = temp->peekItem().get();
652 inline SHAMap::const_iterator
void visitDifferences(SHAMap const *have, std::function< bool(SHAMapTreeNode const &)>) const
Visit every node in this SHAMap that is not present in the specified SHAMap.
static constexpr unsigned int branchFactor
Each non-leaf node has 16 children (the 'radix tree' part of the map)
std::shared_ptr< SHAMapTreeNode > descendNoStore(std::shared_ptr< SHAMapInnerNode > const &, int branch) const
SHAMap(SHAMap const &)=delete
SHAMapLeafNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
SHAMapHash getHash() const
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
std::shared_ptr< SHAMapTreeNode > fetchNodeFromDB(SHAMapHash const &hash) const
bool addItem(SHAMapNodeType type, SHAMapItem &&i)
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::shared_ptr< SHAMapItem const > const & onlyBelow(SHAMapTreeNode *) const
If there is only one leaf below this node, get its contents.
std::uint32_t generation_
std::shared_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
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
@ Modifying
The map is in flux and objects can be added and removed.
const_iterator begin() const
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
@ 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)
SHAMapTreeNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending) 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)
std::vector< std::tuple< SHAMapInnerNode *, SHAMapNodeID, int > > deferredReads_
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
SHAMap & operator=(SHAMap const &)=delete
SHAMapLeafNode const * peekFirstItem(SharedPtrNodeStack &stack) const
void visitLeaves(std::function< void(std::shared_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
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
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
reference operator*() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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.
SHAMapLeafNode * findKey(uint256 const &id) const
Return nullptr if key not found.
bool updateGiveItem(SHAMapNodeType type, std::shared_ptr< SHAMapItem const >)
const_iterator end() const
SHAMapLeafNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
bool addGiveItem(SHAMapNodeType type, std::shared_ptr< SHAMapItem const > item)
int unshare()
Convert any modified nodes to shared.
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
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.
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)
bool walkBranch(SHAMapTreeNode *node, std::shared_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
value_type const & reference
std::uint32_t ledgerSeq_
The sequence of the ledger that this map references, if any.
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< SHAMapNodeID > &nodeIDs, std::vector< Blob > &rawNodes, bool fatLeaves, std::uint32_t depth) const
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.
value_type const & reference