diff --git a/src/ripple/module/app/consensus/LedgerConsensus.cpp b/src/ripple/module/app/consensus/LedgerConsensus.cpp index cbf315c070..053f64fc22 100644 --- a/src/ripple/module/app/consensus/LedgerConsensus.cpp +++ b/src/ripple/module/app/consensus/LedgerConsensus.cpp @@ -794,7 +794,7 @@ public: /** A peer has sent us some nodes from a transaction set */ SHAMapAddNode peerGaveNodes (Peer::ptr const& peer - , uint256 const& setHash, const std::list& nodeIDs + , uint256 const& setHash, const std::list& nodeIDs , const std::list< Blob >& nodeData) { auto acq (mAcquiring.find (setHash)); diff --git a/src/ripple/module/app/consensus/LedgerConsensus.h b/src/ripple/module/app/consensus/LedgerConsensus.h index 213cd643d3..73cdefadca 100644 --- a/src/ripple/module/app/consensus/LedgerConsensus.h +++ b/src/ripple/module/app/consensus/LedgerConsensus.h @@ -71,7 +71,7 @@ public: virtual SHAMapAddNode peerGaveNodes (Peer::ptr const& peer, uint256 const & setHash, - const std::list& nodeIDs, + const std::list& nodeIDs, const std::list< Blob >& nodeData) = 0; virtual bool isOurPubKey (const RippleAddress & k) = 0; diff --git a/src/ripple/module/app/ledger/InboundLedger.cpp b/src/ripple/module/app/ledger/InboundLedger.cpp index 0d4f4f2487..57b3c14277 100644 --- a/src/ripple/module/app/ledger/InboundLedger.cpp +++ b/src/ripple/module/app/ledger/InboundLedger.cpp @@ -546,7 +546,7 @@ void InboundLedger::trigger (Peer::ptr const& peer) { // we need the root node tmGL.set_itype (protocol::liAS_NODE); - * (tmGL.add_nodeids ()) = SHAMapNode ().getRawString (); + *tmGL.add_nodeids () = SHAMapNodeID ().getRawString (); if (m_journal.trace) m_journal.trace << "Sending AS root request to " << (peer ? "selected peer" : "all peers"); sendRequest (tmGL, peer); @@ -554,7 +554,7 @@ void InboundLedger::trigger (Peer::ptr const& peer) } else { - std::vector nodeIDs; + std::vector nodeIDs; std::vector nodeHashes; // VFALCO Why 256? Make this a constant nodeIDs.reserve (256); @@ -592,7 +592,7 @@ void InboundLedger::trigger (Peer::ptr const& peer) if (!nodeIDs.empty ()) { tmGL.set_itype (protocol::liAS_NODE); - BOOST_FOREACH (SHAMapNode const& it, nodeIDs) + BOOST_FOREACH (SHAMapNodeID const& it, nodeIDs) { * (tmGL.add_nodeids ()) = it.getRawString (); } @@ -625,7 +625,7 @@ void InboundLedger::trigger (Peer::ptr const& peer) { // we need the root node tmGL.set_itype (protocol::liTX_NODE); - * (tmGL.add_nodeids ()) = SHAMapNode ().getRawString (); + * (tmGL.add_nodeids ()) = SHAMapNodeID ().getRawString (); if (m_journal.trace) m_journal.trace << "Sending TX root request to " << ( peer ? "selected peer" : "all peers"); @@ -634,7 +634,7 @@ void InboundLedger::trigger (Peer::ptr const& peer) } else { - std::vector nodeIDs; + std::vector nodeIDs; std::vector nodeHashes; nodeIDs.reserve (256); nodeHashes.reserve (256); @@ -663,7 +663,7 @@ void InboundLedger::trigger (Peer::ptr const& peer) if (!nodeIDs.empty ()) { tmGL.set_itype (protocol::liTX_NODE); - BOOST_FOREACH (SHAMapNode const& it, nodeIDs) + BOOST_FOREACH (SHAMapNodeID const& it, nodeIDs) { * (tmGL.add_nodeids ()) = it.getRawString (); } @@ -692,8 +692,8 @@ void InboundLedger::trigger (Peer::ptr const& peer) } } -void InboundLedger::filterNodes (std::vector& nodeIDs, - std::vector& nodeHashes, std::set& recentNodes, +void InboundLedger::filterNodes (std::vector& nodeIDs, + std::vector& nodeHashes, std::set& recentNodes, int max, bool aggressive) { // ask for new nodes in preference to ones we've already asked for @@ -704,7 +704,7 @@ void InboundLedger::filterNodes (std::vector& nodeIDs, int dupCount = 0; - BOOST_FOREACH(SHAMapNode const& nodeID, nodeIDs) + BOOST_FOREACH(SHAMapNodeID const& nodeID, nodeIDs) { if (recentNodes.count (nodeID) != 0) { @@ -757,7 +757,7 @@ void InboundLedger::filterNodes (std::vector& nodeIDs, nodeHashes.resize (max); } - BOOST_FOREACH (const SHAMapNode & n, nodeIDs) + BOOST_FOREACH (const SHAMapNodeID & n, nodeIDs) { recentNodes.insert (n); } @@ -814,7 +814,7 @@ bool InboundLedger::takeBase (const std::string& data) /** Process TX data received from a peer Call with a lock */ -bool InboundLedger::takeTxNode (const std::list& nodeIDs, +bool InboundLedger::takeTxNode (const std::list& nodeIDs, const std::list< Blob >& data, SHAMapAddNode& san) { if (!mHaveBase) @@ -831,7 +831,7 @@ bool InboundLedger::takeTxNode (const std::list& nodeIDs, return true; } - std::list::const_iterator nodeIDit = nodeIDs.begin (); + std::list::const_iterator nodeIDit = nodeIDs.begin (); std::list< Blob >::const_iterator nodeDatait = data.begin (); TransactionStateSF tFilter (mLedger->getLedgerSeq ()); @@ -874,7 +874,7 @@ bool InboundLedger::takeTxNode (const std::list& nodeIDs, /** Process AS data received from a peer Call with a lock */ -bool InboundLedger::takeAsNode (const std::list& nodeIDs, +bool InboundLedger::takeAsNode (const std::list& nodeIDs, const std::list< Blob >& data, SHAMapAddNode& san) { if (m_journal.trace) m_journal.trace << @@ -898,7 +898,7 @@ bool InboundLedger::takeAsNode (const std::list& nodeIDs, return true; } - std::list::const_iterator nodeIDit = nodeIDs.begin (); + std::list::const_iterator nodeIDit = nodeIDs.begin (); std::list< Blob >::const_iterator nodeDatait = data.begin (); AccountStateSF tFilter (mLedger->getLedgerSeq ()); @@ -1117,7 +1117,7 @@ int InboundLedger::processData (std::shared_ptr peer, if ((packet.type () == protocol::liTX_NODE) || ( packet.type () == protocol::liAS_NODE)) { - std::list nodeIDs; + std::list nodeIDs; std::list< Blob > nodeData; if (packet.nodes ().size () == 0) @@ -1140,7 +1140,7 @@ int InboundLedger::processData (std::shared_ptr peer, return -1; } - nodeIDs.push_back (SHAMapNode (node.nodeid ().data (), + nodeIDs.push_back (SHAMapNodeID (node.nodeid ().data (), node.nodeid ().size ())); nodeData.push_back (Blob (node.nodedata ().begin (), node.nodedata ().end ())); diff --git a/src/ripple/module/app/ledger/InboundLedger.h b/src/ripple/module/app/ledger/InboundLedger.h index 8f10325b4e..2c5863a66d 100644 --- a/src/ripple/module/app/ledger/InboundLedger.h +++ b/src/ripple/module/app/ledger/InboundLedger.h @@ -95,8 +95,8 @@ public: std::vector getNeededHashes (); // VFALCO TODO Replace uint256 with something semanticallyh meaningful - void filterNodes (std::vector& nodeIDs, std::vector& nodeHashes, - std::set& recentNodes, int max, bool aggressive); + void filterNodes (std::vector& nodeIDs, std::vector& nodeHashes, + std::set& recentNodes, int max, bool aggressive); Json::Value getJson (int); void runData (); @@ -116,7 +116,7 @@ private: int processData (std::shared_ptr peer, protocol::TMLedgerData& data); bool takeBase (const std::string& data); - bool takeTxNode (const std::list& IDs, const std::list& data, + bool takeTxNode (const std::list& IDs, const std::list& data, SHAMapAddNode&); bool takeTxRootNode (Blob const& data, SHAMapAddNode&); @@ -124,7 +124,7 @@ private: // Don't use acronyms, but if we are going to use them at least // capitalize them correctly. // - bool takeAsNode (const std::list& IDs, const std::list& data, + bool takeAsNode (const std::list& IDs, const std::list& data, SHAMapAddNode&); bool takeAsRootNode (Blob const& data, SHAMapAddNode&); @@ -139,8 +139,8 @@ private: std::uint32_t mSeq; fcReason mReason; - std::set mRecentTXNodes; - std::set mRecentASNodes; + std::set mRecentTXNodes; + std::set mRecentASNodes; // Data we have received from peers diff --git a/src/ripple/module/app/ledger/InboundLedgers.cpp b/src/ripple/module/app/ledger/InboundLedgers.cpp index 09aaa78e84..43d3cc4f50 100644 --- a/src/ripple/module/app/ledger/InboundLedgers.cpp +++ b/src/ripple/module/app/ledger/InboundLedgers.cpp @@ -250,7 +250,7 @@ public: return; SHAMapTreeNode newNode( - SHAMapNode (node.nodeid().data(), node.nodeid().size()), + SHAMapNodeID (node.nodeid().data(), node.nodeid().size()), Blob (node.nodedata().begin(), node.nodedata().end()), 0, snfWIRE, uZero, false); diff --git a/src/ripple/module/app/misc/NetworkOPs.cpp b/src/ripple/module/app/misc/NetworkOPs.cpp index 3261be6267..00e0772dc7 100644 --- a/src/ripple/module/app/misc/NetworkOPs.cpp +++ b/src/ripple/module/app/misc/NetworkOPs.cpp @@ -230,7 +230,7 @@ public: void processTrustedProposal (LedgerProposal::pointer proposal, std::shared_ptr set, RippleAddress nodePublic, uint256 checkLedger, bool sigGood); SHAMapAddNode gotTXData (const std::shared_ptr& peer, uint256 const& hash, - const std::list& nodeIDs, const std::list< Blob >& nodeData); + const std::list& nodeIDs, const std::list< Blob >& nodeData); bool recvValidation (SerializedValidation::ref val, const std::string& source); void takePosition (int seq, SHAMap::ref position); SHAMap::pointer getTXMap (uint256 const& hash); @@ -1608,7 +1608,7 @@ void NetworkOPsImp::takePosition (int seq, SHAMap::ref position) // Call with the master lock for now SHAMapAddNode NetworkOPsImp::gotTXData (const std::shared_ptr& peer, uint256 const& hash, - const std::list& nodeIDs, const std::list< Blob >& nodeData) + const std::list& nodeIDs, const std::list< Blob >& nodeData) { if (!mConsensus) diff --git a/src/ripple/module/app/misc/NetworkOPs.h b/src/ripple/module/app/misc/NetworkOPs.h index a84fb8422a..080f049efe 100644 --- a/src/ripple/module/app/misc/NetworkOPs.h +++ b/src/ripple/module/app/misc/NetworkOPs.h @@ -208,7 +208,7 @@ public: uint256 checkLedger, bool sigGood) = 0; virtual SHAMapAddNode gotTXData (const std::shared_ptr& peer, - uint256 const& hash, const std::list& nodeIDs, + uint256 const& hash, const std::list& nodeIDs, const std::list< Blob >& nodeData) = 0; virtual bool recvValidation (SerializedValidation::ref val, diff --git a/src/ripple/module/app/shamap/FetchPackTests.cpp b/src/ripple/module/app/shamap/FetchPackTests.cpp index 135f576a60..a2552be405 100644 --- a/src/ripple/module/app/shamap/FetchPackTests.cpp +++ b/src/ripple/module/app/shamap/FetchPackTests.cpp @@ -41,12 +41,12 @@ public: } void gotNode (bool fromFilter, - SHAMapNode const& id, uint256 const& nodeHash, + SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType type) { } - bool haveNode (SHAMapNode const& id, + bool haveNode (SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData) { Map::iterator it = mMap.find (nodeHash); diff --git a/src/ripple/module/app/shamap/SHAMap.cpp b/src/ripple/module/app/shamap/SHAMap.cpp index 577ca5e05e..99d448b114 100644 --- a/src/ripple/module/app/shamap/SHAMap.cpp +++ b/src/ripple/module/app/shamap/SHAMap.cpp @@ -43,9 +43,9 @@ SHAMap::SHAMap (SHAMapType t, FullBelowCache& fullBelowCache, std::uint32_t seq, if (t == smtSTATE) mTNByID.rehash (STATE_MAP_BUCKETS); - root = std::make_shared (mSeq, SHAMapNode (0, uint256 ())); + root = std::make_shared (mSeq, SHAMapNodeID (0, uint256 ())); root->makeInner (); - mTNByID.replace(*root, root); + mTNByID.replace(root->getID(), root); } SHAMap::SHAMap (SHAMapType t, uint256 const& hash, FullBelowCache& fullBelowCache, @@ -61,9 +61,9 @@ SHAMap::SHAMap (SHAMapType t, uint256 const& hash, FullBelowCache& fullBelowCach if (t == smtSTATE) mTNByID.rehash (STATE_MAP_BUCKETS); - root = std::make_shared (mSeq, SHAMapNode (0, uint256 ())); + root = std::make_shared (mSeq, SHAMapNodeID (0, uint256 ())); root->makeInner (); - mTNByID.replace(*root, root); + mTNByID.replace(root->getID(), root); } TaggedCache @@ -93,7 +93,7 @@ SHAMap::~SHAMap () } } -void SHAMapNode::setMHash () const +void SHAMapNodeID::setMHash () const { using namespace std; @@ -108,7 +108,7 @@ void SHAMapNode::setMHash () const mHash = h; } -std::size_t hash_value (const SHAMapNode& mn) +std::size_t hash_value (const SHAMapNodeID& mn) { return mn.getMHash (); } @@ -138,8 +138,8 @@ SHAMap::pointer SHAMap::snapShot (bool isMutable) if (nodeIt.second->getSeq() == mSeq) { // We might modify this node, so duplicate it in the snapShot SHAMapTreeNode::pointer newNode = std::make_shared (*nodeIt.second, mSeq); - newMap.mTNByID.replace (*newNode, newNode); - if (newNode->isRoot ()) + newMap.mTNByID.replace (newNode->getID(), newNode); + if (newNode->getID().isRoot ()) newMap.root = newNode; } } @@ -162,7 +162,7 @@ std::stack SHAMap::getStack (uint256 const& id, bool in { stack.push (node); - int branch = node->selectBranch (id); + int branch = node->getID().selectBranch (id); assert (branch >= 0); if (node->isEmptyBranch (branch)) @@ -170,7 +170,8 @@ std::stack SHAMap::getStack (uint256 const& id, bool in try { - node = getNode (node->getChildNodeID (branch), node->getChildHash (branch), false); + node = getNode (node->getID().getChildNodeID (branch), + node->getChildHash (branch), false); } catch (SHAMapMissingNode& mn) { @@ -198,7 +199,7 @@ void SHAMap::dirtyUp (std::stack& stack, uint256 const& stack.pop (); assert (node->isInnerNode ()); - int branch = node->selectBranch (target); + int branch = node->getID().selectBranch (target); assert (branch >= 0); returnNode (node, true); @@ -218,7 +219,7 @@ void SHAMap::dirtyUp (std::stack& stack, uint256 const& } } -SHAMapTreeNode::pointer SHAMap::checkCacheNode (const SHAMapNode& iNode) +SHAMapTreeNode::pointer SHAMap::checkCacheNode (const SHAMapNodeID& iNode) { SHAMapTreeNode::pointer ret = mTNByID.retrieve(iNode); if (ret && (ret->getSeq()!= 0)) @@ -234,14 +235,15 @@ SHAMapTreeNode::pointer SHAMap::walkTo (uint256 const& id, bool modify) while (!inNode->isLeaf ()) { - int branch = inNode->selectBranch (id); + int branch = inNode->getID().selectBranch (id); if (inNode->isEmptyBranch (branch)) return inNode; try { - inNode = getNode (inNode->getChildNodeID (branch), inNode->getChildHash (branch), false); + inNode = getNode (inNode->getID().getChildNodeID (branch), + inNode->getChildHash (branch), false); } catch (SHAMapMissingNode& mn) { @@ -265,19 +267,20 @@ SHAMapTreeNode* SHAMap::walkToPointer (uint256 const& id) while (!inNode->isLeaf ()) { - int branch = inNode->selectBranch (id); + int branch = inNode->getID().selectBranch (id); if (inNode->isEmptyBranch (branch)) return nullptr; - inNode = getNodePointer (inNode->getChildNodeID (branch), inNode->getChildHash (branch)); + inNode = getNodePointer (inNode->getID().getChildNodeID (branch), + inNode->getChildHash (branch)); assert (inNode); } return (inNode->getTag () == id) ? inNode : nullptr; } -SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& id, uint256 const& hash, bool modify) +SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNodeID& id, uint256 const& hash, bool modify) { // retrieve a node whose node hash is known SHAMapTreeNode::pointer node = checkCacheNode (id); @@ -303,7 +306,7 @@ SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& id, uint256 const& ha return fetchNodeExternal (id, hash); } -SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& id, uint256 const& hash) +SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNodeID& id, uint256 const& hash) { // fast, but you do not hold a reference SHAMapTreeNode* ret = getNodePointerNT (id, hash); @@ -314,7 +317,7 @@ SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& id, uint256 const& has return ret; } -SHAMapTreeNode* SHAMap::getNodePointerNT (const SHAMapNode& id, uint256 const& hash) +SHAMapTreeNode* SHAMap::getNodePointerNT (const SHAMapNodeID& id, uint256 const& hash) { SHAMapTreeNode::pointer ret = mTNByID.retrieve (id); if (!ret) @@ -322,7 +325,7 @@ SHAMapTreeNode* SHAMap::getNodePointerNT (const SHAMapNode& id, uint256 const& h return ret ? ret.get() : nullptr; } -SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& id, uint256 const& hash, SHAMapSyncFilter* filter) +SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNodeID& id, uint256 const& hash, SHAMapSyncFilter* filter) { SHAMapTreeNode* ret = getNodePointerNT (id, hash, filter); @@ -332,7 +335,7 @@ SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& id, uint256 const& has return ret; } -SHAMapTreeNode* SHAMap::getNodePointerNT (const SHAMapNode& id, uint256 const& hash, SHAMapSyncFilter* filter) +SHAMapTreeNode* SHAMap::getNodePointerNT (const SHAMapNodeID& id, uint256 const& hash, SHAMapSyncFilter* filter) { SHAMapTreeNode* node = getNodePointerNT (id, hash); @@ -374,13 +377,13 @@ void SHAMap::returnNode (SHAMapTreeNode::pointer& node, bool modify) node = std::make_shared (*node, mSeq); // here's to the new node, same as the old node assert (node->isValid ()); - mTNByID.replace (*node, node); + mTNByID.replace (node->getID(), node); - if (node->isRoot ()) + if (node->getID().isRoot ()) root = node; if (mDirtyNodes) - mDirtyNodes->insert (*node); + mDirtyNodes->insert (node->getID()); } } @@ -388,7 +391,7 @@ void SHAMap::trackNewNode (SHAMapTreeNode::pointer& node) { assert (node->getSeq() == mSeq); if (mDirtyNodes) - mDirtyNodes->insert (*node); + mDirtyNodes->insert (node->getID()); } SHAMapTreeNode* SHAMap::firstBelow (SHAMapTreeNode* node) @@ -405,7 +408,8 @@ SHAMapTreeNode* SHAMap::firstBelow (SHAMapTreeNode* node) for (int i = 0; i < 16; ++i) if (!node->isEmptyBranch (i)) { - node = getNodePointer (node->getChildNodeID (i), node->getChildHash (i)); + node = getNodePointer (node->getID().getChildNodeID (i), + node->getChildHash (i)); foundNode = true; break; } @@ -429,7 +433,8 @@ SHAMapTreeNode* SHAMap::lastBelow (SHAMapTreeNode* node) for (int i = 15; i >= 0; ++i) if (!node->isEmptyBranch (i)) { - node = getNodePointer (node->getChildNodeID (i), node->getChildHash (i)); + node = getNodePointer (node->getID().getChildNodeID (i), + node->getChildHash (i)); foundNode = true; break; } @@ -453,12 +458,13 @@ SHAMapItem::pointer SHAMap::onlyBelow (SHAMapTreeNode* node) if (nextNode) return SHAMapItem::pointer (); // two leaves below - nextNode = getNodePointer (node->getChildNodeID (i), node->getChildHash (i)); + nextNode = getNodePointer (node->getID().getChildNodeID (i), + node->getChildHash (i)); } if (!nextNode) { - WriteLog (lsFATAL, SHAMap) << *node; + WriteLog (lsFATAL, SHAMap) << node->getID(); assert (false); return SHAMapItem::pointer (); } @@ -480,13 +486,14 @@ void SHAMap::eraseChildren (SHAMapTreeNode::pointer node) for (int i = 0; i < 16; ++i) if (!node->isEmptyBranch (i)) { - SHAMapTreeNode::pointer nextNode = getNode (node->getChildNodeID (i), node->getChildHash (i), false); + SHAMapTreeNode::pointer nextNode = getNode (node->getID().getChildNodeID (i), + node->getChildHash (i), false); if (erase) { returnNode (node, true); - if (mTNByID.erase (*node)) + if (mTNByID.erase (node->getID())) assert (false); } @@ -498,7 +505,7 @@ void SHAMap::eraseChildren (SHAMapTreeNode::pointer node) returnNode (node, true); - if (mTNByID.erase (*node) == 0) + if (mTNByID.erase (node->getID()) == 0) assert (false); return; @@ -571,10 +578,11 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT } } else - for (int i = node->selectBranch (id) + 1; i < 16; ++i) + for (int i = node->getID().selectBranch (id) + 1; i < 16; ++i) if (!node->isEmptyBranch (i)) { - SHAMapTreeNode* firstNode = getNodePointer (node->getChildNodeID (i), node->getChildHash (i)); + SHAMapTreeNode* firstNode = getNodePointer (node->getID().getChildNodeID (i), + node->getChildHash (i)); assert (firstNode); firstNode = firstBelow (firstNode); @@ -609,11 +617,12 @@ SHAMapItem::pointer SHAMap::peekPrevItem (uint256 const& id) } else { - for (int i = node->selectBranch (id) - 1; i >= 0; --i) + for (int i = node->getID().selectBranch (id) - 1; i >= 0; --i) { if (!node->isEmptyBranch (i)) { - node = getNode (node->getChildNodeID (i), node->getChildHash (i), false); + node = getNode (node->getID().getChildNodeID (i), + node->getChildHash (i), false); SHAMapTreeNode* item = firstBelow (node.get ()); if (!item) @@ -697,7 +706,7 @@ bool SHAMap::delItem (uint256 const& id) SHAMapTreeNode::TNType type = leaf->getType (); returnNode (leaf, true); - if (mTNByID.erase (*leaf) == 0) + if (mTNByID.erase (leaf->getID()) == 0) assert (false); uint256 prevHash; @@ -709,13 +718,13 @@ bool SHAMap::delItem (uint256 const& id) returnNode (node, true); assert (node->isInner ()); - if (!node->setChildHash (node->selectBranch (id), prevHash)) + if (!node->setChildHash (node->getID().selectBranch (id), prevHash)) { assert (false); return true; } - if (!node->isRoot ()) + if (!node->getID().isRoot ()) { // we may have made this a node with 1 or 0 children int bc = node->getBranchCount (); @@ -724,7 +733,7 @@ bool SHAMap::delItem (uint256 const& id) { prevHash = uint256 (); - if (!mTNByID.erase (*node)) + if (!mTNByID.erase (node->getID())) assert (false); } else if (bc == 1) @@ -781,15 +790,16 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta if (node->isInner ()) { // easy case, we end on an inner node - int branch = node->selectBranch (tag); + int branch = node->getID().selectBranch (tag); assert (node->isEmptyBranch (branch)); SHAMapTreeNode::pointer newNode = - std::make_shared (node->getChildNodeID (branch), item, type, mSeq); + std::make_shared (node->getID().getChildNodeID (branch), + item, type, mSeq); - if (!mTNByID.peekMap().emplace (SHAMapNode (*newNode), newNode).second) + if (!mTNByID.peekMap().emplace (SHAMapNodeID (newNode->getID()), newNode).second) { - WriteLog (lsFATAL, SHAMap) << "Node: " << *node; - WriteLog (lsFATAL, SHAMap) << "NewNode: " << *newNode; + WriteLog (lsFATAL, SHAMap) << "Node: " << node->getID(); + WriteLog (lsFATAL, SHAMap) << "NewNode: " << newNode->getID(); dump (); assert (false); throw (std::runtime_error ("invalid inner node")); @@ -808,14 +818,15 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta int b1, b2; - while ((b1 = node->selectBranch (tag)) == (b2 = node->selectBranch (otherItem->getTag ()))) + while ((b1 = node->getID().selectBranch (tag)) == + (b2 = node->getID().selectBranch (otherItem->getTag ()))) { // we need a new inner node, since both go on same branch at this level SHAMapTreeNode::pointer newNode = - std::make_shared (mSeq, node->getChildNodeID (b1)); + std::make_shared (mSeq, node->getID().getChildNodeID (b1)); newNode->makeInner (); - if (!mTNByID.peekMap().emplace (SHAMapNode (*newNode), newNode).second) + if (!mTNByID.peekMap().emplace (SHAMapNodeID (newNode->getID()), newNode).second) assert (false); stack.push (node); @@ -826,19 +837,21 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta // we can add the two leaf nodes here assert (node->isInner ()); SHAMapTreeNode::pointer newNode = - std::make_shared (node->getChildNodeID (b1), item, type, mSeq); + std::make_shared (node->getID().getChildNodeID (b1), + item, type, mSeq); assert (newNode->isValid () && newNode->isLeaf ()); - if (!mTNByID.peekMap().emplace (SHAMapNode (*newNode), newNode).second) + if (!mTNByID.peekMap().emplace (SHAMapNodeID (newNode->getID()), newNode).second) assert (false); node->setChildHash (b1, newNode->getNodeHash ()); // OPTIMIZEME hash op not needed trackNewNode (newNode); - newNode = std::make_shared (node->getChildNodeID (b2), otherItem, type, mSeq); + newNode = std::make_shared (node->getID().getChildNodeID (b2), + otherItem, type, mSeq); assert (newNode->isValid () && newNode->isLeaf ()); - if (!mTNByID.peekMap().emplace (SHAMapNode (*newNode), newNode).second) + if (!mTNByID.peekMap().emplace (SHAMapNodeID (newNode->getID()), newNode).second) assert (false); node->setChildHash (b2, newNode->getNodeHash ()); @@ -894,7 +907,7 @@ void SHAMapItem::dump () WriteLog (lsINFO, SHAMap) << "SHAMapItem(" << mTag << ") " << mData.size () << "bytes"; } -SHAMapTreeNode::pointer SHAMap::fetchNodeExternal (const SHAMapNode& id, uint256 const& hash) +SHAMapTreeNode::pointer SHAMap::fetchNodeExternal (const SHAMapNodeID& id, uint256 const& hash) { SHAMapTreeNode::pointer ret = fetchNodeExternalNT (id, hash); @@ -906,7 +919,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal (const SHAMapNode& id, uint256 // Non-blocking version SHAMapTreeNode* SHAMap::getNodeAsync ( - const SHAMapNode& id, + const SHAMapNodeID& id, uint256 const& hash, SHAMapSyncFilter *filter, bool& pending) @@ -957,7 +970,7 @@ SHAMapTreeNode* SHAMap::getNodeAsync ( return nullptr; ptr = std::make_shared (id, obj->getData(), 0, snfPREFIX, hash, true); - if (id != *ptr) + if (id != ptr->getID()) { assert (false); return nullptr; @@ -986,7 +999,7 @@ SHAMapTreeNode* SHAMap::getNodeAsync ( get a shared pointer to the same underlying node. This function does not throw. */ -SHAMapTreeNode::pointer SHAMap::fetchNodeExternalNT (const SHAMapNode& id, uint256 const& hash) +SHAMapTreeNode::pointer SHAMap::fetchNodeExternalNT (const SHAMapNodeID& id, uint256 const& hash) { SHAMapTreeNode::pointer ret; @@ -998,7 +1011,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternalNT (const SHAMapNode& id, uint2 if (ret) { // The node was found in the TreeNodeCache assert (ret->getSeq() == 0); - assert (id == *ret); + assert (id == ret->getID()); } else { // Check the back end @@ -1020,9 +1033,9 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternalNT (const SHAMapNode& id, uint2 // CoW is needed if it is modified ret = std::make_shared (id, obj->getData (), 0, snfPREFIX, hash, true); - if (id != *ret) + if (id != ret->getID()) { - WriteLog (lsFATAL, SHAMap) << "id:" << id << ", got:" << *ret; + WriteLog (lsFATAL, SHAMap) << "id:" << id << ", got:" << ret->getID(); assert (false); return SHAMapTreeNode::pointer (); } @@ -1069,7 +1082,7 @@ bool SHAMap::fetchRoot (uint256 const& hash, SHAMapSyncFilter* filter) WriteLog (lsTRACE, SHAMap) << "Fetch root SHAMap node " << hash; } - SHAMapTreeNode::pointer newRoot = fetchNodeExternalNT(SHAMapNode(), hash); + SHAMapTreeNode::pointer newRoot = fetchNodeExternalNT(SHAMapNodeID(), hash); if (newRoot) { @@ -1079,13 +1092,13 @@ bool SHAMap::fetchRoot (uint256 const& hash, SHAMapSyncFilter* filter) { Blob nodeData; - if (!filter || !filter->haveNode (SHAMapNode (), hash, nodeData)) + if (!filter || !filter->haveNode (SHAMapNodeID (), hash, nodeData)) return false; - root = std::make_shared (SHAMapNode (), nodeData, + root = std::make_shared (SHAMapNodeID (), nodeData, mSeq - 1, snfPREFIX, hash, true); - mTNByID.replace(*root, root); - filter->gotNode (true, SHAMapNode (), hash, nodeData, root->getType ()); + mTNByID.replace(root->getID(), root); + filter->gotNode (true, SHAMapNodeID (), hash, nodeData, root->getType ()); } assert (root->getNodeHash () == hash); @@ -1124,7 +1137,7 @@ int SHAMap::flushDirty (DirtySet& set, int maxNodes, NodeObjectType t, std::uint if (s.getSHA512Half () != nodeHash) { - WriteLog (lsFATAL, SHAMap) << *node; + WriteLog (lsFATAL, SHAMap) << node->getID(); WriteLog (lsFATAL, SHAMap) << beast::lexicalCast (s.getDataLength ()); WriteLog (lsFATAL, SHAMap) << s.getSHA512Half () << " != " << nodeHash; assert (false); @@ -1138,7 +1151,7 @@ int SHAMap::flushDirty (DirtySet& set, int maxNodes, NodeObjectType t, std::uint // Make and share a shareable copy node = std::make_shared (*node, 0); canonicalize (node->getNodeHash(), node); - mTNByID.replace (*node, node); + mTNByID.replace (node->getID(), node); } getApp().getNodeStore ().store (t, seq, std::move (s.modData ()), nodeHash); @@ -1160,7 +1173,7 @@ std::shared_ptr SHAMap::disarmDirty () return ret; } -SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& nodeID) +SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNodeID& nodeID) { SHAMapTreeNode::pointer node = checkCacheNode (nodeID); @@ -1170,15 +1183,16 @@ SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& nodeID) node = root; - while (nodeID != *node) + while (nodeID != node->getID()) { - int branch = node->selectBranch (nodeID.getNodeID ()); + int branch = node->getID().selectBranch (nodeID.getNodeID ()); assert (branch >= 0); if ((branch < 0) || node->isEmptyBranch (branch)) return SHAMapTreeNode::pointer (); - node = getNode (node->getChildNodeID (branch), node->getChildHash (branch), false); + node = getNode (node->getID().getChildNodeID (branch), + node->getChildHash (branch), false); assert (node); } @@ -1187,7 +1201,7 @@ SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& nodeID) // This function returns NULL if no node with that ID exists in the map // It throws if the map is incomplete -SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& nodeID) +SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNodeID& nodeID) { SHAMapTreeNode::pointer nodeptr = mTNByID.retrieve (nodeID); if (nodeptr) @@ -1199,18 +1213,19 @@ SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& nodeID) SHAMapTreeNode* node = root.get(); - while (nodeID != *node) + while (nodeID != node->getID()) { if (node->isLeaf ()) return nullptr; - int branch = node->selectBranch (nodeID.getNodeID ()); + int branch = node->getID().selectBranch (nodeID.getNodeID ()); assert (branch >= 0); if ((branch < 0) || node->isEmptyBranch (branch)) return nullptr; - node = getNodePointer (node->getChildNodeID (branch), node->getChildHash (branch)); + node = getNodePointer (node->getID().getChildNodeID (branch), + node->getChildHash (branch)); assert (node); } @@ -1232,12 +1247,13 @@ bool SHAMap::getPath (uint256 const& index, std::vector< Blob >& nodes, SHANodeF inNode->addRaw (s, format); nodes.push_back (s.peekData ()); - int branch = inNode->selectBranch (index); + int branch = inNode->getID().selectBranch (index); if (inNode->isEmptyBranch (branch)) // paths leads to empty branch return false; - inNode = getNodePointer (inNode->getChildNodeID (branch), inNode->getChildHash (branch)); + inNode = getNodePointer (inNode->getID().getChildNodeID (branch), + inNode->getChildHash (branch)); assert (inNode); } @@ -1259,7 +1275,7 @@ void SHAMap::dropCache () mTNByID.clear (); if (root) - mTNByID.canonicalize(*root, &root); + mTNByID.canonicalize(root->getID(), &root); } void SHAMap::dropBelow (SHAMapTreeNode* d) @@ -1267,7 +1283,7 @@ void SHAMap::dropBelow (SHAMapTreeNode* d) if (d->isInner ()) for (int i = 0 ; i < 16; ++i) if (!d->isEmptyBranch (i)) - mTNByID.erase (d->getChildNodeID (i)); + mTNByID.erase (d->getID().getChildNodeID (i)); } void SHAMap::dump (bool hash) @@ -1275,7 +1291,7 @@ void SHAMap::dump (bool hash) WriteLog (lsINFO, SHAMap) << " MAP Contains"; ScopedWriteLockType sl (mLock); - for (ripple::unordered_map::iterator it = mTNByID.peekMap().begin (); + for (ripple::unordered_map::iterator it = mTNByID.peekMap().begin (); it != mTNByID.peekMap().end (); ++it) { WriteLog (lsINFO, SHAMap) << it->second->getString (); @@ -1284,21 +1300,21 @@ void SHAMap::dump (bool hash) } -SHAMapTreeNode::pointer SHAMap::getCache (uint256 const& hash, SHAMapNode const& id) +SHAMapTreeNode::pointer SHAMap::getCache (uint256 const& hash, SHAMapNodeID const& id) { SHAMapTreeNode::pointer ret = treeNodeCache.fetch (hash); assert (!ret || !ret->getSeq()); - if (ret && (*ret != id)) + if (ret && (ret->getID() != id)) { // We have the data, but with a different node ID - WriteLog (lsTRACE, SHAMap) << "ID mismatch: " << id << " != " << *ret; + WriteLog (lsTRACE, SHAMap) << "ID mismatch: " << id << " != " << ret->getID(); ret = std::make_shared (*ret, 0); - ret->set(id); + ret->setID(id); // Future fetches are likely to use the "new" ID treeNodeCache.canonicalize (hash, ret, true); - assert (*ret == id); + assert (ret->getID() == id); assert (ret->getNodeHash() == hash); } @@ -1309,19 +1325,19 @@ void SHAMap::canonicalize (uint256 const& hash, SHAMapTreeNode::pointer& node) { assert (node->getSeq() == 0); - SHAMapNode id = *node; + SHAMapNodeID id = node->getID(); treeNodeCache.canonicalize (hash, node); - if (id != *node) + if (id != node->getID()) { // The cache has the node with a different ID node = std::make_shared (*node, 0); - node->set (id); + node->setID(id); // Future fetches are likely to use the newer ID treeNodeCache.canonicalize (hash, node, true); - assert (id == *node); + assert (id == node->getID()); } } diff --git a/src/ripple/module/app/shamap/SHAMap.h b/src/ripple/module/app/shamap/SHAMap.h index 6ce18e2030..bfa3e360f3 100644 --- a/src/ripple/module/app/shamap/SHAMap.h +++ b/src/ripple/module/app/shamap/SHAMap.h @@ -32,9 +32,9 @@ namespace std { template <> -struct hash +struct hash { - std::size_t operator() (ripple::SHAMapNode const& value) const + std::size_t operator() (ripple::SHAMapNodeID const& value) const { return value.getMHash (); } @@ -47,7 +47,7 @@ struct hash namespace boost { template <> -struct hash : std::hash +struct hash : std::hash { }; @@ -115,8 +115,8 @@ public: typedef std::pair DeltaItem; typedef std::pair DeltaRef; typedef std::map Delta; - typedef ripple::unordered_map NodeMap; - typedef std::unordered_set DirtySet; + typedef ripple::unordered_map NodeMap; + typedef std::unordered_set DirtySet; typedef boost::shared_mutex LockType; typedef boost::shared_lock ScopedReadLockType; @@ -148,7 +148,7 @@ public: mLedgerSeq = lseq; } - bool hasNode (const SHAMapNode & id); + bool hasNode (const SHAMapNodeID & id); bool fetchRoot (uint256 const & hash, SHAMapSyncFilter * filter); // normal hash access functions @@ -184,9 +184,9 @@ public: void visitLeaves(std::function); // comparison/sync functions - void getMissingNodes (std::vector& nodeIDs, std::vector& hashes, int max, + void getMissingNodes (std::vector& nodeIDs, std::vector& hashes, int max, SHAMapSyncFilter * filter); - bool getNodeFat (const SHAMapNode & node, std::vector& nodeIDs, + bool getNodeFat (SHAMapNodeID const& node, std::vector& nodeIDs, std::list& rawNode, bool fatRoot, bool fatLeaves); bool getRootNode (Serializer & s, SHANodeFormat format); std::vector getNeededHashes (int max, SHAMapSyncFilter * filter); @@ -194,7 +194,7 @@ public: SHAMapSyncFilter * filter); SHAMapAddNode addRootNode (Blob const & rootNode, SHANodeFormat format, SHAMapSyncFilter * filter); - SHAMapAddNode addKnownNode (const SHAMapNode & nodeID, Blob const & rawNode, + SHAMapAddNode addKnownNode (const SHAMapNodeID & nodeID, Blob const & rawNode, SHAMapSyncFilter * filter); // status functions @@ -248,8 +248,8 @@ public: } // overloads for backed maps - SHAMapTreeNode::pointer fetchNodeExternal (const SHAMapNode & id, uint256 const & hash); // throws - SHAMapTreeNode::pointer fetchNodeExternalNT (const SHAMapNode & id, uint256 const & hash); // no throw + SHAMapTreeNode::pointer fetchNodeExternal (const SHAMapNodeID & id, uint256 const & hash); // throws + SHAMapTreeNode::pointer fetchNodeExternalNT (const SHAMapNodeID & id, uint256 const & hash); // no throw bool operator== (const SHAMap & s) { @@ -278,7 +278,7 @@ public: // new Application singleton class. // // tree node cache operations - static SHAMapTreeNode::pointer getCache (uint256 const& hash, SHAMapNode const& id); + static SHAMapTreeNode::pointer getCache (uint256 const& hash, SHAMapNodeID const& id); static void canonicalize (uint256 const& hash, SHAMapTreeNode::pointer&); static int getTreeNodeSize () @@ -302,7 +302,7 @@ public: mTXMap = true; } - typedef std::pair TNIndex; + typedef std::pair TNIndex; private: static TaggedCache treeNodeCache; @@ -311,28 +311,28 @@ private: std::stack getStack (uint256 const & id, bool include_nonmatching_leaf); SHAMapTreeNode::pointer walkTo (uint256 const & id, bool modify); SHAMapTreeNode* walkToPointer (uint256 const & id); - SHAMapTreeNode::pointer checkCacheNode (const SHAMapNode&); + SHAMapTreeNode::pointer checkCacheNode (const SHAMapNodeID&); void returnNode (SHAMapTreeNode::pointer&, bool modify); void trackNewNode (SHAMapTreeNode::pointer&); - SHAMapTreeNode::pointer getNode (const SHAMapNode & id); - SHAMapTreeNode::pointer getNode (const SHAMapNode & id, uint256 const & hash, bool modify); - SHAMapTreeNode* getNodePointer (const SHAMapNode & id); - SHAMapTreeNode* getNodePointer (const SHAMapNode & id, uint256 const & hash); - SHAMapTreeNode* getNodePointerNT (const SHAMapNode & id, uint256 const & hash); - SHAMapTreeNode* getNodePointer (const SHAMapNode & id, uint256 const & hash, SHAMapSyncFilter * filter); - SHAMapTreeNode* getNodePointerNT (const SHAMapNode & id, uint256 const & hash, SHAMapSyncFilter * filter); + SHAMapTreeNode::pointer getNode (const SHAMapNodeID & id); + SHAMapTreeNode::pointer getNode (const SHAMapNodeID & id, uint256 const & hash, bool modify); + SHAMapTreeNode* getNodePointer (const SHAMapNodeID & id); + SHAMapTreeNode* getNodePointer (const SHAMapNodeID & id, uint256 const & hash); + SHAMapTreeNode* getNodePointerNT (const SHAMapNodeID & id, uint256 const & hash); + SHAMapTreeNode* getNodePointer (const SHAMapNodeID & id, uint256 const & hash, SHAMapSyncFilter * filter); + SHAMapTreeNode* getNodePointerNT (const SHAMapNodeID & id, uint256 const & hash, SHAMapSyncFilter * filter); SHAMapTreeNode* firstBelow (SHAMapTreeNode*); SHAMapTreeNode* lastBelow (SHAMapTreeNode*); // Non-blocking version of getNodePointerNT SHAMapTreeNode* getNodeAsync ( - const SHAMapNode & id, uint256 const & hash, SHAMapSyncFilter * filter, bool& pending); + const SHAMapNodeID & id, uint256 const & hash, SHAMapSyncFilter * filter, bool& pending); SHAMapItem::pointer onlyBelow (SHAMapTreeNode*); void eraseChildren (SHAMapTreeNode::pointer); void dropBelow (SHAMapTreeNode*); - bool hasInnerNode (const SHAMapNode & nodeID, uint256 const & hash); + bool hasInnerNode (const SHAMapNodeID & nodeID, uint256 const & hash); bool hasLeafNode (uint256 const & tag, uint256 const & hash); bool walkBranch (SHAMapTreeNode * node, SHAMapItem::ref otherMapItem, bool isFirstMap, @@ -350,7 +350,7 @@ private: FullBelowCache& m_fullBelowCache; std::uint32_t mSeq; std::uint32_t mLedgerSeq; // sequence number of ledger this is part of - SyncUnorderedMapType< SHAMapNode, SHAMapTreeNode::pointer, SHAMapNode_hash > mTNByID; + SyncUnorderedMapType< SHAMapNodeID, SHAMapTreeNode::pointer, SHAMapNode_hash > mTNByID; std::shared_ptr mDirtyNodes; SHAMapTreeNode::pointer root; SHAMapState mState; diff --git a/src/ripple/module/app/shamap/SHAMapDelta.cpp b/src/ripple/module/app/shamap/SHAMapDelta.cpp index b8821e13c9..2287cf8904 100644 --- a/src/ripple/module/app/shamap/SHAMapDelta.cpp +++ b/src/ripple/module/app/shamap/SHAMapDelta.cpp @@ -30,10 +30,10 @@ namespace ripple { class SHAMapDeltaNode { public: - SHAMapNode mNodeID; + SHAMapNodeID mNodeID; uint256 mOurHash, mOtherHash; - SHAMapDeltaNode (const SHAMapNode& id, uint256 const& ourHash, uint256 const& otherHash) : + SHAMapDeltaNode (const SHAMapNodeID& id, uint256 const& ourHash, uint256 const& otherHash) : mNodeID (id), mOurHash (ourHash), mOtherHash (otherHash) { ; @@ -59,7 +59,8 @@ bool SHAMap::walkBranch (SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, boo // This is an inner node, add all non-empty branches for (int i = 0; i < 16; ++i) if (!node->isEmptyBranch (i)) - nodeStack.push (getNodePointer (node->getChildNodeID (i), node->getChildHash (i))); + nodeStack.push (getNodePointer (node->getID().getChildNodeID (i), + node->getChildHash (i))); } else { @@ -145,7 +146,7 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount) if (getHash () == otherMap->getHash ()) return true; - nodeStack.push (SHAMapDeltaNode (SHAMapNode (), getHash (), otherMap->getHash ())); + nodeStack.push (SHAMapDeltaNode (SHAMapNodeID (), getHash (), otherMap->getHash ())); while (!nodeStack.empty ()) { @@ -208,7 +209,8 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount) if (otherNode->isEmptyBranch (i)) { // We have a branch, the other tree does not - SHAMapTreeNode* iNode = getNodePointer (ourNode->getChildNodeID (i), ourNode->getChildHash (i)); + SHAMapTreeNode* iNode = getNodePointer (ourNode->getID().getChildNodeID (i), + ourNode->getChildHash (i)); if (!walkBranch (iNode, SHAMapItem::pointer (), true, differences, maxCount)) return false; @@ -217,13 +219,14 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount) { // The other tree has a branch, we do not SHAMapTreeNode* iNode = - otherMap->getNodePointer (otherNode->getChildNodeID (i), otherNode->getChildHash (i)); + otherMap->getNodePointer (otherNode->getID().getChildNodeID (i), + otherNode->getChildHash (i)); if (!otherMap->walkBranch (iNode, SHAMapItem::pointer (), false, differences, maxCount)) return false; } else // The two trees have different non-empty branches - nodeStack.push (SHAMapDeltaNode (ourNode->getChildNodeID (i), + nodeStack.push (SHAMapDeltaNode (ourNode->getID().getChildNodeID (i), ourNode->getChildHash (i), otherNode->getChildHash (i))); } } @@ -255,7 +258,8 @@ void SHAMap::walkMap (std::vector& missingNodes, int maxMissi { try { - SHAMapTreeNode::pointer d = getNode (node->getChildNodeID (i), node->getChildHash (i), false); + SHAMapTreeNode::pointer d = getNode (node->getID().getChildNodeID (i), + node->getChildHash (i), false); if (d->isInner ()) nodeStack.push (d); diff --git a/src/ripple/module/app/shamap/SHAMapMissingNode.h b/src/ripple/module/app/shamap/SHAMapMissingNode.h index 284fed1c6a..02db8644bd 100644 --- a/src/ripple/module/app/shamap/SHAMapMissingNode.h +++ b/src/ripple/module/app/shamap/SHAMapMissingNode.h @@ -33,7 +33,7 @@ class SHAMapMissingNode : public std::runtime_error { public: SHAMapMissingNode (SHAMapType t, - SHAMapNode const& nodeID, + SHAMapNodeID const& nodeID, uint256 const& nodeHash) : std::runtime_error ("SHAMapMissingNode") , mType (t) @@ -43,7 +43,7 @@ public: } SHAMapMissingNode (SHAMapType t, - SHAMapNode const& nodeID, + SHAMapNodeID const& nodeID, uint256 const& nodeHash, uint256 const& targetIndex) : std::runtime_error (nodeID.getString ()) @@ -68,7 +68,7 @@ public: return mType; } - SHAMapNode const& getNodeID () const + SHAMapNodeID const& getNodeID () const { return mNodeID; } @@ -90,7 +90,7 @@ public: private: SHAMapType mType; - SHAMapNode mNodeID; + SHAMapNodeID mNodeID; uint256 mNodeHash; uint256 mTargetIndex; }; diff --git a/src/ripple/module/app/shamap/SHAMapNode.cpp b/src/ripple/module/app/shamap/SHAMapNodeID.cpp similarity index 66% rename from src/ripple/module/app/shamap/SHAMapNode.cpp rename to src/ripple/module/app/shamap/SHAMapNodeID.cpp index 19a3da3dee..6f4ee7588b 100644 --- a/src/ripple/module/app/shamap/SHAMapNode.cpp +++ b/src/ripple/module/app/shamap/SHAMapNodeID.cpp @@ -17,26 +17,34 @@ */ //============================================================================== +#include +#include +#include +#include +#include + namespace ripple { // canonicalize the hash to a node ID for this depth -SHAMapNode::SHAMapNode (int depth, uint256 const& hash) : mNodeID (hash), mDepth (depth), mHash (0) +SHAMapNodeID::SHAMapNodeID (int depth, uint256 const& hash) + : mNodeID (hash), mDepth (depth), mHash (0) { assert ((depth >= 0) && (depth < 65)); mNodeID &= smMasks[depth]; } -SHAMapNode::SHAMapNode (const void* ptr, int len) : mHash (0) +SHAMapNodeID::SHAMapNodeID (void const* ptr, int len) : mHash (0) { if (len < 33) mDepth = -1; else { - memcpy (mNodeID.begin (), ptr, 32); - mDepth = * (static_cast (ptr) + 32); + std::memcpy (mNodeID.begin (), ptr, 32); + mDepth = * (static_cast (ptr) + 32); } } -std::string SHAMapNode::getString () const + +std::string SHAMapNodeID::getString () const { static boost::format NodeID ("NodeID(%s,%s)"); @@ -48,13 +56,13 @@ std::string SHAMapNode::getString () const % to_string (mNodeID)); } -uint256 SHAMapNode::smMasks[65]; +uint256 SHAMapNodeID::smMasks[65]; // VFALCO TODO use a static initializer to do this instead -bool SMN_j = SHAMapNode::ClassInit (); +bool SMN_j = SHAMapNodeID::ClassInit (); // set up the depth masks -bool SHAMapNode::ClassInit () +bool SHAMapNodeID::ClassInit () { uint256 selector; @@ -71,56 +79,19 @@ bool SHAMapNode::ClassInit () return true; } - -bool SHAMapNode::operator< (const SHAMapNode& s) const -{ - if (s.mDepth < mDepth) return true; - - if (s.mDepth > mDepth) return false; - - return mNodeID < s.mNodeID; -} - -bool SHAMapNode::operator> (const SHAMapNode& s) const -{ - if (s.mDepth < mDepth) return false; - - if (s.mDepth > mDepth) return true; - - return mNodeID > s.mNodeID; -} - -bool SHAMapNode::operator<= (const SHAMapNode& s) const -{ - if (s.mDepth < mDepth) return true; - - if (s.mDepth > mDepth) return false; - - return mNodeID <= s.mNodeID; -} - -bool SHAMapNode::operator>= (const SHAMapNode& s) const -{ - if (s.mDepth < mDepth) return false; - - if (s.mDepth > mDepth) return true; - - return mNodeID >= s.mNodeID; -} - -uint256 SHAMapNode::getNodeID (int depth, uint256 const& hash) +uint256 SHAMapNodeID::getNodeID (int depth, uint256 const& hash) { assert ((depth >= 0) && (depth <= 64)); return hash & smMasks[depth]; } -void SHAMapNode::addIDRaw (Serializer& s) const +void SHAMapNodeID::addIDRaw (Serializer& s) const { s.add256 (mNodeID); s.add8 (mDepth); } -std::string SHAMapNode::getRawString () const +std::string SHAMapNodeID::getRawString () const { Serializer s (33); addIDRaw (s); @@ -128,18 +99,18 @@ std::string SHAMapNode::getRawString () const } // This can be optimized to avoid the << if needed -SHAMapNode SHAMapNode::getChildNodeID (int m) const +SHAMapNodeID SHAMapNodeID::getChildNodeID (int m) const { assert ((m >= 0) && (m < 16)); uint256 child (mNodeID); child.begin ()[mDepth / 2] |= (mDepth & 1) ? m : (m << 4); - return SHAMapNode (mDepth + 1, child, true); + return SHAMapNodeID (mDepth + 1, child, true); } // Which branch would contain the specified hash -int SHAMapNode::selectBranch (uint256 const& hash) const +int SHAMapNodeID::selectBranch (uint256 const& hash) const { #if RIPPLE_VERIFY_NODEOBJECT_KEYS @@ -171,9 +142,9 @@ int SHAMapNode::selectBranch (uint256 const& hash) const return branch; } -void SHAMapNode::dump () const +void SHAMapNodeID::dump () const { - WriteLog (lsDEBUG, SHAMapNode) << getString (); + WriteLog (lsDEBUG, SHAMapNodeID) << getString (); } } // ripple diff --git a/src/ripple/module/app/shamap/SHAMapNode.h b/src/ripple/module/app/shamap/SHAMapNodeID.h similarity index 65% rename from src/ripple/module/app/shamap/SHAMapNode.h rename to src/ripple/module/app/shamap/SHAMapNodeID.h index 3326cf34b1..050052fa85 100644 --- a/src/ripple/module/app/shamap/SHAMapNode.h +++ b/src/ripple/module/app/shamap/SHAMapNodeID.h @@ -17,43 +17,64 @@ */ //============================================================================== -#ifndef RIPPLE_SHAMAPNODE_H -#define RIPPLE_SHAMAPNODE_H +#ifndef RIPPLE_SHAMAPNODEID_H +#define RIPPLE_SHAMAPNODEID_H -#include +#include +#include +#include +#include namespace ripple { // Identifies a node in a SHA256 hash map -class SHAMapNode +class SHAMapNodeID { -public: - SHAMapNode () : mDepth (0), mHash (0) - { - ; - } - SHAMapNode (int depth, uint256 const& hash); +private: + static uint256 smMasks[65]; // AND with hash to get node id + uint256 mNodeID; + int mDepth; + mutable size_t mHash; +public: + SHAMapNodeID () : mDepth (0), mHash (0) + { + } + + SHAMapNodeID (int depth, uint256 const& hash); + SHAMapNodeID (void const* ptr, int len); + +protected: + SHAMapNodeID (int depth, uint256 const& id, bool) + : mNodeID (id), mDepth (depth), mHash (0) + { + } + +public: int getDepth () const { return mDepth; } + uint256 const& getNodeID () const { return mNodeID; } + bool isValid () const { return (mDepth >= 0) && (mDepth < 64); } + bool isRoot () const { return mDepth == 0; } + size_t getMHash () const { - if (mHash == 0) setMHash (); - + if (mHash == 0) + setMHash (); return mHash; } @@ -62,42 +83,34 @@ public: return false; } - SHAMapNode getParentNodeID () const + SHAMapNodeID getParentNodeID () const { assert (mDepth); - return SHAMapNode (mDepth - 1, mNodeID); + return SHAMapNodeID (mDepth - 1, mNodeID); } - SHAMapNode getChildNodeID (int m) const; + SHAMapNodeID getChildNodeID (int m) const; int selectBranch (uint256 const& hash) const; - bool operator< (const SHAMapNode&) const; - bool operator> (const SHAMapNode&) const; - bool operator<= (const SHAMapNode&) const; - bool operator>= (const SHAMapNode&) const; + bool operator< (const SHAMapNodeID& n) const + { + return std::tie(mDepth, mNodeID) < std::tie(n.mDepth, n.mNodeID); + } + bool operator> (const SHAMapNodeID& n) const {return n < *this;} + bool operator<= (const SHAMapNodeID& n) const {return !(*this < n);} + bool operator>= (const SHAMapNodeID& n) const {return !(n < *this);} - bool operator== (const SHAMapNode& n) const + bool operator== (const SHAMapNodeID& n) const { return (mDepth == n.mDepth) && (mNodeID == n.mNodeID); } + bool operator!= (const SHAMapNodeID& n) const {return !(*this == n);} + bool operator== (uint256 const& n) const { return n == mNodeID; } - bool operator!= (const SHAMapNode& n) const - { - return (mDepth != n.mDepth) || (mNodeID != n.mNodeID); - } - bool operator!= (uint256 const& n) const - { - return n != mNodeID; - } - void set (SHAMapNode const& from) - { - mNodeID = from.mNodeID; - mDepth = from.mDepth; - mHash = from.mHash; - } + bool operator!= (uint256 const& n) const {return !(*this == n);} virtual std::string getString () const; void dump () const; @@ -112,27 +125,14 @@ public: { return 33; } - SHAMapNode (const void* ptr, int len); - -protected: - SHAMapNode (int depth, uint256 const& id, bool) : mNodeID (id), mDepth (depth), mHash (0) - { - ; - } private: - static uint256 smMasks[65]; // AND with hash to get node id - - uint256 mNodeID; - int mDepth; - mutable size_t mHash; - void setMHash () const; }; -extern std::size_t hash_value (const SHAMapNode& mn); +extern std::size_t hash_value (SHAMapNodeID const& mn); -inline std::ostream& operator<< (std::ostream& out, const SHAMapNode& node) +inline std::ostream& operator<< (std::ostream& out, SHAMapNodeID const& node) { return out << node.getString (); } @@ -140,7 +140,7 @@ inline std::ostream& operator<< (std::ostream& out, const SHAMapNode& node) class SHAMapNode_hash { public: - typedef ripple::SHAMapNode argument_type; + typedef ripple::SHAMapNodeID argument_type; typedef std::size_t result_type; result_type @@ -150,7 +150,7 @@ public: } }; -} +} // ripple //------------------------------------------------------------------------------ @@ -158,9 +158,9 @@ public: namespace std { template <> -struct hash +struct hash { - std::size_t operator() (ripple::SHAMapNode const& value) const + std::size_t operator() (ripple::SHAMapNodeID const& value) const { return value.getMHash (); } @@ -175,7 +175,7 @@ struct hash namespace boost { template <> -struct hash : std::hash +struct hash : std::hash { }; diff --git a/src/ripple/module/app/shamap/SHAMapSync.cpp b/src/ripple/module/app/shamap/SHAMapSync.cpp index f4ced71d84..7ed6c4456d 100644 --- a/src/ripple/module/app/shamap/SHAMapSync.cpp +++ b/src/ripple/module/app/shamap/SHAMapSync.cpp @@ -62,11 +62,12 @@ void SHAMap::visitLeavesInternal (std::function& fu } else { - SHAMapTreeNode* child = getNodePointer (node->getChildNodeID (pos), node->getChildHash (pos)); + SHAMapTreeNode* child = getNodePointer (node->getID().getChildNodeID (pos), + node->getChildHash (pos)); if (child->isLeaf ()) { function (child->peekItem ()); - mTNByID.erase (*child); // don't need this leaf anymore + mTNByID.erase (child->getID()); // don't need this leaf anymore ++pos; } else @@ -78,7 +79,7 @@ void SHAMap::visitLeavesInternal (std::function& fu if (pos != 15) stack.push (posPair (pos + 1, node)); // save next position to resume at else - mTNByID.erase (*node); // don't need this inner node anymore + mTNByID.erase (node->getID()); // don't need this inner node anymore // descend to the child's first position node = child; @@ -88,7 +89,7 @@ void SHAMap::visitLeavesInternal (std::function& fu } // We are done with this inner node - mTNByID.erase (*node); + mTNByID.erase (node->getID()); if (stack.empty ()) break; @@ -116,7 +117,7 @@ public: /** Get a list of node IDs and hashes for nodes that are part of this SHAMap but not available locally. The filter can hold alternate sources of nodes that are not permanently stored locally */ -void SHAMap::getMissingNodes (std::vector& nodeIDs, std::vector& hashes, int max, +void SHAMap::getMissingNodes (std::vector& nodeIDs, std::vector& hashes, int max, SHAMapSyncFilter* filter) { ScopedReadLockType sl (mLock); @@ -145,7 +146,7 @@ void SHAMap::getMissingNodes (std::vector& nodeIDs, std::vector> deferredReads; + std::vector > deferredReads; deferredReads.reserve (maxDefer + 16); std::stack stack; @@ -168,7 +169,7 @@ void SHAMap::getMissingNodes (std::vector& nodeIDs, std::vectorgetChildNodeID (branch); + SHAMapNodeID childID = node->getID().getChildNodeID (branch); bool pending = false; SHAMapTreeNode* d = getNodeAsync (childID, childHash, filter, pending); @@ -242,7 +243,7 @@ void SHAMap::getMissingNodes (std::vector& nodeIDs, std::vector SHAMap::getNeededHashes (int max, SHAMapSyncFilter* filter) std::vector nodeHashes; nodeHashes.reserve(max); - std::vector nodeIDs; + std::vector nodeIDs; nodeIDs.reserve(max); getMissingNodes(nodeIDs, nodeHashes, max, filter); return nodeHashes; } -bool SHAMap::getNodeFat (const SHAMapNode& wanted, std::vector& nodeIDs, +bool SHAMap::getNodeFat (const SHAMapNodeID& wanted, std::vector& nodeIDs, std::list& rawNodes, bool fatRoot, bool fatLeaves) { // Gets a node and some of its children @@ -302,11 +303,11 @@ bool SHAMap::getNodeFat (const SHAMapNode& wanted, std::vector& node { Serializer s; node->addRaw (s, snfWIRE); - nodeIDs.push_back(*node); + nodeIDs.push_back(node->getID()); rawNodes.push_back (s.peekData ()); } - if ((!fatRoot && node->isRoot ()) || node->isLeaf ()) // don't get a fat root, can't get a fat leaf + if ((!fatRoot && node->getID().isRoot ()) || node->isLeaf ()) // don't get a fat root, can't get a fat leaf return true; SHAMapTreeNode* nextNode = nullptr; @@ -315,13 +316,14 @@ bool SHAMap::getNodeFat (const SHAMapNode& wanted, std::vector& node for (int i = 0; i < 16; ++i) if (!node->isEmptyBranch (i)) { - nextNode = getNodePointer (node->getChildNodeID (i), node->getChildHash (i)); + nextNode = getNodePointer (node->getID().getChildNodeID (i), + node->getChildHash (i)); ++count; if (fatLeaves || nextNode->isInner ()) { Serializer s; nextNode->addRaw (s, snfWIRE); - nodeIDs.push_back (*nextNode); + nodeIDs.push_back (nextNode->getID()); rawNodes.push_back (s.peekData ()); skipNode = true; // Don't add this node again if we loop } @@ -356,7 +358,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, SHANodeFormat format, assert (mSeq >= 1); SHAMapTreeNode::pointer node = - std::make_shared (SHAMapNode (), rootNode, mSeq - 1, format, uZero, false); + std::make_shared (SHAMapNodeID (), rootNode, mSeq - 1, format, uZero, false); if (!node) return SHAMapAddNode::invalid (); @@ -366,7 +368,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, SHANodeFormat format, #endif root = node; - mTNByID.replace(*root, root); + mTNByID.replace(root->getID(), root); if (root->isLeaf()) clearSynching (); @@ -375,7 +377,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, SHANodeFormat format, { Serializer s; root->addRaw (s, snfPREFIX); - filter->gotNode (false, *root, root->getNodeHash (), s.modData (), root->getType ()); + filter->gotNode (false, root->getID(), root->getNodeHash (), s.modData (), root->getType ()); } return SHAMapAddNode::useful (); @@ -396,13 +398,13 @@ SHAMapAddNode SHAMap::addRootNode (uint256 const& hash, Blob const& rootNode, SH assert (mSeq >= 1); SHAMapTreeNode::pointer node = - std::make_shared (SHAMapNode (), rootNode, mSeq - 1, format, uZero, false); + std::make_shared (SHAMapNodeID (), rootNode, mSeq - 1, format, uZero, false); if (!node || node->getNodeHash () != hash) return SHAMapAddNode::invalid (); root = node; - mTNByID.replace(*root, root); + mTNByID.replace(root->getID(), root); if (root->isLeaf()) clearSynching (); @@ -411,13 +413,14 @@ SHAMapAddNode SHAMap::addRootNode (uint256 const& hash, Blob const& rootNode, SH { Serializer s; root->addRaw (s, snfPREFIX); - filter->gotNode (false, *root, root->getNodeHash (), s.modData (), root->getType ()); + filter->gotNode (false, root->getID(), root->getNodeHash (), s.modData (), + root->getType ()); } return SHAMapAddNode::useful (); } -SHAMapAddNode SHAMap::addKnownNode (const SHAMapNode& node, Blob const& rawNode, SHAMapSyncFilter* filter) +SHAMapAddNode SHAMap::addKnownNode (const SHAMapNodeID& node, Blob const& rawNode, SHAMapSyncFilter* filter) { ScopedWriteLockType sl (mLock); @@ -436,9 +439,10 @@ SHAMapAddNode SHAMap::addKnownNode (const SHAMapNode& node, Blob const& rawNode, SHAMapTreeNode::pointer parent = checkCacheNode(node.getParentNodeID()); SHAMapTreeNode* iNode = parent ? parent.get() : root.get (); - while (!iNode->isLeaf () && !iNode->isFullBelow () && (iNode->getDepth () < node.getDepth ())) + while (!iNode->isLeaf () && !iNode->isFullBelow () && + (iNode->getID().getDepth () < node.getDepth ())) { - int branch = iNode->selectBranch (node.getNodeID ()); + int branch = iNode->getID().selectBranch (node.getNodeID ()); assert (branch >= 0); if (iNode->isEmptyBranch (branch)) @@ -450,15 +454,17 @@ SHAMapAddNode SHAMap::addKnownNode (const SHAMapNode& node, Blob const& rawNode, if (m_fullBelowCache.touch_if_exists (iNode->getChildHash (branch))) return SHAMapAddNode::duplicate (); - SHAMapTreeNode *nextNode = getNodePointerNT (iNode->getChildNodeID (branch), iNode->getChildHash (branch), filter); + SHAMapTreeNode *nextNode = getNodePointerNT (iNode->getID().getChildNodeID (branch), + iNode->getChildHash (branch), filter); if (!nextNode) { - if (iNode->getDepth () != (node.getDepth () - 1)) + if (iNode->getID().getDepth () != (node.getDepth () - 1)) { // Either this node is broken or we didn't request it (yet) WriteLog (lsWARNING, SHAMap) << "unable to hook node " << node; - WriteLog (lsINFO, SHAMap) << " stuck at " << *iNode; - WriteLog (lsINFO, SHAMap) << "got depth=" << node.getDepth () << ", walked to= " << iNode->getDepth (); + WriteLog (lsINFO, SHAMap) << " stuck at " << iNode->getID(); + WriteLog (lsINFO, SHAMap) << "got depth=" << node.getDepth () + << ", walked to= " << iNode->getID().getDepth (); return SHAMapAddNode::invalid (); } @@ -511,8 +517,8 @@ bool SHAMap::deepCompare (SHAMap& other) SHAMapTreeNode::pointer otherNode; - if (node->isRoot ()) otherNode = other.root; - else otherNode = other.getNode (*node, node->getNodeHash (), false); + if (node->getID().isRoot ()) otherNode = other.root; + else otherNode = other.getNode (node->getID(), node->getNodeHash (), false); if (!otherNode) { @@ -521,7 +527,7 @@ bool SHAMap::deepCompare (SHAMap& other) } else if (otherNode->getNodeHash () != node->getNodeHash ()) { - WriteLog (lsWARNING, SHAMap) << "node hash mismatch " << *node; + WriteLog (lsWARNING, SHAMap) << "node hash mismatch " << node->getID(); return false; } @@ -551,7 +557,8 @@ bool SHAMap::deepCompare (SHAMap& other) } else { - SHAMapTreeNode::pointer next = getNode (node->getChildNodeID (i), node->getChildHash (i), false); + SHAMapTreeNode::pointer next = getNode (node->getID().getChildNodeID (i), + node->getChildHash (i), false); if (!next) { @@ -571,7 +578,7 @@ bool SHAMap::deepCompare (SHAMap& other) /** Does this map have this inner node? You must hold a read lock to call this function */ -bool SHAMap::hasInnerNode (const SHAMapNode& nodeID, uint256 const& nodeHash) +bool SHAMap::hasInnerNode (const SHAMapNodeID& nodeID, uint256 const& nodeHash) { SHAMapTreeNode::pointer ptr = mTNByID.retrieve (nodeID); if (ptr) @@ -579,14 +586,15 @@ bool SHAMap::hasInnerNode (const SHAMapNode& nodeID, uint256 const& nodeHash) SHAMapTreeNode* node = root.get (); - while (node->isInner () && (node->getDepth () < nodeID.getDepth ())) + while (node->isInner () && (node->getID().getDepth () < nodeID.getDepth ())) { - int branch = node->selectBranch (nodeID.getNodeID ()); + int branch = node->getID().selectBranch (nodeID.getNodeID ()); if (node->isEmptyBranch (branch)) return false; - node = getNodePointer (node->getChildNodeID (branch), node->getChildHash (branch)); + node = getNodePointer (node->getID().getChildNodeID (branch), + node->getChildHash (branch)); } return node->getNodeHash () == nodeHash; @@ -604,7 +612,7 @@ bool SHAMap::hasLeafNode (uint256 const& tag, uint256 const& nodeHash) do { - int branch = node->selectBranch (tag); + int branch = node->getID().selectBranch (tag); if (node->isEmptyBranch (branch)) // Dead end, node must not be here return false; @@ -614,7 +622,7 @@ bool SHAMap::hasLeafNode (uint256 const& tag, uint256 const& nodeHash) if (nextHash == nodeHash) // Matching leaf, no need to retrieve it return true; - node = getNodePointer (node->getChildNodeID (branch), nextHash); + node = getNodePointer (node->getID().getChildNodeID (branch), nextHash); } while (node->isInner()); @@ -692,13 +700,13 @@ void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max, if (!node->isEmptyBranch (i)) { uint256 const& childHash = node->getChildHash (i); - SHAMapNode childID = node->getChildNodeID (i); + SHAMapNodeID childID = node->getID().getChildNodeID (i); SHAMapTreeNode* next = getNodePointer (childID, childHash); if (next->isInner ()) { - if (!have || !have->hasInnerNode (*next, childHash)) + if (!have || !have->hasInnerNode (next->getID(), childHash)) stack.push (next); } else if (includeLeaves && (!have || !have->hasLeafNode (next->getTag(), childHash))) @@ -817,11 +825,11 @@ public: source.setImmutable (); - std::vector nodeIDs, gotNodeIDs; + std::vector nodeIDs, gotNodeIDs; std::list< Blob > gotNodes; std::vector hashes; - std::vector::iterator nodeIDIterator; + std::vector::iterator nodeIDIterator; std::list< Blob >::iterator rawNodeIterator; int passes = 0; @@ -829,7 +837,7 @@ public: destination.setSynching (); - unexpected (!source.getNodeFat (SHAMapNode (), nodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0), + unexpected (!source.getNodeFat (SHAMapNodeID (), nodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0), "GetNodeFat"); unexpected (gotNodes.size () < 1, "NodeSize"); diff --git a/src/ripple/module/app/shamap/SHAMapSyncFilter.h b/src/ripple/module/app/shamap/SHAMapSyncFilter.h index 99d92761bb..aac435bc3d 100644 --- a/src/ripple/module/app/shamap/SHAMapSyncFilter.h +++ b/src/ripple/module/app/shamap/SHAMapSyncFilter.h @@ -30,12 +30,12 @@ public: // Note that the nodeData is overwritten by this call virtual void gotNode (bool fromFilter, - SHAMapNode const& id, + SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType type) = 0; - virtual bool haveNode (SHAMapNode const& id, + virtual bool haveNode (SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData) = 0; }; diff --git a/src/ripple/module/app/shamap/SHAMapSyncFilters.cpp b/src/ripple/module/app/shamap/SHAMapSyncFilters.cpp index c5d4eae0b3..161b016912 100644 --- a/src/ripple/module/app/shamap/SHAMapSyncFilters.cpp +++ b/src/ripple/module/app/shamap/SHAMapSyncFilters.cpp @@ -26,7 +26,7 @@ ConsensusTransSetSF::ConsensusTransSetSF (NodeCache& nodeCache) { } -void ConsensusTransSetSF::gotNode (bool fromFilter, const SHAMapNode& id, uint256 const& nodeHash, +void ConsensusTransSetSF::gotNode (bool fromFilter, const SHAMapNodeID& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType type) { if (fromFilter) @@ -58,7 +58,7 @@ void ConsensusTransSetSF::gotNode (bool fromFilter, const SHAMapNode& id, uint25 } } -bool ConsensusTransSetSF::haveNode (const SHAMapNode& id, uint256 const& nodeHash, +bool ConsensusTransSetSF::haveNode (const SHAMapNodeID& id, uint256 const& nodeHash, Blob& nodeData) { if (m_nodeCache.retrieve (nodeHash, nodeData)) @@ -90,7 +90,7 @@ AccountStateSF::AccountStateSF (std::uint32_t ledgerSeq) } void AccountStateSF::gotNode (bool fromFilter, - SHAMapNode const& id, + SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType) @@ -98,7 +98,7 @@ void AccountStateSF::gotNode (bool fromFilter, getApp().getNodeStore ().store (hotACCOUNT_NODE, mLedgerSeq, std::move (nodeData), nodeHash); } -bool AccountStateSF::haveNode (SHAMapNode const& id, +bool AccountStateSF::haveNode (SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData) { @@ -113,7 +113,7 @@ TransactionStateSF::TransactionStateSF (std::uint32_t ledgerSeq) } void TransactionStateSF::gotNode (bool fromFilter, - SHAMapNode const& id, + SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType type) @@ -125,7 +125,7 @@ void TransactionStateSF::gotNode (bool fromFilter, nodeHash); } -bool TransactionStateSF::haveNode (SHAMapNode const& id, +bool TransactionStateSF::haveNode (SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData) { diff --git a/src/ripple/module/app/shamap/SHAMapSyncFilters.h b/src/ripple/module/app/shamap/SHAMapSyncFilters.h index 1fd6427a6d..8ac2a0f4ec 100644 --- a/src/ripple/module/app/shamap/SHAMapSyncFilters.h +++ b/src/ripple/module/app/shamap/SHAMapSyncFilters.h @@ -37,12 +37,12 @@ public: // Note that the nodeData is overwritten by this call void gotNode (bool fromFilter, - SHAMapNode const& id, + SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType); - bool haveNode (SHAMapNode const& id, + bool haveNode (SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData); @@ -59,12 +59,12 @@ public: // Note that the nodeData is overwritten by this call void gotNode (bool fromFilter, - SHAMapNode const& id, + SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType); - bool haveNode (SHAMapNode const& id, + bool haveNode (SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData); @@ -81,12 +81,12 @@ public: // Note that the nodeData is overwritten by this call void gotNode (bool fromFilter, - SHAMapNode const& id, + SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData, SHAMapTreeNode::TNType); - bool haveNode (SHAMapNode const& id, + bool haveNode (SHAMapNodeID const& id, uint256 const& nodeHash, Blob& nodeData); diff --git a/src/ripple/module/app/shamap/SHAMapTreeNode.cpp b/src/ripple/module/app/shamap/SHAMapTreeNode.cpp index c2eb289742..2ee16c3207 100644 --- a/src/ripple/module/app/shamap/SHAMapTreeNode.cpp +++ b/src/ripple/module/app/shamap/SHAMapTreeNode.cpp @@ -19,8 +19,8 @@ namespace ripple { -SHAMapTreeNode::SHAMapTreeNode (std::uint32_t seq, const SHAMapNode& nodeID) - : SHAMapNode (nodeID) +SHAMapTreeNode::SHAMapTreeNode (std::uint32_t seq, const SHAMapNodeID& nodeID) + : mID (nodeID) , mHash (std::uint64_t(0)) , mSeq (seq) , mAccessSeq (seq) @@ -30,8 +30,13 @@ SHAMapTreeNode::SHAMapTreeNode (std::uint32_t seq, const SHAMapNode& nodeID) { } -SHAMapTreeNode::SHAMapTreeNode (const SHAMapTreeNode& node, std::uint32_t seq) : SHAMapNode (node), - mHash (node.mHash), mSeq (seq), mType (node.mType), mIsBranch (node.mIsBranch), mFullBelow (false) +SHAMapTreeNode::SHAMapTreeNode (const SHAMapTreeNode& node, std::uint32_t seq) + : mID (node.getID()) + , mHash (node.mHash) + , mSeq (seq) + , mType (node.mType) + , mIsBranch (node.mIsBranch) + , mFullBelow (false) { if (node.mItem) mItem = node.mItem; @@ -39,17 +44,27 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapTreeNode& node, std::uint32_t seq) : memcpy (mHashes, node.mHashes, sizeof (mHashes)); } -SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& node, SHAMapItem::ref item, - TNType type, std::uint32_t seq) : - SHAMapNode (node), mItem (item), mSeq (seq), mType (type), mIsBranch (0), mFullBelow (false) +SHAMapTreeNode::SHAMapTreeNode (const SHAMapNodeID& id, SHAMapItem::ref item, + TNType type, std::uint32_t seq) + : mID (id) + , mItem (item) + , mSeq (seq) + , mType (type) + , mIsBranch (0) + , mFullBelow (false) { assert (item->peekData ().size () >= 12); updateHash (); } -SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, std::uint32_t seq, - SHANodeFormat format, uint256 const& hash, bool hashValid) : - SHAMapNode (id), mSeq (seq), mType (tnERROR), mIsBranch (0), mFullBelow (false) +SHAMapTreeNode::SHAMapTreeNode (const SHAMapNodeID& id, Blob const& rawNode, + std::uint32_t seq, SHANodeFormat format, + uint256 const& hash, bool hashValid) + : mID (id) + , mSeq (seq) + , mType (tnERROR) + , mIsBranch (0) + , mFullBelow (false) { if (format == snfWIRE) { @@ -144,7 +159,7 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, std:: { if (rawNode.size () < 4) { - WriteLog (lsINFO, SHAMapNode) << "size < 4"; + WriteLog (lsINFO, SHAMapNodeID) << "size < 4"; throw std::runtime_error ("invalid P node"); } @@ -173,7 +188,7 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, std:: if (u.isZero ()) { - WriteLog (lsINFO, SHAMapNode) << "invalid PLN node"; + WriteLog (lsINFO, SHAMapNodeID) << "invalid PLN node"; throw std::runtime_error ("invalid PLN node"); } @@ -209,7 +224,7 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, std:: } else { - WriteLog (lsINFO, SHAMapNode) << "Unknown node prefix " << std::hex << prefix << std::dec; + WriteLog (lsINFO, SHAMapNodeID) << "Unknown node prefix " << std::hex << prefix << std::dec; throw std::runtime_error ("invalid node prefix"); } } @@ -413,15 +428,15 @@ void SHAMapTreeNode::makeInner () void SHAMapTreeNode::dump () { - WriteLog (lsDEBUG, SHAMapNode) << "SHAMapTreeNode(" << getNodeID () << ")"; + WriteLog (lsDEBUG, SHAMapNodeID) << "SHAMapTreeNode(" << mID.getNodeID () << ")"; } std::string SHAMapTreeNode::getString () const { std::string ret = "NodeID("; - ret += beast::lexicalCastThrow (getDepth ()); + ret += beast::lexicalCastThrow (mID.getDepth ()); ret += ","; - ret += to_string (getNodeID ()); + ret += to_string (mID.getNodeID ()); ret += ")"; if (isInner ()) diff --git a/src/ripple/module/app/shamap/SHAMapTreeNode.h b/src/ripple/module/app/shamap/SHAMapTreeNode.h index bb60502461..5933e60e35 100644 --- a/src/ripple/module/app/shamap/SHAMapTreeNode.h +++ b/src/ripple/module/app/shamap/SHAMapTreeNode.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SHAMAPTREENODE_H #define RIPPLE_SHAMAPTREENODE_H +#include + namespace ripple { class SHAMap; @@ -32,8 +34,7 @@ enum SHANodeFormat }; class SHAMapTreeNode - : public SHAMapNode - , public CountedObject + : public CountedObject { public: static char const* getCountedObjectName () { return "SHAMapTreeNode"; } @@ -51,13 +52,13 @@ public: }; public: - SHAMapTreeNode (std::uint32_t seq, const SHAMapNode & nodeID); // empty node + SHAMapTreeNode (std::uint32_t seq, const SHAMapNodeID & nodeID); // empty node SHAMapTreeNode (const SHAMapTreeNode & node, std::uint32_t seq); // copy node from older tree - SHAMapTreeNode (const SHAMapNode & nodeID, SHAMapItem::ref item, TNType type, + SHAMapTreeNode (const SHAMapNodeID & nodeID, SHAMapItem::ref item, TNType type, std::uint32_t seq); // raw node functions - SHAMapTreeNode (const SHAMapNode & id, Blob const & data, std::uint32_t seq, + SHAMapTreeNode (const SHAMapNodeID & id, Blob const & data, std::uint32_t seq, SHANodeFormat format, uint256 const & hash, bool hashValid); void addRaw (Serializer&, SHANodeFormat format); @@ -102,7 +103,7 @@ public: bool isInBounds () const { // Nodes at depth 64 must be leaves - return (!isInner() || (getDepth() < 64)); + return (!isInner() || (mID.getDepth() < 64)); } bool isValid () const { @@ -172,6 +173,9 @@ public: virtual void dump (); virtual std::string getString () const; + SHAMapNodeID const& getID() const {return mID;} + void setID(SHAMapNodeID const& id) {mID = id;} + private: // VFALCO TODO derive from Uncopyable SHAMapTreeNode (const SHAMapTreeNode&); // no implementation @@ -180,6 +184,7 @@ private: // VFALCO TODO remove the use of friend friend class SHAMap; + SHAMapNodeID mID; uint256 mHash; uint256 mHashes[16]; SHAMapItem::pointer mItem; diff --git a/src/ripple/module/app/tx/TransactionAcquire.cpp b/src/ripple/module/app/tx/TransactionAcquire.cpp index 8ee9d7afec..9944f96061 100644 --- a/src/ripple/module/app/tx/TransactionAcquire.cpp +++ b/src/ripple/module/app/tx/TransactionAcquire.cpp @@ -157,7 +157,7 @@ void TransactionAcquire::trigger (Peer::ptr const& peer) if (getTimeouts () != 0) tmGL.set_querytype (protocol::qtINDIRECT); - * (tmGL.add_nodeids ()) = SHAMapNode ().getRawString (); + * (tmGL.add_nodeids ()) = SHAMapNodeID ().getRawString (); sendRequest (tmGL, peer); } else if (!mMap->isValid ()) @@ -167,7 +167,7 @@ void TransactionAcquire::trigger (Peer::ptr const& peer) } else { - std::vector nodeIDs; + std::vector nodeIDs; std::vector nodeHashes; // VFALCO TODO Use a dependency injection on the temp node cache ConsensusTransSetSF sf (getApp().getTempNodeCache ()); @@ -191,15 +191,15 @@ void TransactionAcquire::trigger (Peer::ptr const& peer) if (getTimeouts () != 0) tmGL.set_querytype (protocol::qtINDIRECT); - BOOST_FOREACH (SHAMapNode & it, nodeIDs) + for (SHAMapNodeID& it : nodeIDs) { - * (tmGL.add_nodeids ()) = it.getRawString (); + *tmGL.add_nodeids () = it.getRawString (); } sendRequest (tmGL, peer); } } -SHAMapAddNode TransactionAcquire::takeNodes (const std::list& nodeIDs, +SHAMapAddNode TransactionAcquire::takeNodes (const std::list& nodeIDs, const std::list< Blob >& data, Peer::ptr const& peer) { if (mComplete) @@ -219,7 +219,7 @@ SHAMapAddNode TransactionAcquire::takeNodes (const std::list& nodeID if (nodeIDs.empty ()) return SHAMapAddNode::invalid (); - std::list::const_iterator nodeIDit = nodeIDs.begin (); + std::list::const_iterator nodeIDit = nodeIDs.begin (); std::list< Blob >::const_iterator nodeDatait = data.begin (); ConsensusTransSetSF sf (getApp().getTempNodeCache ()); diff --git a/src/ripple/module/app/tx/TransactionAcquire.h b/src/ripple/module/app/tx/TransactionAcquire.h index 0bcbd2d4ed..3a015587e5 100644 --- a/src/ripple/module/app/tx/TransactionAcquire.h +++ b/src/ripple/module/app/tx/TransactionAcquire.h @@ -43,7 +43,7 @@ public: return mMap; } - SHAMapAddNode takeNodes (const std::list& IDs, + SHAMapAddNode takeNodes (const std::list& IDs, const std::list< Blob >& data, Peer::ptr const&); private: diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 0334ddbe20..58bf2e27db 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -39,7 +39,7 @@ static void peerTXData (Job&, protocol::TMLedgerData& packet = *pPacket; - std::list nodeIDs; + std::list nodeIDs; std::list< Blob > nodeData; for (int i = 0; i < packet.nodes ().size (); ++i) { @@ -52,7 +52,8 @@ static void peerTXData (Job&, return; } - nodeIDs.push_back (SHAMapNode (node.nodeid ().data (), node.nodeid ().size ())); + nodeIDs.push_back (SHAMapNodeID {node.nodeid ().data (), + static_cast(node.nodeid ().size ())}); nodeData.push_back (Blob (node.nodedata ().begin (), node.nodedata ().end ())); } @@ -338,7 +339,7 @@ PeerImp::getLedger (protocol::TMGetLedger& packet) for (int i = 0; i < packet.nodeids ().size (); ++i) { - SHAMapNode mn (packet.nodeids (i).data (), packet.nodeids (i).size ()); + SHAMapNodeID mn (packet.nodeids (i).data (), packet.nodeids (i).size ()); if (!mn.isValid ()) { @@ -347,7 +348,7 @@ PeerImp::getLedger (protocol::TMGetLedger& packet) return; } - std::vector nodeIDs; + std::vector nodeIDs; std::list< Blob > rawNodes; try @@ -356,7 +357,7 @@ PeerImp::getLedger (protocol::TMGetLedger& packet) { assert (nodeIDs.size () == rawNodes.size ()); m_journal.trace << "getNodeFat got " << rawNodes.size () << " nodes"; - std::vector::iterator nodeIDIterator; + std::vector::iterator nodeIDIterator; std::list< Blob >::iterator rawNodeIterator; for (nodeIDIterator = nodeIDs.begin (), rawNodeIterator = rawNodes.begin (); diff --git a/src/ripple/unity/app.h b/src/ripple/unity/app.h index 22a0b6e197..4d60c83962 100644 --- a/src/ripple/unity/app.h +++ b/src/ripple/unity/app.h @@ -65,7 +65,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/ripple/unity/app3.cpp b/src/ripple/unity/app3.cpp index 0d654d7190..5d9a369f79 100644 --- a/src/ripple/unity/app3.cpp +++ b/src/ripple/unity/app3.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include