@@ -1091,8 +1091,10 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
10911091 }
10921092
10931093 // Check the header
1094- if (!CheckProofOfWork (block.GetHash (), block.nBits , consensusParams))
1094+ if (block.GetHash () != consensusParams.hashGenesisBlock &&
1095+ !CheckProofOfWork (block.GetHash (), block.nBits , consensusParams)) {
10951096 return error (" ReadBlockFromDisk: Errors in block header at %s" , pos.ToString ());
1097+ }
10961098
10971099 return true ;
10981100}
@@ -1810,6 +1812,22 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18101812 assert (*pindex->phashBlock == block.GetHash ());
18111813 int64_t nTimeStart = GetTimeMicros ();
18121814
1815+ // verify that the view's current state corresponds to the previous block
1816+ uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256 () : pindex->pprev ->GetBlockHash ();
1817+ assert (hashPrevBlock == view.GetBestBlock ());
1818+
1819+ // Add genesis outputs but don't validate.
1820+ if (block.GetHash () == chainparams.GetConsensus ().hashGenesisBlock ) {
1821+ if (!fJustCheck ) {
1822+ for (const auto & tx : block.vtx ) {
1823+ // Directly add new coins to DB
1824+ AddCoins (view, *tx, 0 );
1825+ }
1826+ view.SetBestBlock (pindex->GetBlockHash ());
1827+ }
1828+ return true ;
1829+ }
1830+
18131831 // Check it again in case a previous version let a bad block in
18141832 // NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
18151833 // ContextualCheckBlockHeader() here. This means that if we add a new
@@ -1833,22 +1851,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18331851 return error (" %s: Consensus::CheckBlock: %s" , __func__, FormatStateMessage (state));
18341852 }
18351853
1836- // verify that the view's current state corresponds to the previous block
1837- uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256 () : pindex->pprev ->GetBlockHash ();
1838- assert (hashPrevBlock == view.GetBestBlock ());
1839-
1840- // Add genesis outputs but don't validate.
1841- if (block.GetHash () == chainparams.GetConsensus ().hashGenesisBlock ) {
1842- if (!fJustCheck ) {
1843- for (const auto & tx : block.vtx ) {
1844- // Directly add new coins to DB
1845- AddCoins (view, *tx, 0 );
1846- }
1847- view.SetBestBlock (pindex->GetBlockHash ());
1848- }
1849- return true ;
1850- }
1851-
18521854 nBlocksTotal++;
18531855
18541856 bool fScriptChecks = true ;
@@ -3083,9 +3085,10 @@ static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos,
30833085static bool CheckBlockHeader (const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true )
30843086{
30853087 // Check proof of work matches claimed amount
3086- if (fCheckPOW && !CheckProofOfWork (block.GetHash (), block.nBits , consensusParams))
3088+ if (fCheckPOW && block.GetHash () != consensusParams.hashGenesisBlock
3089+ && !CheckProofOfWork (block.GetHash (), block.nBits , consensusParams)) {
30873090 return state.DoS (50 , false , REJECT_INVALID, " high-hash" , false , " proof of work failed" );
3088-
3091+ }
30893092 return true ;
30903093}
30913094
@@ -3502,8 +3505,9 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
35023505 if (pindex->nChainWork < nMinimumChainWork) return true ;
35033506 }
35043507
3505- if (!CheckBlock (block, state, chainparams.GetConsensus ()) ||
3506- !ContextualCheckBlock (block, state, chainparams.GetConsensus (), pindex->pprev )) {
3508+ if (block.GetHash () != chainparams.GetConsensus ().hashGenesisBlock &&
3509+ (!CheckBlock (block, state, chainparams.GetConsensus ()) ||
3510+ !ContextualCheckBlock (block, state, chainparams.GetConsensus (), pindex->pprev ))) {
35073511 if (state.IsInvalid () && !state.CorruptionPossible ()) {
35083512 pindex->nStatus |= BLOCK_FAILED_VALID;
35093513 setDirtyBlockIndex.insert (pindex);
0 commit comments