diff --git a/src/ripple/app/ledger/AccountStateSF.cpp b/src/ripple/app/ledger/AccountStateSF.cpp index 8dcba9a86..5dbf46857 100644 --- a/src/ripple/app/ledger/AccountStateSF.cpp +++ b/src/ripple/app/ledger/AccountStateSF.cpp @@ -35,7 +35,7 @@ AccountStateSF::AccountStateSF(Application& app) void AccountStateSF::gotNode (bool fromFilter, SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType) { @@ -43,14 +43,14 @@ void AccountStateSF::gotNode (bool fromFilter, // SHAMap should provide an accessor to get the injected Database, // and this should use that Database instad of getNodeStore app_.getNodeStore ().store ( - hotACCOUNT_NODE, std::move (nodeData), nodeHash); + hotACCOUNT_NODE, std::move (nodeData), nodeHash.as_uint256()); } bool AccountStateSF::haveNode (SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData) { - return app_.getLedgerMaster ().getFetchPack (nodeHash, nodeData); + return app_.getLedgerMaster ().getFetchPack (nodeHash.as_uint256(), nodeData); } } // ripple diff --git a/src/ripple/app/ledger/AccountStateSF.h b/src/ripple/app/ledger/AccountStateSF.h index d93c02e00..48fd7b2a5 100644 --- a/src/ripple/app/ledger/AccountStateSF.h +++ b/src/ripple/app/ledger/AccountStateSF.h @@ -40,12 +40,12 @@ public: // Note that the nodeData is overwritten by this call void gotNode (bool fromFilter, SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType) override; bool haveNode (SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData) override; }; diff --git a/src/ripple/app/ledger/ConsensusTransSetSF.cpp b/src/ripple/app/ledger/ConsensusTransSetSF.cpp index 6f862934a..82222db13 100644 --- a/src/ripple/app/ledger/ConsensusTransSetSF.cpp +++ b/src/ripple/app/ledger/ConsensusTransSetSF.cpp @@ -39,7 +39,7 @@ ConsensusTransSetSF::ConsensusTransSetSF (Application& app, NodeCache& nodeCache } void ConsensusTransSetSF::gotNode ( - bool fromFilter, const SHAMapNodeID& id, uint256 const& nodeHash, + bool fromFilter, const SHAMapNodeID& id, SHAMapHash const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType type) { if (fromFilter) @@ -59,7 +59,7 @@ void ConsensusTransSetSF::gotNode ( Serializer s (nodeData.data() + 4, nodeData.size() - 4); SerialIter sit (s.slice()); auto stx = std::make_shared (std::ref (sit)); - assert (stx->getTransactionID () == nodeHash); + assert (stx->getTransactionID () == nodeHash.as_uint256()); auto const pap = &app_; app_.getJobQueue ().addJob ( jtTRANSACTION, "TXS->TXN", @@ -76,12 +76,12 @@ void ConsensusTransSetSF::gotNode ( } bool ConsensusTransSetSF::haveNode ( - const SHAMapNodeID& id, uint256 const& nodeHash, Blob& nodeData) + const SHAMapNodeID& id, SHAMapHash const& nodeHash, Blob& nodeData) { if (m_nodeCache.retrieve (nodeHash, nodeData)) return true; - auto txn = app_.getMasterTransaction().fetch(nodeHash, false); + auto txn = app_.getMasterTransaction().fetch(nodeHash.as_uint256(), false); if (txn) { @@ -91,7 +91,7 @@ bool ConsensusTransSetSF::haveNode ( Serializer s; s.add32 (HashPrefix::transactionID); txn->getSTransaction ()->add (s); - assert(sha512Half(s.slice()) == nodeHash); + assert(sha512Half(s.slice()) == nodeHash.as_uint256()); nodeData = s.peekData (); return true; } diff --git a/src/ripple/app/ledger/ConsensusTransSetSF.h b/src/ripple/app/ledger/ConsensusTransSetSF.h index fb9a209aa..6390f6ae9 100644 --- a/src/ripple/app/ledger/ConsensusTransSetSF.h +++ b/src/ripple/app/ledger/ConsensusTransSetSF.h @@ -34,19 +34,19 @@ namespace ripple { class ConsensusTransSetSF : public SHAMapSyncFilter { public: - using NodeCache = TaggedCache ; + using NodeCache = TaggedCache ; ConsensusTransSetSF (Application& app, NodeCache& nodeCache); // Note that the nodeData is overwritten by this call void gotNode (bool fromFilter, SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType) override; bool haveNode (SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData) override; private: diff --git a/src/ripple/app/ledger/TransactionStateSF.cpp b/src/ripple/app/ledger/TransactionStateSF.cpp index 3d93fb111..1baeba0f8 100644 --- a/src/ripple/app/ledger/TransactionStateSF.cpp +++ b/src/ripple/app/ledger/TransactionStateSF.cpp @@ -36,7 +36,7 @@ TransactionStateSF::TransactionStateSF(Application& app) // VFALCO This might be better as Blob&& void TransactionStateSF::gotNode (bool fromFilter, SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType type) { @@ -47,14 +47,14 @@ void TransactionStateSF::gotNode (bool fromFilter, SHAMapTreeNode::tnTRANSACTION_NM); app_.getNodeStore().store( hotTRANSACTION_NODE, - std::move (nodeData), nodeHash); + std::move (nodeData), nodeHash.as_uint256()); } bool TransactionStateSF::haveNode (SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData) { - return app_.getLedgerMaster ().getFetchPack (nodeHash, nodeData); + return app_.getLedgerMaster ().getFetchPack (nodeHash.as_uint256(), nodeData); } } // ripple diff --git a/src/ripple/app/ledger/TransactionStateSF.h b/src/ripple/app/ledger/TransactionStateSF.h index 6e1b0ea6d..f5336d977 100644 --- a/src/ripple/app/ledger/TransactionStateSF.h +++ b/src/ripple/app/ledger/TransactionStateSF.h @@ -41,13 +41,13 @@ public: // Note that the nodeData is overwritten by this call void gotNode (bool fromFilter, SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData, - SHAMapTreeNode::TNType); + SHAMapTreeNode::TNType) override; bool haveNode (SHAMapNodeID const& id, - uint256 const& nodeHash, - Blob& nodeData); + SHAMapHash const& nodeHash, + Blob& nodeData) override; }; } // ripple diff --git a/src/ripple/app/main/Application.h b/src/ripple/app/main/Application.h index 77a53c067..04c13087d 100644 --- a/src/ripple/app/main/Application.h +++ b/src/ripple/app/main/Application.h @@ -69,7 +69,7 @@ class Cluster; class DatabaseCon; class SHAMapStore; -using NodeCache = TaggedCache ; +using NodeCache = TaggedCache ; class Application : public beast::PropertyStream::Source { diff --git a/src/ripple/app/misc/SHAMapStoreImp.h b/src/ripple/app/misc/SHAMapStoreImp.h index 602e2a8a0..ed6f34d7e 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.h +++ b/src/ripple/app/misc/SHAMapStoreImp.h @@ -190,7 +190,7 @@ private: { std::uint64_t check = 0; - for (uint256 const& key: cache.getKeys()) + for (auto const& key: cache.getKeys()) { database_->fetchNode (key); if (! (++check % checkHealthInterval_) && health()) diff --git a/src/ripple/shamap/SHAMapSyncFilter.h b/src/ripple/shamap/SHAMapSyncFilter.h index e85cfc0be..a7d2a948a 100644 --- a/src/ripple/shamap/SHAMapSyncFilter.h +++ b/src/ripple/shamap/SHAMapSyncFilter.h @@ -37,12 +37,12 @@ public: // Note that the nodeData is overwritten by this call virtual void gotNode (bool fromFilter, SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType type) = 0; virtual bool haveNode (SHAMapNodeID const& id, - uint256 const& nodeHash, + SHAMapHash const& nodeHash, Blob& nodeData) = 0; }; diff --git a/src/ripple/shamap/SHAMapTreeNode.h b/src/ripple/shamap/SHAMapTreeNode.h index 3538c753e..925973664 100644 --- a/src/ripple/shamap/SHAMapTreeNode.h +++ b/src/ripple/shamap/SHAMapTreeNode.h @@ -73,6 +73,14 @@ public: } friend std::string to_string(SHAMapHash const& x) {return to_string(x.hash_);} + + template + friend + void + hash_append(H& h, SHAMapHash const& x) + { + hash_append(h, x.hash_); + } }; inline diff --git a/src/ripple/shamap/TreeNodeCache.h b/src/ripple/shamap/TreeNodeCache.h index c41ee5fc0..4b6f225a3 100644 --- a/src/ripple/shamap/TreeNodeCache.h +++ b/src/ripple/shamap/TreeNodeCache.h @@ -20,7 +20,8 @@ #ifndef RIPPLE_SHAMAP_TREENODECACHE_H_INCLUDED #define RIPPLE_SHAMAP_TREENODECACHE_H_INCLUDED -#include +#include +#include namespace ripple { diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index 50edea206..e8cd2e650 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -205,13 +205,13 @@ SHAMap::checkFilter(SHAMapHash const& hash, SHAMapNodeID const& id, { std::shared_ptr node; Blob nodeData; - if (filter->haveNode (id, hash.as_uint256(), nodeData)) + if (filter->haveNode (id, hash, nodeData)) { node = SHAMapAbstractNode::make( nodeData, 0, snfPREFIX, hash, true, f_.journal ()); if (node) { - filter->gotNode (true, id, hash.as_uint256(), nodeData, node->getType ()); + filter->gotNode (true, id, hash, nodeData, node->getType ()); if (backed_) canonicalize (hash, node); } diff --git a/src/ripple/shamap/impl/SHAMapSync.cpp b/src/ripple/shamap/impl/SHAMapSync.cpp index eeb1b22e0..738be14d3 100644 --- a/src/ripple/shamap/impl/SHAMapSync.cpp +++ b/src/ripple/shamap/impl/SHAMapSync.cpp @@ -439,7 +439,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, { Serializer s; root_->addRaw (s, snfPREFIX); - filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash ().as_uint256(), + filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash (), s.modData (), root_->getType ()); } @@ -476,7 +476,7 @@ SHAMapAddNode SHAMap::addRootNode (SHAMapHash const& hash, Blob const& rootNode, { Serializer s; root_->addRaw (s, snfPREFIX); - filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash ().as_uint256(), + filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash (), s.modData (), root_->getType ()); } @@ -563,7 +563,7 @@ SHAMap::addKnownNode (const SHAMapNodeID& node, Blob const& rawNode, { Serializer s; newNode->addRaw (s, snfPREFIX); - filter->gotNode (false, node, childHash.as_uint256(), + filter->gotNode (false, node, childHash, s.modData (), newNode->getType ()); } diff --git a/src/ripple/shamap/tests/FetchPack.test.cpp b/src/ripple/shamap/tests/FetchPack.test.cpp index 8f6d9dfd0..5c4ee597a 100644 --- a/src/ripple/shamap/tests/FetchPack.test.cpp +++ b/src/ripple/shamap/tests/FetchPack.test.cpp @@ -42,7 +42,7 @@ public: tableItemsExtra = 20 }; - using Map = hash_map ; + using Map = hash_map ; using Table = SHAMap; using Item = SHAMapItem; @@ -61,13 +61,13 @@ public: } void gotNode (bool fromFilter, - SHAMapNodeID const& id, uint256 const& nodeHash, - Blob& nodeData, SHAMapTreeNode::TNType type) + SHAMapNodeID const& id, SHAMapHash const& nodeHash, + Blob& nodeData, SHAMapTreeNode::TNType type) override { } bool haveNode (SHAMapNodeID const& id, - uint256 const& nodeHash, Blob& nodeData) + SHAMapHash const& nodeHash, Blob& nodeData) override { Map::iterator it = mMap.find (nodeHash); if (it == mMap.end ()) @@ -106,9 +106,9 @@ public: } } - void on_fetch (Map& map, uint256 const& hash, Blob const& blob) + void on_fetch (Map& map, SHAMapHash const& hash, Blob const& blob) { - expect (sha512Half(makeSlice(blob)) == hash, + expect (sha512Half(makeSlice(blob)) == hash.as_uint256(), "Hash mismatch"); map.emplace (hash, blob); }