Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 5 additions & 28 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down