Skip to content

Commit

Permalink
Merge pull request bitcoin#511 from ptschip/release_482
Browse files Browse the repository at this point in the history
[Release] backport of PR 482
  • Loading branch information
gandrewstone committed May 3, 2017
2 parents 4ce66a3 + d6699ae commit 1344353
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/thinblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ bool CThinBlock::process(CNode *pfrom, int nSizeThinBlock, string strCommand)
pfrom->thinBlock.vtx.size(), mapMissingTx.size());
} // end lock cs_orphancache, mempool.cs, cs_xval

// Clear out data we no longer need before processing block.
pfrom->thinBlockHashes.clear();

if (pfrom->thinBlockWaitingForTxns == 0)
{
// We have all the transactions now that are in this block: try to reassemble and process.
Expand All @@ -148,7 +151,7 @@ bool CThinBlock::process(CNode *pfrom, int nSizeThinBlock, string strCommand)
// finish reassembling the block, we need to re-request the full regular block:
vector<CInv> vGetData;
vGetData.push_back(CInv(MSG_BLOCK, header.GetHash()));
pfrom->PushMessage("getdata", vGetData);
pfrom->PushMessage(NetMsgType::GETDATA, vGetData);
setPreVerifiedTxHash.clear(); // Xpress Validation - clear the set since we do not do XVal on regular blocks
LogPrint("thin", "Missing %d Thinblock transactions, re-requesting a regular block\n",
pfrom->thinBlockWaitingForTxns);
Expand Down Expand Up @@ -359,20 +362,29 @@ bool CXThinBlock::process(CNode* pfrom, int nSizeThinBlock, string strCommand)
}
} // End locking mempool.cs and cs_xval

// Clear out data we no longer need before processing block or making re-requests.
pfrom->xThinBlockHashes.clear();
mapPartialTxHash.clear();

// This must be done outside of the above section or a deadlock may occur.
if (!fMerkleRootCorrect)
{
LOCK(cs_main);
Misbehaving(pfrom->GetId(), 100);
return error("xthinblock merkelroot does not match computed merkleroot, peer=%d", pfrom->GetId());
vector<CInv> vGetData;
vGetData.push_back(CInv(MSG_THINBLOCK, header.GetHash()));
pfrom->PushMessage(NetMsgType::GETDATA, vGetData);
LogPrintf("xthinblock merkelroot does not match computed merkleroot - requesting full thinblock, peer=%d",
pfrom->GetId());
return true;
}

// There is a remote possiblity of a Tx hash collision therefore if it occurs we re-request a normal
// thinblock which has the full Tx hash data rather than just the truncated hash.
if (collision) {
// This must be done outside of the mempool.cs lock or the deadlock
// detection with pfrom->cs_vSend will be triggered.
vector<CInv> vGetData;
vGetData.push_back(CInv(MSG_THINBLOCK, header.GetHash()));
pfrom->PushMessage("getdata", vGetData); // This must be done outside of the mempool.cs lock or the deadlock detection with pfrom->cs_vSend will be triggered.
vGetData.push_back(CInv(MSG_THINBLOCK, header.GetHash()));
pfrom->PushMessage(NetMsgType::GETDATA, vGetData);
LogPrintf("TX HASH COLLISION for xthinblock: re-requesting a thinblock\n");
return true;
}
Expand Down

0 comments on commit 1344353

Please sign in to comment.