At level 64, only leaves are allowed

This commit is contained in:
David Schwartz
2014-05-09 12:05:40 -07:00
committed by Vinnie Falco
parent 52f45669d1
commit 0075f36bbc
4 changed files with 27 additions and 2 deletions

View File

@@ -539,7 +539,11 @@ void InboundLedger::trigger (Peer::ptr const& peer)
{
assert (mLedger);
if (mLedger->peekAccountStateMap ()->getHash ().isZero ())
if (!mLedger->peekAccountStateMap ()->isValid ())
{
mFailed = true;
}
else if (mLedger->peekAccountStateMap ()->getHash ().isZero ())
{
// we need the root node
tmGL.set_itype (protocol::liAS_NODE);
@@ -614,7 +618,11 @@ void InboundLedger::trigger (Peer::ptr const& peer)
{
assert (mLedger);
if (mLedger->peekTransactionMap ()->getHash ().isZero ())
if (!mLedger->peekTransactionMap ()->isValid ())
{
mFailed = true;
}
else if (mLedger->peekTransactionMap ()->getHash ().isZero ())
{
// we need the root node
tmGL.set_itype (protocol::liTX_NODE);

View File

@@ -472,6 +472,13 @@ SHAMapAddNode SHAMap::addKnownNode (const SHAMapNode& node, Blob const& rawNode,
canonicalize (iNode->getChildHash (branch), newNode);
if (!iNode->isInBounds ())
{
// Map is provably invalid
mState = smsInvalid;
return SHAMapAddNode::useful ();
}
if (mTNByID.canonicalize(node, &newNode) && filter)
{
Serializer s;

View File

@@ -99,6 +99,11 @@ public:
{
return mType == tnINNER;
}
bool isInBounds () const
{
// Nodes at depth 64 must be leaves
return (!isInner() || (getDepth() < 64));
}
bool isValid () const
{
return mType != tnERROR;

View File

@@ -163,6 +163,11 @@ void TransactionAcquire::trigger (Peer::ptr const& peer)
* (tmGL.add_nodeids ()) = SHAMapNode ().getRawString ();
sendRequest (tmGL, peer);
}
else if (!mMap->isValid ())
{
mFailed = true;
done ();
}
else
{
std::vector<SHAMapNode> nodeIDs;