mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
9102: Really don't validate genesis block
This commit is contained in:
parent
504269835d
commit
56515c34cb
2 changed files with 24 additions and 18 deletions
|
|
@ -274,9 +274,11 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
|
||||||
pindexNew->nStatus = diskindex.nStatus;
|
pindexNew->nStatus = diskindex.nStatus;
|
||||||
pindexNew->nTx = diskindex.nTx;
|
pindexNew->nTx = diskindex.nTx;
|
||||||
|
|
||||||
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams))
|
const uint256 block_hash = pindexNew->GetBlockHash();
|
||||||
return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
|
if (!CheckProofOfWork(block_hash, pindexNew->nBits, consensusParams) &&
|
||||||
|
block_hash != consensusParams.hashGenesisBlock) {
|
||||||
|
return error("%s: CheckProofOfWork: %s, %s", __func__, block_hash.ToString(), pindexNew->ToString());
|
||||||
|
}
|
||||||
pcursor->Next();
|
pcursor->Next();
|
||||||
} else {
|
} else {
|
||||||
return error("%s: failed to read value", __func__);
|
return error("%s: failed to read value", __func__);
|
||||||
|
|
|
||||||
|
|
@ -1091,8 +1091,11 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the header
|
// Check the header
|
||||||
if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
|
const uint256 block_hash = block.GetHash();
|
||||||
|
if (!CheckProofOfWork(block_hash, block.nBits, consensusParams) &&
|
||||||
|
block_hash != consensusParams.hashGenesisBlock) {
|
||||||
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
|
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1810,6 +1813,18 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||||
assert(*pindex->phashBlock == block.GetHash());
|
assert(*pindex->phashBlock == block.GetHash());
|
||||||
int64_t nTimeStart = GetTimeMicros();
|
int64_t nTimeStart = GetTimeMicros();
|
||||||
|
|
||||||
|
// verify that the view's current state corresponds to the previous block
|
||||||
|
const uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
|
||||||
|
assert(hashPrevBlock == view.GetBestBlock());
|
||||||
|
|
||||||
|
// Special case for the genesis block, skipping connection of its transactions
|
||||||
|
// (its coinbase is unspendable)
|
||||||
|
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
|
||||||
|
if (!fJustCheck)
|
||||||
|
view.SetBestBlock(pindex->GetBlockHash());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check it again in case a previous version let a bad block in
|
// Check it again in case a previous version let a bad block in
|
||||||
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
|
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
|
||||||
// ContextualCheckBlockHeader() here. This means that if we add a new
|
// ContextualCheckBlockHeader() here. This means that if we add a new
|
||||||
|
|
@ -1833,18 +1848,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||||
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
|
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify that the view's current state corresponds to the previous block
|
|
||||||
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
|
|
||||||
assert(hashPrevBlock == view.GetBestBlock());
|
|
||||||
|
|
||||||
// Special case for the genesis block, skipping connection of its transactions
|
|
||||||
// (its coinbase is unspendable)
|
|
||||||
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
|
|
||||||
if (!fJustCheck)
|
|
||||||
view.SetBestBlock(pindex->GetBlockHash());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
nBlocksTotal++;
|
nBlocksTotal++;
|
||||||
|
|
||||||
bool fScriptChecks = true;
|
bool fScriptChecks = true;
|
||||||
|
|
@ -3498,8 +3501,9 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
|
||||||
if (pindex->nChainWork < nMinimumChainWork) return true;
|
if (pindex->nChainWork < nMinimumChainWork) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CheckBlock(block, state, chainparams.GetConsensus()) ||
|
if (chainparams.GetConsensus().hashGenesisBlock != block.GetHash() &&
|
||||||
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) {
|
(!CheckBlock(block, state, chainparams.GetConsensus()) ||
|
||||||
|
!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;
|
||||||
setDirtyBlockIndex.insert(pindex);
|
setDirtyBlockIndex.insert(pindex);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue