diff --git a/src/validation.cpp b/src/validation.cpp index 412d8c121a2980..8ff73f58cdb8cb 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2935,8 +2935,8 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta (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 < 8 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_0))) - { + (block.nVersion < 8 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_0)) || + (block.nVersion < 12 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_SHIELD_STAKING))) { std::string stringErr = strprintf("rejected block version %d at height %d", block.nVersion, nHeight); return state.Invalid(false, REJECT_OBSOLETE, "bad-version", stringErr); } @@ -3147,7 +3147,8 @@ static bool CheckInBlockDoubleSpends(const CBlock& block, int nHeight, CValidati if (inblock_txes.find(it->hash) != inblock_txes.end()) { // the input spent was created as output of another in-block tx // this is not allowed for the coinstake input - if (*it == block.vtx[1]->vin[0].prevout) { + // this check is not needed in shield staking + if (block.IsProofOfStake() && *it == block.vtx[1]->vin[0].prevout) { return state.DoS(100, error("%s: coinstake input created in the same block", __func__)); } it = spent_outpoints.erase(it); @@ -3282,12 +3283,17 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockInde return state.DoS(100, false, REJECT_INVALID); bool isPoS = block.IsProofOfStake(); + bool isShieldPos = block.IsProofOfShieldStake(); if (isPoS) { std::string strError; if (!CheckProofOfStake(block, strError, pindexPrev)) return state.DoS(100, error("%s: proof of stake check failed (%s)", __func__, strError)); } + if (isShieldPos) { + // TODO: add zkproof check here + } + if (!AcceptBlockHeader(block, state, &pindex, pindexPrev)) return false; @@ -3308,7 +3314,7 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockInde int nHeight = pindex->nHeight; - if (isPoS) { + if (isPoS || isShieldPos) { // Blocks arrives in order, so if prev block is not the tip then we are on a fork. // Extra info: duplicated blocks are skipping this checks, so we don't have to worry about those here. bool isBlockFromFork = pindexPrev != nullptr && chainActive.Tip() != pindexPrev; @@ -3388,7 +3394,6 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockInde coinstake.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv"); } } - } // Write block to history file