Merge #9765: Harden against mistakes handling invalid blocks
ba803ef Harden against mistakes handling invalid blocks (Suhas Daftuar)
This commit is contained in:
parent
662ec024ab
commit
4ac4e96e8f
@ -399,7 +399,7 @@ class FullBlockTest(ComparisonTestFramework):
|
|||||||
|
|
||||||
# Extend the b26 chain to make sure bitcoind isn't accepting b26
|
# Extend the b26 chain to make sure bitcoind isn't accepting b26
|
||||||
b27 = block(27, spend=out[7])
|
b27 = block(27, spend=out[7])
|
||||||
yield rejected(RejectResult(16, b'bad-prevblk'))
|
yield rejected(RejectResult(0, b'bad-prevblk'))
|
||||||
|
|
||||||
# Now try a too-large-coinbase script
|
# Now try a too-large-coinbase script
|
||||||
tip(15)
|
tip(15)
|
||||||
@ -411,7 +411,7 @@ class FullBlockTest(ComparisonTestFramework):
|
|||||||
|
|
||||||
# Extend the b28 chain to make sure bitcoind isn't accepting b28
|
# Extend the b28 chain to make sure bitcoind isn't accepting b28
|
||||||
b29 = block(29, spend=out[7])
|
b29 = block(29, spend=out[7])
|
||||||
yield rejected(RejectResult(16, b'bad-prevblk'))
|
yield rejected(RejectResult(0, b'bad-prevblk'))
|
||||||
|
|
||||||
# b30 has a max-sized coinbase scriptSig.
|
# b30 has a max-sized coinbase scriptSig.
|
||||||
tip(23)
|
tip(23)
|
||||||
|
@ -3586,7 +3586,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
|
|||||||
}
|
}
|
||||||
if (fNewBlock) *fNewBlock = true;
|
if (fNewBlock) *fNewBlock = true;
|
||||||
|
|
||||||
if (!CheckBlock(block, state, chainparams.GetConsensus(), GetAdjustedTime()) ||
|
if (!CheckBlock(block, state, chainparams.GetConsensus()) ||
|
||||||
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) {
|
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) {
|
||||||
if (state.IsInvalid() && !state.CorruptionPossible()) {
|
if (state.IsInvalid() && !state.CorruptionPossible()) {
|
||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||||
@ -3628,13 +3628,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)
|
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;
|
CBlockIndex *pindex = NULL;
|
||||||
if (fNewBlock) *fNewBlock = false;
|
if (fNewBlock) *fNewBlock = false;
|
||||||
CValidationState state;
|
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());
|
CheckBlockIndex(chainparams.GetConsensus());
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
GetMainSignals().BlockChecked(*pblock, state);
|
GetMainSignals().BlockChecked(*pblock, state);
|
||||||
|
Loading…
Reference in New Issue
Block a user