Use ProcessNewBlockHeaders in CMPCTBLOCK processing

This commit is contained in:
Matt Corallo 2016-11-03 17:01:39 -04:00
parent a8b936df20
commit 58a215ce8c

View file

@ -5768,6 +5768,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CBlockHeaderAndShortTxIDs cmpctblock; CBlockHeaderAndShortTxIDs cmpctblock;
vRecv >> cmpctblock; vRecv >> cmpctblock;
{
LOCK(cs_main); LOCK(cs_main);
if (mapBlockIndex.find(cmpctblock.header.hashPrevBlock) == mapBlockIndex.end()) { if (mapBlockIndex.find(cmpctblock.header.hashPrevBlock) == mapBlockIndex.end()) {
@ -5776,19 +5777,23 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
connman.PushMessage(pfrom, NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), uint256()); connman.PushMessage(pfrom, NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), uint256());
return true; return true;
} }
}
CBlockIndex *pindex = NULL; CBlockIndex *pindex = NULL;
CValidationState state; CValidationState state;
if (!AcceptBlockHeader(cmpctblock.header, state, chainparams, &pindex)) { if (!ProcessNewBlockHeaders({cmpctblock.header}, state, chainparams, &pindex)) {
int nDoS; int nDoS;
if (state.IsInvalid(nDoS)) { if (state.IsInvalid(nDoS)) {
if (nDoS > 0) if (nDoS > 0) {
LOCK(cs_main);
Misbehaving(pfrom->GetId(), nDoS); Misbehaving(pfrom->GetId(), nDoS);
}
LogPrintf("Peer %d sent us invalid header via cmpctblock\n", pfrom->id); LogPrintf("Peer %d sent us invalid header via cmpctblock\n", pfrom->id);
return true; return true;
} }
} }
LOCK(cs_main);
// If AcceptBlockHeader returned true, it set pindex // If AcceptBlockHeader returned true, it set pindex
assert(pindex); assert(pindex);
UpdateBlockAvailability(pfrom->GetId(), pindex->GetBlockHash()); UpdateBlockAvailability(pfrom->GetId(), pindex->GetBlockHash());