mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 22:15:52 +00:00
SHAMap refactoring:
* Rename SHAMapNode to SHAMapNodeID. * Cleanups
This commit is contained in:
committed by
Nik Bougalis
parent
23dc08c925
commit
9dc32cb791
@@ -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<SHAMapNode>& nodeIDs
|
||||
, uint256 const& setHash, const std::list<SHAMapNodeID>& nodeIDs
|
||||
, const std::list< Blob >& nodeData)
|
||||
{
|
||||
auto acq (mAcquiring.find (setHash));
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
|
||||
virtual SHAMapAddNode peerGaveNodes (Peer::ptr const& peer,
|
||||
uint256 const & setHash,
|
||||
const std::list<SHAMapNode>& nodeIDs,
|
||||
const std::list<SHAMapNodeID>& nodeIDs,
|
||||
const std::list< Blob >& nodeData) = 0;
|
||||
|
||||
virtual bool isOurPubKey (const RippleAddress & k) = 0;
|
||||
|
||||
@@ -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<SHAMapNode> nodeIDs;
|
||||
std::vector<SHAMapNodeID> nodeIDs;
|
||||
std::vector<uint256> 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<SHAMapNode> nodeIDs;
|
||||
std::vector<SHAMapNodeID> nodeIDs;
|
||||
std::vector<uint256> 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<SHAMapNode>& nodeIDs,
|
||||
std::vector<uint256>& nodeHashes, std::set<SHAMapNode>& recentNodes,
|
||||
void InboundLedger::filterNodes (std::vector<SHAMapNodeID>& nodeIDs,
|
||||
std::vector<uint256>& nodeHashes, std::set<SHAMapNodeID>& 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<SHAMapNode>& 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<SHAMapNode>& 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<SHAMapNode>& nodeIDs,
|
||||
bool InboundLedger::takeTxNode (const std::list<SHAMapNodeID>& nodeIDs,
|
||||
const std::list< Blob >& data, SHAMapAddNode& san)
|
||||
{
|
||||
if (!mHaveBase)
|
||||
@@ -831,7 +831,7 @@ bool InboundLedger::takeTxNode (const std::list<SHAMapNode>& nodeIDs,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::list<SHAMapNode>::const_iterator nodeIDit = nodeIDs.begin ();
|
||||
std::list<SHAMapNodeID>::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<SHAMapNode>& nodeIDs,
|
||||
/** Process AS data received from a peer
|
||||
Call with a lock
|
||||
*/
|
||||
bool InboundLedger::takeAsNode (const std::list<SHAMapNode>& nodeIDs,
|
||||
bool InboundLedger::takeAsNode (const std::list<SHAMapNodeID>& 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<SHAMapNode>& nodeIDs,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::list<SHAMapNode>::const_iterator nodeIDit = nodeIDs.begin ();
|
||||
std::list<SHAMapNodeID>::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> peer,
|
||||
if ((packet.type () == protocol::liTX_NODE) || (
|
||||
packet.type () == protocol::liAS_NODE))
|
||||
{
|
||||
std::list<SHAMapNode> nodeIDs;
|
||||
std::list<SHAMapNodeID> nodeIDs;
|
||||
std::list< Blob > nodeData;
|
||||
|
||||
if (packet.nodes ().size () == 0)
|
||||
@@ -1140,7 +1140,7 @@ int InboundLedger::processData (std::shared_ptr<Peer> 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 ()));
|
||||
|
||||
@@ -95,8 +95,8 @@ public:
|
||||
std::vector<neededHash_t> getNeededHashes ();
|
||||
|
||||
// VFALCO TODO Replace uint256 with something semanticallyh meaningful
|
||||
void filterNodes (std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& nodeHashes,
|
||||
std::set<SHAMapNode>& recentNodes, int max, bool aggressive);
|
||||
void filterNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<uint256>& nodeHashes,
|
||||
std::set<SHAMapNodeID>& recentNodes, int max, bool aggressive);
|
||||
|
||||
Json::Value getJson (int);
|
||||
void runData ();
|
||||
@@ -116,7 +116,7 @@ private:
|
||||
int processData (std::shared_ptr<Peer> peer, protocol::TMLedgerData& data);
|
||||
|
||||
bool takeBase (const std::string& data);
|
||||
bool takeTxNode (const std::list<SHAMapNode>& IDs, const std::list<Blob >& data,
|
||||
bool takeTxNode (const std::list<SHAMapNodeID>& IDs, const std::list<Blob >& 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<SHAMapNode>& IDs, const std::list<Blob >& data,
|
||||
bool takeAsNode (const std::list<SHAMapNodeID>& IDs, const std::list<Blob >& data,
|
||||
SHAMapAddNode&);
|
||||
bool takeAsRootNode (Blob const& data, SHAMapAddNode&);
|
||||
|
||||
@@ -139,8 +139,8 @@ private:
|
||||
std::uint32_t mSeq;
|
||||
fcReason mReason;
|
||||
|
||||
std::set <SHAMapNode> mRecentTXNodes;
|
||||
std::set <SHAMapNode> mRecentASNodes;
|
||||
std::set <SHAMapNodeID> mRecentTXNodes;
|
||||
std::set <SHAMapNodeID> mRecentASNodes;
|
||||
|
||||
|
||||
// Data we have received from peers
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ public:
|
||||
void processTrustedProposal (LedgerProposal::pointer proposal, std::shared_ptr<protocol::TMProposeSet> set,
|
||||
RippleAddress nodePublic, uint256 checkLedger, bool sigGood);
|
||||
SHAMapAddNode gotTXData (const std::shared_ptr<Peer>& peer, uint256 const& hash,
|
||||
const std::list<SHAMapNode>& nodeIDs, const std::list< Blob >& nodeData);
|
||||
const std::list<SHAMapNodeID>& 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>& peer, uint256 const& hash,
|
||||
const std::list<SHAMapNode>& nodeIDs, const std::list< Blob >& nodeData)
|
||||
const std::list<SHAMapNodeID>& nodeIDs, const std::list< Blob >& nodeData)
|
||||
{
|
||||
|
||||
if (!mConsensus)
|
||||
|
||||
@@ -208,7 +208,7 @@ public:
|
||||
uint256 checkLedger, bool sigGood) = 0;
|
||||
|
||||
virtual SHAMapAddNode gotTXData (const std::shared_ptr<Peer>& peer,
|
||||
uint256 const& hash, const std::list<SHAMapNode>& nodeIDs,
|
||||
uint256 const& hash, const std::list<SHAMapNodeID>& nodeIDs,
|
||||
const std::list< Blob >& nodeData) = 0;
|
||||
|
||||
virtual bool recvValidation (SerializedValidation::ref val,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<SHAMapTreeNode> (mSeq, SHAMapNode (0, uint256 ()));
|
||||
root = std::make_shared<SHAMapTreeNode> (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<SHAMapTreeNode> (mSeq, SHAMapNode (0, uint256 ()));
|
||||
root = std::make_shared<SHAMapTreeNode> (mSeq, SHAMapNodeID (0, uint256 ()));
|
||||
root->makeInner ();
|
||||
mTNByID.replace(*root, root);
|
||||
mTNByID.replace(root->getID(), root);
|
||||
}
|
||||
|
||||
TaggedCache <uint256, SHAMapTreeNode>
|
||||
@@ -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<SHAMapTreeNode> (*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<SHAMapTreeNode::pointer> 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<SHAMapTreeNode::pointer> 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<SHAMapTreeNode::pointer>& 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<SHAMapTreeNode::pointer>& 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<SHAMapTreeNode> (*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<SHAMapTreeNode> (node->getChildNodeID (branch), item, type, mSeq);
|
||||
std::make_shared<SHAMapTreeNode> (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<SHAMapTreeNode> (mSeq, node->getChildNodeID (b1));
|
||||
std::make_shared<SHAMapTreeNode> (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<SHAMapTreeNode> (node->getChildNodeID (b1), item, type, mSeq);
|
||||
std::make_shared<SHAMapTreeNode> (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<SHAMapTreeNode> (node->getChildNodeID (b2), otherItem, type, mSeq);
|
||||
newNode = std::make_shared<SHAMapTreeNode> (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 <SHAMapTreeNode> (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<SHAMapTreeNode> (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<SHAMapTreeNode> (SHAMapNode (), nodeData,
|
||||
root = std::make_shared<SHAMapTreeNode> (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 <std::string> (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 <SHAMapTreeNode> (*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::DirtySet> 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<SHAMapNode, SHAMapTreeNode::pointer, SHAMapNode_hash>::iterator it = mTNByID.peekMap().begin ();
|
||||
for (ripple::unordered_map<SHAMapNodeID, SHAMapTreeNode::pointer, SHAMapNode_hash>::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 <SHAMapTreeNode> (*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 <SHAMapTreeNode> (*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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash <ripple::SHAMapNode>
|
||||
struct hash <ripple::SHAMapNodeID>
|
||||
{
|
||||
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 <ripple::SHAMapNode>
|
||||
namespace boost {
|
||||
|
||||
template <>
|
||||
struct hash <ripple::SHAMapNode> : std::hash <ripple::SHAMapNode>
|
||||
struct hash <ripple::SHAMapNodeID> : std::hash <ripple::SHAMapNodeID>
|
||||
{
|
||||
};
|
||||
|
||||
@@ -115,8 +115,8 @@ public:
|
||||
typedef std::pair<SHAMapItem::pointer, SHAMapItem::pointer> DeltaItem;
|
||||
typedef std::pair<SHAMapItem::ref, SHAMapItem::ref> DeltaRef;
|
||||
typedef std::map<uint256, DeltaItem> Delta;
|
||||
typedef ripple::unordered_map<SHAMapNode, SHAMapTreeNode::pointer, SHAMapNode_hash> NodeMap;
|
||||
typedef std::unordered_set<SHAMapNode, SHAMapNode_hash> DirtySet;
|
||||
typedef ripple::unordered_map<SHAMapNodeID, SHAMapTreeNode::pointer, SHAMapNode_hash> NodeMap;
|
||||
typedef std::unordered_set<SHAMapNodeID, SHAMapNode_hash> DirtySet;
|
||||
|
||||
typedef boost::shared_mutex LockType;
|
||||
typedef boost::shared_lock<LockType> 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<void (SHAMapItem::ref)>);
|
||||
|
||||
// comparison/sync functions
|
||||
void getMissingNodes (std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max,
|
||||
void getMissingNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<uint256>& hashes, int max,
|
||||
SHAMapSyncFilter * filter);
|
||||
bool getNodeFat (const SHAMapNode & node, std::vector<SHAMapNode>& nodeIDs,
|
||||
bool getNodeFat (SHAMapNodeID const& node, std::vector<SHAMapNodeID>& nodeIDs,
|
||||
std::list<Blob >& rawNode, bool fatRoot, bool fatLeaves);
|
||||
bool getRootNode (Serializer & s, SHANodeFormat format);
|
||||
std::vector<uint256> 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<uint256, SHAMapNode> TNIndex;
|
||||
typedef std::pair<uint256, SHAMapNodeID> TNIndex;
|
||||
|
||||
private:
|
||||
static TaggedCache <uint256, SHAMapTreeNode> treeNodeCache;
|
||||
@@ -311,28 +311,28 @@ private:
|
||||
std::stack<SHAMapTreeNode::pointer> 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<DirtySet> mDirtyNodes;
|
||||
SHAMapTreeNode::pointer root;
|
||||
SHAMapState mState;
|
||||
|
||||
@@ -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<SHAMapMissingNode>& 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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -17,26 +17,34 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <beast/module/core/text/LexicalCast.h>
|
||||
#include <ripple/module/app/shamap/SHAMapNodeID.h>
|
||||
#include <boost/format.hpp>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
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<const unsigned char*> (ptr) + 32);
|
||||
std::memcpy (mNodeID.begin (), ptr, 32);
|
||||
mDepth = * (static_cast<unsigned char const*> (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
|
||||
@@ -17,43 +17,64 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_SHAMAPNODE_H
|
||||
#define RIPPLE_SHAMAPNODE_H
|
||||
#ifndef RIPPLE_SHAMAPNODEID_H
|
||||
#define RIPPLE_SHAMAPNODEID_H
|
||||
|
||||
#include <functional>
|
||||
#include <ripple/types/api/base_uint.h>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
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 <ripple::SHAMapNode>
|
||||
struct hash <ripple::SHAMapNodeID>
|
||||
{
|
||||
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 <ripple::SHAMapNode>
|
||||
namespace boost {
|
||||
|
||||
template <>
|
||||
struct hash <ripple::SHAMapNode> : std::hash <ripple::SHAMapNode>
|
||||
struct hash <ripple::SHAMapNodeID> : std::hash <ripple::SHAMapNodeID>
|
||||
{
|
||||
};
|
||||
|
||||
@@ -62,11 +62,12 @@ void SHAMap::visitLeavesInternal (std::function<void (SHAMapItem::ref item)>& 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<void (SHAMapItem::ref item)>& 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<void (SHAMapItem::ref item)>& 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<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max,
|
||||
void SHAMap::getMissingNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<uint256>& hashes, int max,
|
||||
SHAMapSyncFilter* filter)
|
||||
{
|
||||
ScopedReadLockType sl (mLock);
|
||||
@@ -145,7 +146,7 @@ void SHAMap::getMissingNodes (std::vector<SHAMapNode>& nodeIDs, std::vector<uint
|
||||
|
||||
while (1)
|
||||
{
|
||||
std::vector <std::pair <SHAMapNode, uint256>> deferredReads;
|
||||
std::vector <std::pair <SHAMapNodeID, uint256>> deferredReads;
|
||||
deferredReads.reserve (maxDefer + 16);
|
||||
|
||||
std::stack <GMNEntry> stack;
|
||||
@@ -168,7 +169,7 @@ void SHAMap::getMissingNodes (std::vector<SHAMapNode>& nodeIDs, std::vector<uint
|
||||
|
||||
if (! m_fullBelowCache.touch_if_exists (childHash))
|
||||
{
|
||||
SHAMapNode childID = node->getChildNodeID (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<SHAMapNode>& nodeIDs, std::vector<uint
|
||||
{
|
||||
auto const& nodeID = node.first;
|
||||
auto const& nodeHash = node.second;
|
||||
SHAMapNode *nodePtr = getNodePointerNT (nodeID, nodeHash, filter);
|
||||
SHAMapTreeNode* nodePtr = getNodePointerNT (nodeID, nodeHash, filter);
|
||||
if (!nodePtr && missingHashes.insert (nodeHash).second)
|
||||
{
|
||||
nodeIDs.push_back (nodeID);
|
||||
@@ -264,14 +265,14 @@ std::vector<uint256> SHAMap::getNeededHashes (int max, SHAMapSyncFilter* filter)
|
||||
std::vector<uint256> nodeHashes;
|
||||
nodeHashes.reserve(max);
|
||||
|
||||
std::vector<SHAMapNode> nodeIDs;
|
||||
std::vector<SHAMapNodeID> nodeIDs;
|
||||
nodeIDs.reserve(max);
|
||||
|
||||
getMissingNodes(nodeIDs, nodeHashes, max, filter);
|
||||
return nodeHashes;
|
||||
}
|
||||
|
||||
bool SHAMap::getNodeFat (const SHAMapNode& wanted, std::vector<SHAMapNode>& nodeIDs,
|
||||
bool SHAMap::getNodeFat (const SHAMapNodeID& wanted, std::vector<SHAMapNodeID>& nodeIDs,
|
||||
std::list<Blob >& 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<SHAMapNode>& 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<SHAMapNode>& 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<SHAMapTreeNode> (SHAMapNode (), rootNode, mSeq - 1, format, uZero, false);
|
||||
std::make_shared<SHAMapTreeNode> (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<SHAMapTreeNode> (SHAMapNode (), rootNode, mSeq - 1, format, uZero, false);
|
||||
std::make_shared<SHAMapTreeNode> (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<SHAMapNode> nodeIDs, gotNodeIDs;
|
||||
std::vector<SHAMapNodeID> nodeIDs, gotNodeIDs;
|
||||
std::list< Blob > gotNodes;
|
||||
std::vector<uint256> hashes;
|
||||
|
||||
std::vector<SHAMapNode>::iterator nodeIDIterator;
|
||||
std::vector<SHAMapNodeID>::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");
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 <std::string> (getDepth ());
|
||||
ret += beast::lexicalCastThrow <std::string> (mID.getDepth ());
|
||||
ret += ",";
|
||||
ret += to_string (getNodeID ());
|
||||
ret += to_string (mID.getNodeID ());
|
||||
ret += ")";
|
||||
|
||||
if (isInner ())
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef RIPPLE_SHAMAPTREENODE_H
|
||||
#define RIPPLE_SHAMAPTREENODE_H
|
||||
|
||||
#include <ripple/module/app/shamap/SHAMapNodeID.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class SHAMap;
|
||||
@@ -32,8 +34,7 @@ enum SHANodeFormat
|
||||
};
|
||||
|
||||
class SHAMapTreeNode
|
||||
: public SHAMapNode
|
||||
, public CountedObject <SHAMapTreeNode>
|
||||
: public CountedObject <SHAMapTreeNode>
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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<SHAMapNode> nodeIDs;
|
||||
std::vector<SHAMapNodeID> nodeIDs;
|
||||
std::vector<uint256> 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<SHAMapNode>& nodeIDs,
|
||||
SHAMapAddNode TransactionAcquire::takeNodes (const std::list<SHAMapNodeID>& nodeIDs,
|
||||
const std::list< Blob >& data, Peer::ptr const& peer)
|
||||
{
|
||||
if (mComplete)
|
||||
@@ -219,7 +219,7 @@ SHAMapAddNode TransactionAcquire::takeNodes (const std::list<SHAMapNode>& nodeID
|
||||
if (nodeIDs.empty ())
|
||||
return SHAMapAddNode::invalid ();
|
||||
|
||||
std::list<SHAMapNode>::const_iterator nodeIDit = nodeIDs.begin ();
|
||||
std::list<SHAMapNodeID>::const_iterator nodeIDit = nodeIDs.begin ();
|
||||
std::list< Blob >::const_iterator nodeDatait = data.begin ();
|
||||
ConsensusTransSetSF sf (getApp().getTempNodeCache ());
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
return mMap;
|
||||
}
|
||||
|
||||
SHAMapAddNode takeNodes (const std::list<SHAMapNode>& IDs,
|
||||
SHAMapAddNode takeNodes (const std::list<SHAMapNodeID>& IDs,
|
||||
const std::list< Blob >& data, Peer::ptr const&);
|
||||
|
||||
private:
|
||||
|
||||
@@ -39,7 +39,7 @@ static void peerTXData (Job&,
|
||||
|
||||
protocol::TMLedgerData& packet = *pPacket;
|
||||
|
||||
std::list<SHAMapNode> nodeIDs;
|
||||
std::list<SHAMapNodeID> 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<int>(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<SHAMapNode> nodeIDs;
|
||||
std::vector<SHAMapNodeID> 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<SHAMapNode>::iterator nodeIDIterator;
|
||||
std::vector<SHAMapNodeID>::iterator nodeIDIterator;
|
||||
std::list< Blob >::iterator rawNodeIterator;
|
||||
|
||||
for (nodeIDIterator = nodeIDs.begin (), rawNodeIterator = rawNodes.begin ();
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
#include <ripple/module/app/data/SqliteDatabase.h>
|
||||
#include <ripple/module/app/data/DBInit.h>
|
||||
#include <ripple/module/app/shamap/SHAMapItem.h>
|
||||
#include <ripple/module/app/shamap/SHAMapNode.h>
|
||||
#include <ripple/module/app/shamap/SHAMapNodeID.h>
|
||||
#include <ripple/module/app/shamap/SHAMapTreeNode.h>
|
||||
#include <ripple/module/app/shamap/SHAMapMissingNode.h>
|
||||
#include <ripple/module/app/shamap/SHAMapSyncFilter.h>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <ripple/module/app/ledger/Ledger.cpp>
|
||||
#include <ripple/module/app/shamap/SHAMapDelta.cpp>
|
||||
#include <ripple/module/app/shamap/SHAMapNode.cpp>
|
||||
#include <ripple/module/app/shamap/SHAMapNodeID.cpp>
|
||||
#include <ripple/module/app/shamap/SHAMapTreeNode.cpp>
|
||||
#include <ripple/module/app/misc/AccountItems.cpp>
|
||||
#include <ripple/module/app/misc/AccountState.cpp>
|
||||
|
||||
Reference in New Issue
Block a user