another try to fix the infinite recursion triggered when the new (longer) chain

contains an invalid transaction (due to older, buggy, twisterd or attacker).
i'm not entirely convinced that original bitcoin couldn't be attacked the same
way (51% is still needed, but crashing the client is pretty bad).
This commit is contained in:
Miguel Freitas 2014-01-19 00:53:15 -02:00
parent 19ff320d24
commit 6416fa5d58

View File

@ -1299,9 +1299,22 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
// List of what to connect (typically only pindexNew)
vector<CBlockIndex*> vConnect;
for (CBlockIndex* pindex = pindexNew; pindex != pfork; pindex = pindex->pprev)
for (CBlockIndex* pindex = pindexNew; pindex != pfork; pindex = pindex->pprev) {
vConnect.push_back(pindex);
if( pindex->nStatus & BLOCK_FAILED_MASK ) {
BOOST_FOREACH(CBlockIndex *pindex, vConnect) {
pindex->nStatus |= BLOCK_FAILED_CHILD;
setBlockIndexValid.erase(pindex);
pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex));
}
vConnect.clear();
}
}
reverse(vConnect.begin(), vConnect.end());
if (vConnect.size() < vDisconnect.size()) {
return error("SetBestChain() : Tried to connect to a shorter chain (invalid blocks)");
}
if (vDisconnect.size() > 0) {
printf("REORGANIZE: Disconnect %"PRIszu" blocks; %s..\n", vDisconnect.size(), pfork->GetBlockHash().ToString().c_str());