Skip to content

Commit 24f2489

Browse files
committed
Merge pull request #6299
4f40716 test: Move reindex test to standard tests (Wladimir J. van der Laan) 36c97b4 Bugfix: Don't check the genesis block header before accepting it (Jorge Timón)
2 parents 41076aa + 4f40716 commit 24f2489

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

qa/pull-tester/rpc-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ testScripts=(
3434
'signrawtransactions.py'
3535
'walletbackup.py'
3636
'nodehandling.py'
37+
'reindex.py'
3738
);
3839
testScriptsExt=(
3940
'bipdersig-p2p.py'
@@ -45,7 +46,6 @@ testScriptsExt=(
4546
'invalidateblock.py'
4647
'keypool.py'
4748
'receivedby.py'
48-
'reindex.py'
4949
'rpcbind_test.py'
5050
# 'script_test.py'
5151
'smartfees.py'

src/main.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,36 +2810,37 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
28102810
uint256 hash = block.GetHash();
28112811
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
28122812
CBlockIndex *pindex = NULL;
2813-
if (miSelf != mapBlockIndex.end()) {
2814-
// Block header is already known.
2815-
pindex = miSelf->second;
2816-
if (ppindex)
2817-
*ppindex = pindex;
2818-
if (pindex->nStatus & BLOCK_FAILED_MASK)
2819-
return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate");
2820-
return true;
2821-
}
2813+
if (hash != chainparams.GetConsensus().hashGenesisBlock) {
28222814

2823-
if (!CheckBlockHeader(block, state))
2824-
return false;
2815+
if (miSelf != mapBlockIndex.end()) {
2816+
// Block header is already known.
2817+
pindex = miSelf->second;
2818+
if (ppindex)
2819+
*ppindex = pindex;
2820+
if (pindex->nStatus & BLOCK_FAILED_MASK)
2821+
return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate");
2822+
return true;
2823+
}
28252824

2826-
// Get prev block index
2827-
CBlockIndex* pindexPrev = NULL;
2828-
if (hash != chainparams.GetConsensus().hashGenesisBlock) {
2825+
if (!CheckBlockHeader(block, state))
2826+
return false;
2827+
2828+
// Get prev block index
2829+
CBlockIndex* pindexPrev = NULL;
28292830
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
28302831
if (mi == mapBlockIndex.end())
28312832
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk");
28322833
pindexPrev = (*mi).second;
28332834
if (pindexPrev->nStatus & BLOCK_FAILED_MASK)
28342835
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
2835-
}
2836-
assert(pindexPrev);
2837-
if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint(pindexPrev, state, chainparams, hash))
2838-
return error("%s: CheckIndexAgainstCheckpoint(): %s", __func__, state.GetRejectReason().c_str());
28392836

2840-
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
2841-
return false;
2837+
assert(pindexPrev);
2838+
if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint(pindexPrev, state, chainparams, hash))
2839+
return error("%s: CheckIndexAgainstCheckpoint(): %s", __func__, state.GetRejectReason().c_str());
28422840

2841+
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
2842+
return false;
2843+
}
28432844
if (pindex == NULL)
28442845
pindex = AddToBlockIndex(block);
28452846

0 commit comments

Comments
 (0)