From 8e2d9496801ae10351cd63754aeefbe4e52c332a Mon Sep 17 00:00:00 2001 From: Bart <11445373+bthomee@users.noreply.github.com> Date: Thu, 23 Apr 2026 15:01:01 -0700 Subject: [PATCH] Review feedback --- include/xrpl/rdb/DatabaseCon.h | 2 +- include/xrpl/shamap/SHAMap.h | 77 +++++++++---------- .../xrpl/shamap/SHAMapAccountStateLeafNode.h | 2 +- include/xrpl/shamap/SHAMapInnerNode.h | 16 ++-- include/xrpl/shamap/SHAMapTreeNode.h | 2 + include/xrpl/shamap/SHAMapTxLeafNode.h | 2 +- .../xrpl/shamap/SHAMapTxPlusMetaLeafNode.h | 2 +- include/xrpl/shamap/TreeNodeCache.h | 2 +- include/xrpl/shamap/detail/TaggedPointer.h | 4 +- include/xrpl/shamap/detail/TaggedPointer.ipp | 34 ++++---- src/libxrpl/ledger/helpers/NFTokenHelpers.cpp | 1 + src/libxrpl/ledger/helpers/OfferHelpers.cpp | 1 + src/libxrpl/protocol/Quality.cpp | 2 + src/libxrpl/protocol/STInteger.cpp | 1 + src/libxrpl/protocol/STNumber.cpp | 1 + src/libxrpl/protocol/STValidation.cpp | 1 + src/libxrpl/shamap/SHAMap.cpp | 51 ++++++------ src/libxrpl/shamap/SHAMapDelta.cpp | 7 +- src/libxrpl/shamap/SHAMapInnerNode.cpp | 22 +++--- src/libxrpl/shamap/SHAMapSync.cpp | 18 ++--- src/libxrpl/shamap/SHAMapTreeNode.cpp | 10 +-- src/test/app/LedgerNodeHelpers_test.cpp | 16 ++-- src/test/app/PayChan_test.cpp | 1 + src/test/core/Config_test.cpp | 1 + src/test/jtx/impl/amount.cpp | 1 + src/test/rpc/DepositAuthorized_test.cpp | 1 + src/test/shamap/SHAMapSync_test.cpp | 13 ++-- src/xrpld/app/ledger/detail/BuildLedger.cpp | 2 + src/xrpld/app/ledger/detail/InboundLedger.cpp | 14 ++-- .../app/ledger/detail/InboundLedgers.cpp | 6 +- .../app/ledger/detail/InboundTransactions.cpp | 13 ++-- .../app/ledger/detail/LedgerNodeHelpers.cpp | 33 ++++---- .../app/ledger/detail/LedgerNodeHelpers.h | 12 ++- .../app/ledger/detail/LedgerPersistence.cpp | 2 + src/xrpld/app/ledger/detail/OpenLedger.cpp | 1 + .../app/ledger/detail/TransactionAcquire.cpp | 3 +- .../app/ledger/detail/TransactionAcquire.h | 2 +- src/xrpld/app/main/Application.cpp | 2 + src/xrpld/app/misc/FeeVoteImpl.cpp | 1 + src/xrpld/overlay/detail/PeerImp.cpp | 15 ++-- src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp | 1 + 41 files changed, 198 insertions(+), 200 deletions(-) diff --git a/include/xrpl/rdb/DatabaseCon.h b/include/xrpl/rdb/DatabaseCon.h index 579f30516b..2c689a3533 100644 --- a/include/xrpl/rdb/DatabaseCon.h +++ b/include/xrpl/rdb/DatabaseCon.h @@ -92,7 +92,7 @@ public: std::array lgrPragma; }; - struct CheckpointerSetup + struct CheckpointerSetup // NOLINT(cppcoreguidelines-pro-type-member-init) { JobQueue* jobQueue{}; std::reference_wrapper registry; diff --git a/include/xrpl/shamap/SHAMap.h b/include/xrpl/shamap/SHAMap.h index 41c43be5e2..5aafa435e0 100644 --- a/include/xrpl/shamap/SHAMap.h +++ b/include/xrpl/shamap/SHAMap.h @@ -74,6 +74,17 @@ enum class SHAMapState { See https://en.wikipedia.org/wiki/Merkle_tree */ + +/** Holds a SHAMap node's identity, serialized data, and leaf status. + Used by getNodeFat to return node data for peer synchronization. +*/ +struct SHAMapNodeData +{ + SHAMapNodeID nodeID; + Blob data; + bool isLeaf; +}; + class SHAMap { private: @@ -86,7 +97,7 @@ private: /** The sequence of the ledger that this map references, if any. */ std::uint32_t ledgerSeq_ = 0; - intr_ptr::SharedPtr root_; + SHAMapTreeNodePtr root_; mutable SHAMapState state_; SHAMapType const type_; bool backed_ = true; // Map is backed by the database @@ -254,7 +265,7 @@ public: bool getNodeFat( SHAMapNodeID const& wanted, - std::vector>& data, + std::vector& data, bool fatLeaves, std::uint32_t depth) const; @@ -296,10 +307,7 @@ public: * function. */ SHAMapAddNode - addRootNode( - SHAMapHash const& hash, - intr_ptr::SharedPtr rootNode, - SHAMapSyncFilter const* filter); + addRootNode(SHAMapHash const& hash, SHAMapTreeNodePtr rootNode, SHAMapSyncFilter const* filter); /** Add a known node at a specific position in the SHAMap during synchronization. * @@ -318,7 +326,7 @@ public: SHAMapAddNode addKnownNode( SHAMapNodeID const& nodeID, - intr_ptr::SharedPtr treeNode, + SHAMapTreeNodePtr treeNode, SHAMapSyncFilter const* filter); // status functions @@ -362,36 +370,32 @@ public: invariants() const; private: - using SharedPtrNodeStack = - std::stack, SHAMapNodeID>>; + using SharedPtrNodeStack = std::stack>; using DeltaRef = std::pair, boost::intrusive_ptr>; // tree node cache operations - intr_ptr::SharedPtr + SHAMapTreeNodePtr cacheLookup(SHAMapHash const& hash) const; void - canonicalize(SHAMapHash const& hash, intr_ptr::SharedPtr&) const; + canonicalize(SHAMapHash const& hash, SHAMapTreeNodePtr&) const; // database operations - intr_ptr::SharedPtr + SHAMapTreeNodePtr fetchNodeFromDB(SHAMapHash const& hash) const; - intr_ptr::SharedPtr + SHAMapTreeNodePtr fetchNodeNT(SHAMapHash const& hash) const; - intr_ptr::SharedPtr + SHAMapTreeNodePtr fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const; - intr_ptr::SharedPtr + SHAMapTreeNodePtr fetchNode(SHAMapHash const& hash) const; - intr_ptr::SharedPtr + SHAMapTreeNodePtr checkFilter(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const; /** Update hashes up to the root */ void - dirtyUp( - SharedPtrNodeStack& stack, - uint256 const& target, - intr_ptr::SharedPtr terminal); + dirtyUp(SharedPtrNodeStack& stack, uint256 const& target, SHAMapTreeNodePtr terminal); /** Walk towards the specified id, returning the node. Caller must check if the return is nullptr, and if not, if the node->peekItem()->key() == @@ -413,25 +417,21 @@ private: preFlushNode(intr_ptr::SharedPtr node) const; /** write and canonicalize modified node */ - intr_ptr::SharedPtr - writeNode(NodeObjectType t, intr_ptr::SharedPtr node) const; + SHAMapTreeNodePtr + writeNode(NodeObjectType t, SHAMapTreeNodePtr node) const; // returns the first item at or below this node SHAMapLeafNode* - firstBelow(intr_ptr::SharedPtr, SharedPtrNodeStack& stack, int branch = 0) - const; + firstBelow(SHAMapTreeNodePtr, SharedPtrNodeStack& stack, int branch = 0) const; // returns the last item at or below this node SHAMapLeafNode* - lastBelow( - intr_ptr::SharedPtr node, - SharedPtrNodeStack& stack, - int branch = branchFactor) const; + lastBelow(SHAMapTreeNodePtr node, SharedPtrNodeStack& stack, int branch = branchFactor) const; // helper function for firstBelow and lastBelow SHAMapLeafNode* belowHelper( - intr_ptr::SharedPtr node, + SHAMapTreeNodePtr node, SharedPtrNodeStack& stack, int branch, std::tuple, std::function> const& loopParams) @@ -443,15 +443,14 @@ private: descend(SHAMapInnerNode*, int branch) const; SHAMapTreeNode* descendThrow(SHAMapInnerNode*, int branch) const; - intr_ptr::SharedPtr + SHAMapTreeNodePtr descend(SHAMapInnerNode&, int branch) const; - intr_ptr::SharedPtr + SHAMapTreeNodePtr descendThrow(SHAMapInnerNode&, int branch) const; // Descend with filter // If pending, callback is called as if it called fetchNodeNT - using descendCallback = - std::function, SHAMapHash const&)>; + using descendCallback = std::function; SHAMapTreeNode* descendAsync( SHAMapInnerNode* parent, @@ -469,7 +468,7 @@ private: // Non-storing // Does not hook the returned node to its parent - intr_ptr::SharedPtr + SHAMapTreeNodePtr descendNoStore(SHAMapInnerNode&, int branch) const; /** If there is only one leaf below this node, get its contents */ @@ -531,10 +530,10 @@ private: // nodes we may have acquired from deferred reads using DeferredNode = std::tuple< - SHAMapInnerNode*, // parent node - SHAMapNodeID, // parent node ID - int, // branch - intr_ptr::SharedPtr>; // node + SHAMapInnerNode*, // parent node + SHAMapNodeID, // parent node ID + int, // branch + SHAMapTreeNodePtr>; // node int deferred_; std::mutex deferLock_; @@ -560,7 +559,7 @@ private: gmn_ProcessDeferredReads(MissingNodes&); // fetch from DB helper function - intr_ptr::SharedPtr + SHAMapTreeNodePtr finishFetch(SHAMapHash const& hash, std::shared_ptr const& object) const; }; diff --git a/include/xrpl/shamap/SHAMapAccountStateLeafNode.h b/include/xrpl/shamap/SHAMapAccountStateLeafNode.h index 2f71d10b0a..4588f71af5 100644 --- a/include/xrpl/shamap/SHAMapAccountStateLeafNode.h +++ b/include/xrpl/shamap/SHAMapAccountStateLeafNode.h @@ -27,7 +27,7 @@ public: { } - intr_ptr::SharedPtr + SHAMapTreeNodePtr clone(std::uint32_t cowid) const final { return intr_ptr::make_shared(item_, cowid, hash_); diff --git a/include/xrpl/shamap/SHAMapInnerNode.h b/include/xrpl/shamap/SHAMapInnerNode.h index f2c34cbc1a..fc43afcc0e 100644 --- a/include/xrpl/shamap/SHAMapInnerNode.h +++ b/include/xrpl/shamap/SHAMapInnerNode.h @@ -87,7 +87,7 @@ public: void partialDestructor() override; - intr_ptr::SharedPtr + SHAMapTreeNodePtr clone(std::uint32_t cowid) const override; SHAMapNodeType @@ -121,19 +121,19 @@ public: getChildHash(int m) const; void - setChild(int m, intr_ptr::SharedPtr child); + setChild(int m, SHAMapTreeNodePtr child); void - shareChild(int m, intr_ptr::SharedPtr const& child); + shareChild(int m, SHAMapTreeNodePtr const& child); SHAMapTreeNode* getChildPointer(int branch); - intr_ptr::SharedPtr + SHAMapTreeNodePtr getChild(int branch); - intr_ptr::SharedPtr - canonicalizeChild(int branch, intr_ptr::SharedPtr node); + SHAMapTreeNodePtr + canonicalizeChild(int branch, SHAMapTreeNodePtr node); // sync functions bool @@ -161,10 +161,10 @@ public: void invariants(bool is_root = false) const override; - static intr_ptr::SharedPtr + static SHAMapTreeNodePtr makeFullInner(Slice data, SHAMapHash const& hash, bool hashValid); - static intr_ptr::SharedPtr + static SHAMapTreeNodePtr makeCompressedInner(Slice data); }; diff --git a/include/xrpl/shamap/SHAMapTreeNode.h b/include/xrpl/shamap/SHAMapTreeNode.h index 55b18a2d12..e30c112bee 100644 --- a/include/xrpl/shamap/SHAMapTreeNode.h +++ b/include/xrpl/shamap/SHAMapTreeNode.h @@ -166,4 +166,6 @@ private: makeTransactionWithMeta(Slice data, SHAMapHash const& hash, bool hashValid); }; +using SHAMapTreeNodePtr = intr_ptr::SharedPtr; + } // namespace xrpl diff --git a/include/xrpl/shamap/SHAMapTxLeafNode.h b/include/xrpl/shamap/SHAMapTxLeafNode.h index 368aa2e21b..1db302f908 100644 --- a/include/xrpl/shamap/SHAMapTxLeafNode.h +++ b/include/xrpl/shamap/SHAMapTxLeafNode.h @@ -26,7 +26,7 @@ public: { } - intr_ptr::SharedPtr + SHAMapTreeNodePtr clone(std::uint32_t cowid) const final { return intr_ptr::make_shared(item_, cowid, hash_); diff --git a/include/xrpl/shamap/SHAMapTxPlusMetaLeafNode.h b/include/xrpl/shamap/SHAMapTxPlusMetaLeafNode.h index 40be482ed9..e3c5106960 100644 --- a/include/xrpl/shamap/SHAMapTxPlusMetaLeafNode.h +++ b/include/xrpl/shamap/SHAMapTxPlusMetaLeafNode.h @@ -27,7 +27,7 @@ public: { } - intr_ptr::SharedPtr + SHAMapTreeNodePtr clone(std::uint32_t cowid) const override { return intr_ptr::make_shared(item_, cowid, hash_); diff --git a/include/xrpl/shamap/TreeNodeCache.h b/include/xrpl/shamap/TreeNodeCache.h index 4edb6348ec..2d5782c7e9 100644 --- a/include/xrpl/shamap/TreeNodeCache.h +++ b/include/xrpl/shamap/TreeNodeCache.h @@ -11,5 +11,5 @@ using TreeNodeCache = TaggedCache< SHAMapTreeNode, /*IsKeyCache*/ false, intr_ptr::SharedWeakUnionPtr, - intr_ptr::SharedPtr>; + SHAMapTreeNodePtr>; } // namespace xrpl diff --git a/include/xrpl/shamap/detail/TaggedPointer.h b/include/xrpl/shamap/detail/TaggedPointer.h index d7adde4b05..2120335bb5 100644 --- a/include/xrpl/shamap/detail/TaggedPointer.h +++ b/include/xrpl/shamap/detail/TaggedPointer.h @@ -148,7 +148,7 @@ public: /** Get the number of elements in each array and a pointer to the start of each array. */ - [[nodiscard]] std::tuple*> + [[nodiscard]] std::tuple getHashesAndChildren() const; /** Get the `hashes` array */ @@ -156,7 +156,7 @@ public: getHashes() const; /** Get the `children` array */ - [[nodiscard]] intr_ptr::SharedPtr* + [[nodiscard]] SHAMapTreeNodePtr* getChildren() const; /** Call the `f` callback for all 16 (branchFactor) branches - even if diff --git a/include/xrpl/shamap/detail/TaggedPointer.ipp b/include/xrpl/shamap/detail/TaggedPointer.ipp index 903108ac66..f3133f0646 100644 --- a/include/xrpl/shamap/detail/TaggedPointer.ipp +++ b/include/xrpl/shamap/detail/TaggedPointer.ipp @@ -25,8 +25,7 @@ static_assert( // Terminology: A chunk is the memory being allocated from a block. A block // contains multiple chunks. This is the terminology the boost documentation // uses. Pools use "Simple Segregated Storage" as their storage format. -constexpr size_t elementSizeBytes = - (sizeof(SHAMapHash) + sizeof(intr_ptr::SharedPtr)); +constexpr size_t elementSizeBytes = (sizeof(SHAMapHash) + sizeof(SHAMapTreeNodePtr)); constexpr size_t blockSizeBytes = kilobytes(512); @@ -363,8 +362,7 @@ inline TaggedPointer::TaggedPointer( // keep new (&dstHashes[dstIndex]) SHAMapHash{srcHashes[srcIndex]}; - new (&dstChildren[dstIndex]) - intr_ptr::SharedPtr{std::move(srcChildren[srcIndex])}; + new (&dstChildren[dstIndex]) SHAMapTreeNodePtr{std::move(srcChildren[srcIndex])}; ++dstIndex; ++srcIndex; } @@ -375,7 +373,7 @@ inline TaggedPointer::TaggedPointer( if (dstIsDense) { new (&dstHashes[dstIndex]) SHAMapHash{}; - new (&dstChildren[dstIndex]) intr_ptr::SharedPtr{}; + new (&dstChildren[dstIndex]) SHAMapTreeNodePtr{}; ++dstIndex; } } @@ -383,7 +381,7 @@ inline TaggedPointer::TaggedPointer( { // add new (&dstHashes[dstIndex]) SHAMapHash{}; - new (&dstChildren[dstIndex]) intr_ptr::SharedPtr{}; + new (&dstChildren[dstIndex]) SHAMapTreeNodePtr{}; ++dstIndex; if (srcIsDense) { @@ -396,7 +394,7 @@ inline TaggedPointer::TaggedPointer( if (dstIsDense) { new (&dstHashes[dstIndex]) SHAMapHash{}; - new (&dstChildren[dstIndex]) intr_ptr::SharedPtr{}; + new (&dstChildren[dstIndex]) SHAMapTreeNodePtr{}; ++dstIndex; } if (srcIsDense) @@ -413,7 +411,7 @@ inline TaggedPointer::TaggedPointer( for (int i = dstIndex; i < dstNumAllocated; ++i) { new (&dstHashes[i]) SHAMapHash{}; - new (&dstChildren[i]) intr_ptr::SharedPtr{}; + new (&dstChildren[i]) SHAMapTreeNodePtr{}; } *this = std::move(dst); } @@ -433,7 +431,7 @@ inline TaggedPointer::TaggedPointer( // allocate hashes and children, but do not run constructors TaggedPointer newHashesAndChildren{RawAllocateTag{}, toAllocate}; SHAMapHash *newHashes, *oldHashes; - intr_ptr::SharedPtr*newChildren, *oldChildren; + SHAMapTreeNodePtr *newChildren, *oldChildren; std::uint8_t newNumAllocated; // structured bindings can't be captured in c++ 17; use tie instead std::tie(newNumAllocated, newHashes, newChildren) = newHashesAndChildren.getHashesAndChildren(); @@ -444,8 +442,7 @@ inline TaggedPointer::TaggedPointer( // new arrays are dense, old arrays are sparse iterNonEmptyChildIndexes(isBranch, [&](auto branchNum, auto indexNum) { new (&newHashes[branchNum]) SHAMapHash{oldHashes[indexNum]}; - new (&newChildren[branchNum]) - intr_ptr::SharedPtr{std::move(oldChildren[indexNum])}; + new (&newChildren[branchNum]) SHAMapTreeNodePtr{std::move(oldChildren[indexNum])}; }); // Run the constructors for the remaining elements for (int i = 0; i < SHAMapInnerNode::branchFactor; ++i) @@ -453,7 +450,7 @@ inline TaggedPointer::TaggedPointer( if ((1 << i) & isBranch) continue; new (&newHashes[i]) SHAMapHash{}; - new (&newChildren[i]) intr_ptr::SharedPtr{}; + new (&newChildren[i]) SHAMapTreeNodePtr{}; } } else @@ -463,14 +460,14 @@ inline TaggedPointer::TaggedPointer( iterNonEmptyChildIndexes(isBranch, [&](auto branchNum, auto indexNum) { new (&newHashes[curCompressedIndex]) SHAMapHash{oldHashes[indexNum]}; new (&newChildren[curCompressedIndex]) - intr_ptr::SharedPtr{std::move(oldChildren[indexNum])}; + SHAMapTreeNodePtr{std::move(oldChildren[indexNum])}; ++curCompressedIndex; }); // Run the constructors for the remaining elements for (int i = curCompressedIndex; i < newNumAllocated; ++i) { new (&newHashes[i]) SHAMapHash{}; - new (&newChildren[i]) intr_ptr::SharedPtr{}; + new (&newChildren[i]) SHAMapTreeNodePtr{}; } } @@ -484,7 +481,7 @@ inline TaggedPointer::TaggedPointer(std::uint8_t numChildren) for (std::size_t i = 0; i < numAllocated; ++i) { new (&hashes[i]) SHAMapHash{}; - new (&children[i]) intr_ptr::SharedPtr{}; + new (&children[i]) SHAMapTreeNodePtr{}; } } @@ -522,14 +519,13 @@ TaggedPointer::isDense() const return (tp_ & tagMask) == boundaries.size() - 1; } -[[nodiscard]] inline std::tuple*> +[[nodiscard]] inline std::tuple TaggedPointer::getHashesAndChildren() const { auto const [tag, ptr] = decode(); auto const hashes = reinterpret_cast(ptr); std::uint8_t numAllocated = boundaries[tag]; - auto const children = - reinterpret_cast*>(hashes + numAllocated); + auto const children = reinterpret_cast(hashes + numAllocated); return {numAllocated, hashes, children}; }; @@ -539,7 +535,7 @@ TaggedPointer::getHashes() const return reinterpret_cast(tp_ & ptrMask); }; -[[nodiscard]] inline intr_ptr::SharedPtr* +[[nodiscard]] inline SHAMapTreeNodePtr* TaggedPointer::getChildren() const { auto [unused1, unused2, result] = getHashesAndChildren(); diff --git a/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp b/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp index f57294a855..1a2b86b3d5 100644 --- a/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libxrpl/ledger/helpers/OfferHelpers.cpp b/src/libxrpl/ledger/helpers/OfferHelpers.cpp index d57066cfe2..03a1170aad 100644 --- a/src/libxrpl/ledger/helpers/OfferHelpers.cpp +++ b/src/libxrpl/ledger/helpers/OfferHelpers.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include // IWYU pragma: keep #include diff --git a/src/libxrpl/protocol/Quality.cpp b/src/libxrpl/protocol/Quality.cpp index 5f38f2219b..37925cddd4 100644 --- a/src/libxrpl/protocol/Quality.cpp +++ b/src/libxrpl/protocol/Quality.cpp @@ -1,10 +1,12 @@ #include +#include #include #include #include #include +#include namespace xrpl { diff --git a/src/libxrpl/protocol/STInteger.cpp b/src/libxrpl/protocol/STInteger.cpp index 0530a784d9..db6ca03410 100644 --- a/src/libxrpl/protocol/STInteger.cpp +++ b/src/libxrpl/protocol/STInteger.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace xrpl { diff --git a/src/libxrpl/protocol/STNumber.cpp b/src/libxrpl/protocol/STNumber.cpp index 25aa9eaa05..b073a56700 100644 --- a/src/libxrpl/protocol/STNumber.cpp +++ b/src/libxrpl/protocol/STNumber.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libxrpl/protocol/STValidation.cpp b/src/libxrpl/protocol/STValidation.cpp index 14349d3f85..661a168e5c 100644 --- a/src/libxrpl/protocol/STValidation.cpp +++ b/src/libxrpl/protocol/STValidation.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libxrpl/shamap/SHAMap.cpp b/src/libxrpl/shamap/SHAMap.cpp index 1895941626..05407a35c5 100644 --- a/src/libxrpl/shamap/SHAMap.cpp +++ b/src/libxrpl/shamap/SHAMap.cpp @@ -97,10 +97,7 @@ SHAMap::snapShot(bool isMutable) const } void -SHAMap::dirtyUp( - SharedPtrNodeStack& stack, - uint256 const& target, - intr_ptr::SharedPtr child) +SHAMap::dirtyUp(SharedPtrNodeStack& stack, uint256 const& target, SHAMapTreeNodePtr child) { // walk the tree up from through the inner nodes to the root_ // update hashes and links @@ -165,7 +162,7 @@ SHAMap::findKey(uint256 const& id) const return leaf; } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::fetchNodeFromDB(SHAMapHash const& hash) const { XRPL_ASSERT(backed_, "xrpl::SHAMap::fetchNodeFromDB : is backed"); @@ -173,7 +170,7 @@ SHAMap::fetchNodeFromDB(SHAMapHash const& hash) const return finishFetch(hash, obj); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::finishFetch(SHAMapHash const& hash, std::shared_ptr const& object) const { XRPL_ASSERT(backed_, "xrpl::SHAMap::finishFetch : is backed"); @@ -208,7 +205,7 @@ SHAMap::finishFetch(SHAMapHash const& hash, std::shared_ptr const& o } // See if a sync filter has a node -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::checkFilter(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const { if (auto nodeData = filter->getNode(hash)) @@ -234,7 +231,7 @@ SHAMap::checkFilter(SHAMapHash const& hash, SHAMapSyncFilter const* filter) cons // Get a node without throwing // Used on maps where missing nodes are expected -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter const* filter) const { auto node = cacheLookup(hash); @@ -257,7 +254,7 @@ SHAMap::fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter const* filter) cons return node; } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::fetchNodeNT(SHAMapHash const& hash) const { auto node = cacheLookup(hash); @@ -269,7 +266,7 @@ SHAMap::fetchNodeNT(SHAMapHash const& hash) const } // Throw if the node is missing -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::fetchNode(SHAMapHash const& hash) const { auto node = fetchNodeNT(hash); @@ -291,10 +288,10 @@ SHAMap::descendThrow(SHAMapInnerNode* parent, int branch) const return ret; } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::descendThrow(SHAMapInnerNode& parent, int branch) const { - intr_ptr::SharedPtr ret = descend(parent, branch); + SHAMapTreeNodePtr ret = descend(parent, branch); if (!ret && !parent.isEmptyBranch(branch)) Throw(type_, parent.getChildHash(branch)); @@ -309,7 +306,7 @@ SHAMap::descend(SHAMapInnerNode* parent, int branch) const if ((ret != nullptr) || !backed_) return ret; - intr_ptr::SharedPtr node = fetchNodeNT(parent->getChildHash(branch)); + SHAMapTreeNodePtr node = fetchNodeNT(parent->getChildHash(branch)); if (!node) return nullptr; @@ -317,10 +314,10 @@ SHAMap::descend(SHAMapInnerNode* parent, int branch) const return node.get(); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::descend(SHAMapInnerNode& parent, int branch) const { - intr_ptr::SharedPtr node = parent.getChild(branch); + SHAMapTreeNodePtr node = parent.getChild(branch); if (node || !backed_) return node; @@ -334,10 +331,10 @@ SHAMap::descend(SHAMapInnerNode& parent, int branch) const // Gets the node that would be hooked to this branch, // but doesn't hook it up. -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::descendNoStore(SHAMapInnerNode& parent, int branch) const { - intr_ptr::SharedPtr ret = parent.getChild(branch); + SHAMapTreeNodePtr ret = parent.getChild(branch); if (!ret && backed_) ret = fetchNode(parent.getChildHash(branch)); return ret; @@ -361,7 +358,7 @@ SHAMap::descend( if (child == nullptr) { auto const& childHash = parent->getChildHash(branch); - intr_ptr::SharedPtr childNode = fetchNodeNT(childHash, filter); + SHAMapTreeNodePtr childNode = fetchNodeNT(childHash, filter); if (childNode) { @@ -434,7 +431,7 @@ SHAMap::unshareNode(intr_ptr::SharedPtr node, SHAMapNodeID const& nodeID) SHAMapLeafNode* SHAMap::belowHelper( - intr_ptr::SharedPtr node, + SHAMapTreeNodePtr node, SharedPtrNodeStack& stack, int branch, std::tuple, std::function> const& loopParams) const @@ -479,8 +476,7 @@ SHAMap::belowHelper( return nullptr; } SHAMapLeafNode* -SHAMap::lastBelow(intr_ptr::SharedPtr node, SharedPtrNodeStack& stack, int branch) - const +SHAMap::lastBelow(SHAMapTreeNodePtr node, SharedPtrNodeStack& stack, int branch) const { auto init = branchFactor - 1; auto cmp = [](int i) { return i >= 0; }; @@ -489,8 +485,7 @@ SHAMap::lastBelow(intr_ptr::SharedPtr node, SharedPtrNodeStack& return belowHelper(node, stack, branch, {init, cmp, incr}); } SHAMapLeafNode* -SHAMap::firstBelow(intr_ptr::SharedPtr node, SharedPtrNodeStack& stack, int branch) - const +SHAMap::firstBelow(SHAMapTreeNodePtr node, SharedPtrNodeStack& stack, int branch) const { auto init = 0; auto cmp = [](int i) { return i <= branchFactor; }; @@ -699,7 +694,7 @@ SHAMap::delItem(uint256 const& id) SHAMapNodeType const type = leaf->getType(); - using TreeNodeType = intr_ptr::SharedPtr; + using TreeNodeType = SHAMapTreeNodePtr; // What gets attached to the end of the chain (For now, nothing, since we deleted the leaf) TreeNodeType prevNode; @@ -937,8 +932,8 @@ SHAMap::fetchRoot(SHAMapHash const& hash, SHAMapSyncFilter* filter) @note The node must have already been unshared by having the caller first call SHAMapTreeNode::unshare(). */ -intr_ptr::SharedPtr -SHAMap::writeNode(NodeObjectType t, intr_ptr::SharedPtr node) const +SHAMapTreeNodePtr +SHAMap::writeNode(NodeObjectType t, SHAMapTreeNodePtr node) const { XRPL_ASSERT(node->cowid() == 0, "xrpl::SHAMap::writeNode : valid input node"); XRPL_ASSERT(backed_, "xrpl::SHAMap::writeNode : is backed"); @@ -1155,7 +1150,7 @@ SHAMap::dump(bool hash) const JLOG(journal_.info()) << leafCount << " resident leaves"; } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMap::cacheLookup(SHAMapHash const& hash) const { auto ret = f_.getTreeNodeCache()->fetch(hash.as_uint256()); @@ -1164,7 +1159,7 @@ SHAMap::cacheLookup(SHAMapHash const& hash) const } void -SHAMap::canonicalize(SHAMapHash const& hash, intr_ptr::SharedPtr& node) const +SHAMap::canonicalize(SHAMapHash const& hash, SHAMapTreeNodePtr& node) const { XRPL_ASSERT(backed_, "xrpl::SHAMap::canonicalize : is backed"); XRPL_ASSERT(node->cowid() == 0, "xrpl::SHAMap::canonicalize : valid node input"); diff --git a/src/libxrpl/shamap/SHAMapDelta.cpp b/src/libxrpl/shamap/SHAMapDelta.cpp index d8162710be..695c00b62f 100644 --- a/src/libxrpl/shamap/SHAMapDelta.cpp +++ b/src/libxrpl/shamap/SHAMapDelta.cpp @@ -261,7 +261,7 @@ SHAMap::walkMap(std::vector& missingNodes, int maxMissing) co { if (!node->isEmptyBranch(i)) { - intr_ptr::SharedPtr const nextNode = descendNoStore(*node, i); + SHAMapTreeNodePtr const nextNode = descendNoStore(*node, i); if (nextNode) { @@ -286,7 +286,7 @@ SHAMap::walkMapParallel(std::vector& missingNodes, int maxMis return false; using StackEntry = intr_ptr::SharedPtr; - std::array, 16> topChildren; + std::array topChildren; { auto const& innerRoot = intr_ptr::static_pointer_cast(root_); for (int i = 0; i < 16; ++i) @@ -331,8 +331,7 @@ SHAMap::walkMapParallel(std::vector& missingNodes, int maxMis { if (node->isEmptyBranch(i)) continue; - intr_ptr::SharedPtr const nextNode = - descendNoStore(*node, i); + SHAMapTreeNodePtr const nextNode = descendNoStore(*node, i); if (nextNode) { diff --git a/src/libxrpl/shamap/SHAMapInnerNode.cpp b/src/libxrpl/shamap/SHAMapInnerNode.cpp index e501561ee4..bfa4d78f45 100644 --- a/src/libxrpl/shamap/SHAMapInnerNode.cpp +++ b/src/libxrpl/shamap/SHAMapInnerNode.cpp @@ -37,7 +37,7 @@ SHAMapInnerNode::~SHAMapInnerNode() = default; void SHAMapInnerNode::partialDestructor() { - intr_ptr::SharedPtr* children = nullptr; + SHAMapTreeNodePtr* children = nullptr; // structured bindings can't be captured in c++ 17; use tie instead std::tie(std::ignore, std::ignore, children) = hashesAndChildren_.getHashesAndChildren(); iterNonEmptyChildIndexes([&](auto branchNum, auto indexNum) { children[indexNum].reset(); }); @@ -69,7 +69,7 @@ SHAMapInnerNode::getChildIndex(int i) const return hashesAndChildren_.getChildIndex(isBranch_, i); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapInnerNode::clone(std::uint32_t cowid) const { auto const branchCount = getBranchCount(); @@ -79,7 +79,7 @@ SHAMapInnerNode::clone(std::uint32_t cowid) const p->isBranch_ = isBranch_; p->fullBelowGen_ = fullBelowGen_; SHAMapHash *cloneHashes = nullptr, *thisHashes = nullptr; - intr_ptr::SharedPtr*cloneChildren = nullptr, *thisChildren = nullptr; + SHAMapTreeNodePtr *cloneChildren = nullptr, *thisChildren = nullptr; // structured bindings can't be captured in c++ 17; use tie instead std::tie(std::ignore, cloneHashes, cloneChildren) = p->hashesAndChildren_.getHashesAndChildren(); @@ -118,7 +118,7 @@ SHAMapInnerNode::clone(std::uint32_t cowid) const return p; } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapInnerNode::makeFullInner(Slice data, SHAMapHash const& hash, bool hashValid) { // A full inner node is serialized as 16 256-bit hashes, back to back: @@ -153,7 +153,7 @@ SHAMapInnerNode::makeFullInner(Slice data, SHAMapHash const& hash, bool hashVali return ret; } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapInnerNode::makeCompressedInner(Slice data) { // A compressed inner node is serialized as a series of 33 byte chunks, @@ -207,7 +207,7 @@ void SHAMapInnerNode::updateHashDeep() { SHAMapHash* hashes = nullptr; - intr_ptr::SharedPtr* children = nullptr; + SHAMapTreeNodePtr* children = nullptr; // structured bindings can't be captured in c++ 17; use tie instead std::tie(std::ignore, hashes, children) = hashesAndChildren_.getHashesAndChildren(); iterNonEmptyChildIndexes([&](auto branchNum, auto indexNum) { @@ -265,7 +265,7 @@ SHAMapInnerNode::getString(SHAMapNodeID const& id) const // We are modifying an inner node void -SHAMapInnerNode::setChild(int m, intr_ptr::SharedPtr child) +SHAMapInnerNode::setChild(int m, SHAMapTreeNodePtr child) { XRPL_ASSERT( (m >= 0) && (m < branchFactor), "xrpl::SHAMapInnerNode::setChild : valid branch input"); @@ -306,7 +306,7 @@ SHAMapInnerNode::setChild(int m, intr_ptr::SharedPtr child) // finished modifying, now make shareable void -SHAMapInnerNode::shareChild(int m, intr_ptr::SharedPtr const& child) +SHAMapInnerNode::shareChild(int m, SHAMapTreeNodePtr const& child) { XRPL_ASSERT( (m >= 0) && (m < branchFactor), "xrpl::SHAMapInnerNode::shareChild : valid branch input"); @@ -334,7 +334,7 @@ SHAMapInnerNode::getChildPointer(int branch) return hashesAndChildren_.getChildren()[index].get(); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapInnerNode::getChild(int branch) { XRPL_ASSERT( @@ -360,8 +360,8 @@ SHAMapInnerNode::getChildHash(int m) const return zeroSHAMapHash; } -intr_ptr::SharedPtr -SHAMapInnerNode::canonicalizeChild(int branch, intr_ptr::SharedPtr node) +SHAMapTreeNodePtr +SHAMapInnerNode::canonicalizeChild(int branch, SHAMapTreeNodePtr node) { XRPL_ASSERT( branch >= 0 && branch < branchFactor, diff --git a/src/libxrpl/shamap/SHAMapSync.cpp b/src/libxrpl/shamap/SHAMapSync.cpp index 7507c63ca1..eddce058a9 100644 --- a/src/libxrpl/shamap/SHAMapSync.cpp +++ b/src/libxrpl/shamap/SHAMapSync.cpp @@ -66,7 +66,7 @@ SHAMap::visitNodes(std::function const& function) const { if (!node->isEmptyBranch(pos)) { - intr_ptr::SharedPtr const child = descendNoStore(*node, pos); + SHAMapTreeNodePtr const child = descendNoStore(*node, pos); if (!function(*child)) return; @@ -204,8 +204,7 @@ SHAMap::gmn_ProcessNodes(MissingNodes& mn, MissingNodes::StackEntry& se) branch, mn.filter_, pending, - [node, nodeID, branch, &mn]( - intr_ptr::SharedPtr found, SHAMapHash const&) { + [node, nodeID, branch, &mn](SHAMapTreeNodePtr found, SHAMapHash const&) { // a read completed asynchronously std::unique_lock const lock{mn.deferLock_}; mn.finishedReads_.emplace_back(node, nodeID, branch, std::move(found)); @@ -268,8 +267,7 @@ SHAMap::gmn_ProcessDeferredReads(MissingNodes& mn) int complete = 0; while (complete != mn.deferred_) { - std::tuple> - deferredNode; + std::tuple deferredNode; { std::unique_lock lock{mn.deferLock_}; @@ -417,7 +415,7 @@ SHAMap::getMissingNodes(int max, SHAMapSyncFilter* filter) bool SHAMap::getNodeFat( SHAMapNodeID const& wanted, - std::vector>& data, + std::vector& data, bool fatLeaves, std::uint32_t depth) const { @@ -463,7 +461,7 @@ SHAMap::getNodeFat( // Add this node to the reply s.erase(); node->serializeForWire(s); - data.emplace_back(nodeID, s.getData(), node->isLeaf()); + data.push_back({nodeID, s.getData(), node->isLeaf()}); if (node->isInner()) { @@ -493,7 +491,7 @@ SHAMap::getNodeFat( // Just include this node s.erase(); childNode->serializeForWire(s); - data.emplace_back(childID, s.getData(), childNode->isLeaf()); + data.push_back({childID, s.getData(), childNode->isLeaf()}); } } } @@ -513,7 +511,7 @@ SHAMap::serializeRoot(Serializer& s) const SHAMapAddNode SHAMap::addRootNode( SHAMapHash const& hash, - intr_ptr::SharedPtr rootNode, + SHAMapTreeNodePtr rootNode, SHAMapSyncFilter const* filter) { XRPL_ASSERT(rootNode, "xrpl::SHAMap::addRootNode : non-null root node"); @@ -560,7 +558,7 @@ SHAMap::addRootNode( SHAMapAddNode SHAMap::addKnownNode( SHAMapNodeID const& nodeID, - intr_ptr::SharedPtr treeNode, + SHAMapTreeNodePtr treeNode, SHAMapSyncFilter const* filter) { XRPL_ASSERT(!nodeID.isRoot(), "xrpl::SHAMap::addKnownNode : valid node input"); diff --git a/src/libxrpl/shamap/SHAMapTreeNode.cpp b/src/libxrpl/shamap/SHAMapTreeNode.cpp index 6fc7bd81e4..1660fadfa4 100644 --- a/src/libxrpl/shamap/SHAMapTreeNode.cpp +++ b/src/libxrpl/shamap/SHAMapTreeNode.cpp @@ -25,7 +25,7 @@ namespace xrpl { -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapTreeNode::makeTransaction(Slice data, SHAMapHash const& hash, bool hashValid) { auto item = make_shamapitem(sha512Half(HashPrefix::transactionID, data), data); @@ -36,7 +36,7 @@ SHAMapTreeNode::makeTransaction(Slice data, SHAMapHash const& hash, bool hashVal return intr_ptr::make_shared(std::move(item), 0); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapTreeNode::makeTransactionWithMeta(Slice data, SHAMapHash const& hash, bool hashValid) { Serializer s(data.data(), data.size()); @@ -60,7 +60,7 @@ SHAMapTreeNode::makeTransactionWithMeta(Slice data, SHAMapHash const& hash, bool return intr_ptr::make_shared(std::move(item), 0); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapTreeNode::makeAccountState(Slice data, SHAMapHash const& hash, bool hashValid) { Serializer s(data.data(), data.size()); @@ -87,7 +87,7 @@ SHAMapTreeNode::makeAccountState(Slice data, SHAMapHash const& hash, bool hashVa return intr_ptr::make_shared(std::move(item), 0); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapTreeNode::makeFromWire(Slice rawNode) { if (rawNode.empty()) @@ -118,7 +118,7 @@ SHAMapTreeNode::makeFromWire(Slice rawNode) Throw("wire: Unknown type (" + std::to_string(type) + ")"); } -intr_ptr::SharedPtr +SHAMapTreeNodePtr SHAMapTreeNode::makeFromPrefix(Slice rawNode, SHAMapHash const& hash) { if (rawNode.size() < 4) diff --git a/src/test/app/LedgerNodeHelpers_test.cpp b/src/test/app/LedgerNodeHelpers_test.cpp index 447190fa8c..4636fcf325 100644 --- a/src/test/app/LedgerNodeHelpers_test.cpp +++ b/src/test/app/LedgerNodeHelpers_test.cpp @@ -22,7 +22,6 @@ namespace xrpl::tests { class LedgerNodeHelpers_test : public beast::unit_test::suite { - // Helper function to create a simple SHAMapItem for testing. static boost::intrusive_ptr makeTestItem(std::uint32_t seed) { @@ -33,9 +32,8 @@ class LedgerNodeHelpers_test : public beast::unit_test::suite return make_shamapitem(s.getSHA512Half(), s.slice()); } - // Helper function to serialize a tree node to wire format. static std::string - serializeNode(intr_ptr::SharedPtr const& node) + serializeNode(SHAMapTreeNodePtr const& node) { Serializer s; node->serializeForWire(s); @@ -267,7 +265,7 @@ class LedgerNodeHelpers_test : public beast::unit_test::suite protocol::TMLedgerNode ledgerNode; ledgerNode.set_nodedata(leafData); ledgerNode.set_nodeid(leafID.getRawString()); - auto result = getSHAMapNodeID(ledgerNode, leafNode); + auto const result = getSHAMapNodeID(ledgerNode, leafNode); BEAST_EXPECT(result.has_value()); BEAST_EXPECT(*result == leafID); } @@ -280,7 +278,7 @@ class LedgerNodeHelpers_test : public beast::unit_test::suite protocol::TMLedgerNode ledgerNode; ledgerNode.set_nodedata(leafData); ledgerNode.set_id(leafID.getRawString()); - auto result = getSHAMapNodeID(ledgerNode, leafNode); + auto const result = getSHAMapNodeID(ledgerNode, leafNode); BEAST_EXPECT(!result.has_value()); } @@ -292,7 +290,7 @@ class LedgerNodeHelpers_test : public beast::unit_test::suite protocol::TMLedgerNode node; node.set_nodedata(leafData); node.set_depth(leafDepth); - auto result = getSHAMapNodeID(node, leafNode); + auto const result = getSHAMapNodeID(node, leafNode); BEAST_EXPECT(result.has_value()); BEAST_EXPECT(*result == leafID); } @@ -305,7 +303,7 @@ class LedgerNodeHelpers_test : public beast::unit_test::suite protocol::TMLedgerNode ledgerNode; ledgerNode.set_nodedata(leafData); ledgerNode.set_depth(leafDepth); - auto result = getSHAMapNodeID(ledgerNode, leafNode); + auto const result = getSHAMapNodeID(ledgerNode, leafNode); BEAST_EXPECT(result.has_value()); BEAST_EXPECT(*result == leafID); } @@ -321,7 +319,7 @@ class LedgerNodeHelpers_test : public beast::unit_test::suite protocol::TMLedgerNode node; node.set_nodedata(leafData); node.set_depth(leafDepth); - auto result = getSHAMapNodeID(node, leafNode); + auto const result = getSHAMapNodeID(node, leafNode); BEAST_EXPECT(result.has_value()); BEAST_EXPECT(*result == leafID); } @@ -339,7 +337,7 @@ class LedgerNodeHelpers_test : public beast::unit_test::suite protocol::TMLedgerNode ledgerNode; ledgerNode.set_nodedata(otherData); ledgerNode.set_nodeid(otherID.getRawString()); - auto result = getSHAMapNodeID(ledgerNode, leafNode); + auto const result = getSHAMapNodeID(ledgerNode, leafNode); BEAST_EXPECT(!result.has_value()); } } diff --git a/src/test/app/PayChan_test.cpp b/src/test/app/PayChan_test.cpp index 1f4376a656..624893cf67 100644 --- a/src/test/app/PayChan_test.cpp +++ b/src/test/app/PayChan_test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/src/test/core/Config_test.cpp b/src/test/core/Config_test.cpp index a3137b8e69..40e3305622 100644 --- a/src/test/core/Config_test.cpp +++ b/src/test/core/Config_test.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/src/test/jtx/impl/amount.cpp b/src/test/jtx/impl/amount.cpp index 1a02e07bdf..0d889b14c8 100644 --- a/src/test/jtx/impl/amount.cpp +++ b/src/test/jtx/impl/amount.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/src/test/rpc/DepositAuthorized_test.cpp b/src/test/rpc/DepositAuthorized_test.cpp index 900adb5c7e..1363f54e85 100644 --- a/src/test/rpc/DepositAuthorized_test.cpp +++ b/src/test/rpc/DepositAuthorized_test.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/src/test/shamap/SHAMapSync_test.cpp b/src/test/shamap/SHAMapSync_test.cpp index 2f45f6a579..51b947123b 100644 --- a/src/test/shamap/SHAMapSync_test.cpp +++ b/src/test/shamap/SHAMapSync_test.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include #include @@ -21,7 +20,6 @@ #include #include #include -#include #include #include @@ -116,13 +114,13 @@ public: destination.setSynching(); { - std::vector> a; + std::vector a; BEAST_EXPECT(source.getNodeFat(SHAMapNodeID(), a, rand_bool(eng_), rand_int(eng_, 2))); unexpected(a.empty(), "NodeSize"); - auto node = SHAMapTreeNode::makeFromWire(makeSlice(std::get<1>(a[0]))); + auto node = SHAMapTreeNode::makeFromWire(makeSlice(a[0].data)); if (!node) fail("", __FILE__, __LINE__); BEAST_EXPECT( @@ -140,7 +138,7 @@ public: break; // get as many nodes as possible based on this information - std::vector> b; + std::vector b; for (auto& it : nodesMissing) { @@ -162,11 +160,10 @@ public: // Don't use BEAST_EXPECT here b/c it will be called a // non-deterministic number of times and the number of tests run // should be deterministic - auto node = SHAMapTreeNode::makeFromWire(makeSlice(std::get<1>(b[i]))); + auto node = SHAMapTreeNode::makeFromWire(makeSlice(b[i].data)); if (!node) fail("", __FILE__, __LINE__); - if (!destination.addKnownNode(std::get<0>(b[i]), std::move(node), nullptr) - .isUseful()) + if (!destination.addKnownNode(b[i].nodeID, std::move(node), nullptr).isUseful()) fail("", __FILE__, __LINE__); } } while (true); diff --git a/src/xrpld/app/ledger/detail/BuildLedger.cpp b/src/xrpld/app/ledger/detail/BuildLedger.cpp index 8f5184336a..326260f05d 100644 --- a/src/xrpld/app/ledger/detail/BuildLedger.cpp +++ b/src/xrpld/app/ledger/detail/BuildLedger.cpp @@ -13,8 +13,10 @@ #include #include #include +#include #include #include +#include #include #include diff --git a/src/xrpld/app/ledger/detail/InboundLedger.cpp b/src/xrpld/app/ledger/detail/InboundLedger.cpp index 0b6af3b561..858d5644cd 100644 --- a/src/xrpld/app/ledger/detail/InboundLedger.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedger.cpp @@ -22,9 +22,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -882,9 +884,9 @@ InboundLedger::receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode& san) { auto const f = filter.get(); - for (auto const& ledger_node : packet.nodes()) + for (auto const& ledgerNode : packet.nodes()) { - auto treeNode = getTreeNode(ledger_node.nodedata()); + auto treeNode = getTreeNode(ledgerNode.nodedata()); if (!treeNode) { JLOG(journal_.warn()) << "Got invalid node data"; @@ -892,7 +894,7 @@ InboundLedger::receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode& san) return; } - auto const nodeID = getSHAMapNodeID(ledger_node, *treeNode); + auto const nodeID = getSHAMapNodeID(ledgerNode, *treeNode); if (!nodeID) { JLOG(journal_.warn()) << "Got invalid node id"; @@ -1141,12 +1143,12 @@ InboundLedger::processData(std::shared_ptr peer, protocol::TMLedgerData& p ScopedLockType const sl(mtx_); // Verify nodes are complete - for (auto const& ledger_node : packet.nodes()) + for (auto const& ledgerNode : packet.nodes()) { - if (!validateLedgerNode(ledger_node)) + if (!validateLedgerNode(ledgerNode)) { JLOG(journal_.warn()) << "Got malformed ledger node"; - peer->charge(Resource::feeMalformedRequest, "ledger_node"); + peer->charge(Resource::feeMalformedRequest, "ledgerNode"); return -1; } } diff --git a/src/xrpld/app/ledger/detail/InboundLedgers.cpp b/src/xrpld/app/ledger/detail/InboundLedgers.cpp index 318930746e..c2bdfb2f3f 100644 --- a/src/xrpld/app/ledger/detail/InboundLedgers.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedgers.cpp @@ -248,12 +248,12 @@ public: Serializer s; try { - for (auto const& ledger_node : packet_ptr->nodes()) + for (auto const& ledgerNode : packet_ptr->nodes()) { - if (!validateLedgerNode(ledger_node)) + if (!validateLedgerNode(ledgerNode)) return; - auto const treeNode = getTreeNode(ledger_node.nodedata()); + auto const treeNode = getTreeNode(ledgerNode.nodedata()); if (!treeNode) return; auto const tn = *treeNode; diff --git a/src/xrpld/app/ledger/detail/InboundTransactions.cpp b/src/xrpld/app/ledger/detail/InboundTransactions.cpp index 70e0509181..c0577100f7 100644 --- a/src/xrpld/app/ledger/detail/InboundTransactions.cpp +++ b/src/xrpld/app/ledger/detail/InboundTransactions.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -146,19 +145,19 @@ public: return; } - std::vector>> data; + std::vector> data; data.reserve(packet.nodes().size()); - for (auto const& ledger_node : packet.nodes()) + for (auto const& ledgerNode : packet.nodes()) { - if (!validateLedgerNode(ledger_node)) + if (!validateLedgerNode(ledgerNode)) { JLOG(j_.warn()) << "Got malformed ledger node"; - peer->charge(Resource::feeMalformedRequest, "ledger_node"); + peer->charge(Resource::feeMalformedRequest, "ledgerNode"); return; } - auto treeNode = getTreeNode(ledger_node.nodedata()); + auto treeNode = getTreeNode(ledgerNode.nodedata()); if (!treeNode) { JLOG(j_.warn()) << "Got invalid node data"; @@ -166,7 +165,7 @@ public: return; } - auto const nodeID = getSHAMapNodeID(ledger_node, *treeNode); + auto const nodeID = getSHAMapNodeID(ledgerNode, *treeNode); if (!nodeID) { JLOG(j_.warn()) << "Got invalid node id"; diff --git a/src/xrpld/app/ledger/detail/LedgerNodeHelpers.cpp b/src/xrpld/app/ledger/detail/LedgerNodeHelpers.cpp index 81e27ade3f..ec35d62416 100644 --- a/src/xrpld/app/ledger/detail/LedgerNodeHelpers.cpp +++ b/src/xrpld/app/ledger/detail/LedgerNodeHelpers.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -18,19 +17,19 @@ namespace xrpl { bool -validateLedgerNode(protocol::TMLedgerNode const& ledger_node) +validateLedgerNode(protocol::TMLedgerNode const& ledgerNode) { - if (!ledger_node.has_nodedata()) + if (!ledgerNode.has_nodedata()) return false; - if (ledger_node.has_nodeid()) - return !ledger_node.has_id() && !ledger_node.has_depth(); + if (ledgerNode.has_nodeid()) + return !ledgerNode.has_id() && !ledgerNode.has_depth(); - return ledger_node.has_id() || - (ledger_node.has_depth() && ledger_node.depth() <= SHAMap::leafDepth); + return ledgerNode.has_id() || + (ledgerNode.has_depth() && ledgerNode.depth() <= SHAMap::leafDepth); } -std::optional> +std::optional getTreeNode(std::string_view data) { auto const slice = makeSlice(data); @@ -48,38 +47,36 @@ getTreeNode(std::string_view data) } std::optional -getSHAMapNodeID( - protocol::TMLedgerNode const& ledger_node, - intr_ptr::SharedPtr const& treeNode) +getSHAMapNodeID(protocol::TMLedgerNode const& ledgerNode, SHAMapTreeNodePtr const& treeNode) { - if (ledger_node.has_id() || ledger_node.has_depth()) + if (ledgerNode.has_id() || ledgerNode.has_depth()) { if (treeNode->isInner()) { - if (!ledger_node.has_id()) + if (!ledgerNode.has_id()) return std::nullopt; - return deserializeSHAMapNodeID(ledger_node.id()); + return deserializeSHAMapNodeID(ledgerNode.id()); } if (treeNode->isLeaf()) { - if (!ledger_node.has_depth()) + if (!ledgerNode.has_depth()) return std::nullopt; auto const key = safe_downcast(treeNode.get())->peekItem()->key(); - return SHAMapNodeID::createID(ledger_node.depth(), key); + return SHAMapNodeID::createID(ledgerNode.depth(), key); } UNREACHABLE("xrpl::getSHAMapNodeID : tree node is neither inner nor leaf"); return std::nullopt; } - if (!ledger_node.has_nodeid()) + if (!ledgerNode.has_nodeid()) return std::nullopt; - auto nodeID = deserializeSHAMapNodeID(ledger_node.nodeid()); + auto nodeID = deserializeSHAMapNodeID(ledgerNode.nodeid()); if (!nodeID.has_value()) return std::nullopt; diff --git a/src/xrpld/app/ledger/detail/LedgerNodeHelpers.h b/src/xrpld/app/ledger/detail/LedgerNodeHelpers.h index 4516f3221c..442610bb30 100644 --- a/src/xrpld/app/ledger/detail/LedgerNodeHelpers.h +++ b/src/xrpld/app/ledger/detail/LedgerNodeHelpers.h @@ -24,11 +24,11 @@ namespace xrpl { * be set) then the legacy `nodeid` must not be present. * - If the `depth` field is present then it must be between 0 and SHAMap::leafDepth (inclusive). * - * @param ledger_node The ledger node to validate. + * @param ledgerNode The ledger node to validate. * @return true if the ledger node has the expected fields, false otherwise. */ [[nodiscard]] bool -validateLedgerNode(protocol::TMLedgerNode const& ledger_node); +validateLedgerNode(protocol::TMLedgerNode const& ledgerNode); /** * @brief Deserializes a SHAMapTreeNode from wire format data. @@ -41,7 +41,7 @@ validateLedgerNode(protocol::TMLedgerNode const& ledger_node); * @return An optional containing the deserialized tree node if successful, or std::nullopt if * deserialization fails. */ -[[nodiscard]] std::optional> +[[nodiscard]] std::optional getTreeNode(std::string_view data); /** @@ -60,7 +60,7 @@ getTreeNode(std::string_view data); * key from the leaf node's item. * Note that root nodes may be inner nodes or leaf nodes. * - * @param ledger_node The validated protocol message containing the ledger node data. + * @param ledgerNode The validated protocol message containing the ledger node data. * @param treeNode The deserialized tree node (inner or leaf node). * @return An optional containing the node ID if extraction/reconstruction succeeds, or std::nullopt * if the required fields are missing or validation fails. @@ -68,8 +68,6 @@ getTreeNode(std::string_view data); * `validateLedgerNode` function and obtained a valid tree node by calling `getTreeNode`. */ [[nodiscard]] std::optional -getSHAMapNodeID( - protocol::TMLedgerNode const& ledger_node, - intr_ptr::SharedPtr const& treeNode); +getSHAMapNodeID(protocol::TMLedgerNode const& ledgerNode, SHAMapTreeNodePtr const& treeNode); } // namespace xrpl diff --git a/src/xrpld/app/ledger/detail/LedgerPersistence.cpp b/src/xrpld/app/ledger/detail/LedgerPersistence.cpp index 0edf425f13..55abac9b7d 100644 --- a/src/xrpld/app/ledger/detail/LedgerPersistence.cpp +++ b/src/xrpld/app/ledger/detail/LedgerPersistence.cpp @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include diff --git a/src/xrpld/app/ledger/detail/OpenLedger.cpp b/src/xrpld/app/ledger/detail/OpenLedger.cpp index 5db4e23e1e..d922ea4a89 100644 --- a/src/xrpld/app/ledger/detail/OpenLedger.cpp +++ b/src/xrpld/app/ledger/detail/OpenLedger.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp index 149096e393..da08ab9e22 100644 --- a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp +++ b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -174,7 +173,7 @@ TransactionAcquire::trigger(std::shared_ptr const& peer) SHAMapAddNode TransactionAcquire::takeNodes( - std::vector>> data, + std::vector> data, std::shared_ptr const& peer) { ScopedLockType const sl(mtx_); diff --git a/src/xrpld/app/ledger/detail/TransactionAcquire.h b/src/xrpld/app/ledger/detail/TransactionAcquire.h index 9a594f4de7..2b878ae10f 100644 --- a/src/xrpld/app/ledger/detail/TransactionAcquire.h +++ b/src/xrpld/app/ledger/detail/TransactionAcquire.h @@ -21,7 +21,7 @@ public: SHAMapAddNode takeNodes( - std::vector>> data, + std::vector> data, std::shared_ptr const& peer); void diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index c83b45f247..33d9e2083f 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -78,9 +78,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/misc/FeeVoteImpl.cpp b/src/xrpld/app/misc/FeeVoteImpl.cpp index 53e56286b8..39a551d522 100644 --- a/src/xrpld/app/misc/FeeVoteImpl.cpp +++ b/src/xrpld/app/misc/FeeVoteImpl.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index dcbfada66b..01961feadb 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -3457,7 +3458,7 @@ PeerImp::processLedgerRequest(std::shared_ptr const& m) std::uint32_t const defaultDepth = isHighLatency() ? 2 : 1; auto const queryDepth{m->has_querydepth() ? m->querydepth() : defaultDepth}; - std::vector> data; + std::vector data; auto const useLedgerNodeDepth = supportsFeature(ProtocolFeature::LedgerNodeDepth); for (int i = 0; @@ -3485,24 +3486,22 @@ PeerImp::processLedgerRequest(std::shared_ptr const& m) protocol::TMLedgerNode* node{ledgerData.add_nodes()}; - auto const& nodeData = std::get<1>(d); - node->set_nodedata(nodeData.data(), nodeData.size()); + node->set_nodedata(d.data.data(), d.data.size()); // When the LedgerNodeDepth protocol feature is not supported by the peer, // we always set the `nodeid` field. However, when it is supported then we // set the `id` field for inner nodes and the `depth` field for leaf nodes. - auto const& nodeID = std::get<0>(d); if (!useLedgerNodeDepth) { - node->set_nodeid(nodeID.getRawString()); + node->set_nodeid(d.nodeID.getRawString()); } - else if (std::get<2>(d)) + else if (d.isLeaf) { - node->set_depth(nodeID.getDepth()); + node->set_depth(d.nodeID.getDepth()); } else { - node->set_id(nodeID.getRawString()); + node->set_id(d.nodeID.getRawString()); } } } diff --git a/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp b/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp index c093c5fcf5..0b9278d580 100644 --- a/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp +++ b/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include