mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-03 22:03:01 +01:00
Harden against mistakes handling invalid blocks
Fixes a bug in AcceptBlock() in invoking CheckBlock() with incorrect arguments, and restores a call to CheckBlock() from ProcessNewBlock() as belt-and-suspenders. Updates the (overspecified) tests to match behavior.
This commit is contained in:
@@ -3187,7 +3187,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
|
||||
}
|
||||
if (fNewBlock) *fNewBlock = true;
|
||||
|
||||
if (!CheckBlock(block, state, chainparams.GetConsensus(), GetAdjustedTime()) ||
|
||||
if (!CheckBlock(block, state, chainparams.GetConsensus()) ||
|
||||
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) {
|
||||
if (state.IsInvalid() && !state.CorruptionPossible()) {
|
||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||
@@ -3229,13 +3229,19 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
|
||||
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool *fNewBlock)
|
||||
{
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
// Store to disk
|
||||
CBlockIndex *pindex = NULL;
|
||||
if (fNewBlock) *fNewBlock = false;
|
||||
CValidationState state;
|
||||
bool ret = AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, NULL, fNewBlock);
|
||||
// Ensure that CheckBlock() passes before calling AcceptBlock, as
|
||||
// belt-and-suspenders.
|
||||
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus());
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
if (ret) {
|
||||
// Store to disk
|
||||
ret = AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, NULL, fNewBlock);
|
||||
}
|
||||
CheckBlockIndex(chainparams.GetConsensus());
|
||||
if (!ret) {
|
||||
GetMainSignals().BlockChecked(*pblock, state);
|
||||
|
||||
Reference in New Issue
Block a user