Skip to content

Commit

Permalink
[Squash] More validation
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Apr 21, 2023
1 parent 432979f commit c0ea05f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c0ea05f

Please sign in to comment.