diff --git a/src/miner.cpp b/src/miner.cpp index fb77c93fb269..03e9075e07b8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -169,8 +169,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, if (fSaplingActive) { //!> Block v8: Sapling / tx v2 pblock->nVersion = CBlockHeader::CURRENT_VERSION; - } else { + } else if (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V4_0)) { pblock->nVersion = 7; + } else if (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_4)) { + pblock->nVersion = 6; + } else if (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BIP65)) { + pblock->nVersion = 5; + } else if (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_ZC)) { + pblock->nVersion = 4; + } else { + pblock->nVersion = 3; } // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios diff --git a/src/validation.cpp b/src/validation.cpp index 712c81314195..bdbac4e38445 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2617,26 +2617,6 @@ bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigne return true; } -bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW) -{ - // Check proof of work matches claimed amount - if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits)) - return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed"); - - if (Params().IsRegTestNet()) return true; - - // Version 4 header must be used after consensus.ZC_TimeStart. And never before. - if (block.GetBlockTime() > Params().GetConsensus().ZC_TimeStart) { - if(block.nVersion < 4) - return state.DoS(50,false, REJECT_INVALID, "block-version", "must be above 4 after ZC_TimeStart"); - } else { - if (block.nVersion >= 4) - return state.DoS(50,false, REJECT_INVALID, "block-version", "must be below 4 before ZC_TimeStart"); - } - - return true; -} - bool CheckColdStakeFreeOutput(const CTransaction& tx, const int nHeight) { if (!tx.HasP2CSOutputs()) @@ -2703,8 +2683,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. - if (!CheckBlockHeader(block, state, !IsPoS)) - return false; + if (!IsPoS && fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits)) + return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed"); // All potential-corruption validation must be done before we do any // transaction validation, as otherwise we may mark the header as invalid @@ -2953,11 +2933,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta return state.DoS(0, error("%s : forked chain older than last checkpoint (height %d)", __func__, nHeight)); // Reject outdated version blocks - if((block.nVersion < 3 && nHeight >= 1) || + if ((block.nVersion < 3 && nHeight >= 1) || (block.nVersion < 4 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_ZC)) || (block.nVersion < 5 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BIP65)) || (block.nVersion < 6 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_4)) || - (block.nVersion < 7 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V4_0))) + (block.nVersion < 7 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V4_0)) || + (block.nVersion < 8 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_0))) { std::string stringErr = strprintf("rejected block version %d at height %d", block.nVersion, nHeight); return state.Invalid(false, REJECT_OBSOLETE, "bad-version", stringErr); @@ -3069,10 +3050,6 @@ bool AcceptBlockHeader(const CBlock& block, CValidationState& state, CBlockIndex return true; } - if (!CheckBlockHeader(block, state, false)) { - return error("%s: CheckBlockHeader failed for block %s: %s", __func__, hash.ToString(), FormatStateMessage(state)); - } - // Get prev block index if (pindexPrev == nullptr && !GetPrevIndex(block, &pindexPrev, state)) { return false; diff --git a/src/validation.h b/src/validation.h index 9715c02a087f..06713a60f3b6 100644 --- a/src/validation.h +++ b/src/validation.h @@ -323,7 +323,6 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex); bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck, bool fAlreadyChecked = false); /** Context-independent validity checks */ -bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW = true, bool fCheckMerkleRoot = true, bool fCheckSig = true); bool CheckWork(const CBlock block, CBlockIndex* const pindexPrev);