Skip to content

Commit

Permalink
[Refactoring] unify contextual checks for txes
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Apr 7, 2021
1 parent 11d2025 commit bfd3fe4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/consensus/tx_verify.cpp
Expand Up @@ -169,3 +169,16 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, CValidationS

return true;
}

bool ContextualCheckTransaction(const CTransactionRef& tx, CValidationState& state, const CChainParams& chainparams, int nHeight, bool isMined, bool fIBD)
{
// Dispatch to Sapling validator
if (!SaplingValidation::ContextualCheckTransaction(*tx, state, chainparams, nHeight, isMined, fIBD)) {
return false; // Failure reason has been set in validation state object
}

// Dispatch to ZerocoinTx validator
// !TODO

return true;
}
3 changes: 3 additions & 0 deletions src/consensus/tx_verify.h
Expand Up @@ -11,13 +11,16 @@
#include <vector>

class CBlockIndex;
class CChainParams;
class CCoinsViewCache;
class CValidationState;

/** Transaction validation functions */

/** Context-independent validity checks */
bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, CValidationState& state, bool fFakeSerialAttack, bool fColdStakingActive);
/** Context-dependent validity checks */
bool ContextualCheckTransaction(const CTransactionRef& tx, CValidationState& state, const CChainParams& chainparams, int nHeight, bool isMined, bool fIBD);

/**
* Count ECDSA signature operations the old-fashioned (pre-0.6) way
Expand Down
11 changes: 5 additions & 6 deletions src/validation.cpp
Expand Up @@ -417,10 +417,9 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
state, isBlockBetweenFakeSerialAttackRange(chainHeight), fColdStakingActive))
return error("%s : transaction checks for %s failed with %s", __func__, tx.GetHash().ToString(), FormatStateMessage(state));

// Sapling
int nextBlockHeight = chainHeight + 1;
// Check transaction contextually against the set of consensus rules which apply in the next block to be mined.
if (!SaplingValidation::ContextualCheckTransaction(tx, state, params, nextBlockHeight, false, IsInitialBlockDownload())) {
// Check transaction contextually against consensus rules at block height
if (!ContextualCheckTransaction(_tx, state, params, nextBlockHeight, false /* isMined */, IsInitialBlockDownload())) {
return error("AcceptToMemoryPool: ContextualCheckTransaction failed");
}

Expand Down Expand Up @@ -3012,9 +3011,9 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
// Check that all transactions are finalized
for (const auto& tx : block.vtx) {

// Sapling: Check transaction contextually against consensus rules at block height
if (!SaplingValidation::ContextualCheckTransaction(*tx, state, chainparams, nHeight, true, IsInitialBlockDownload())) {
return false; // Failure reason has been set in validation state object
// Check transaction contextually against consensus rules at block height
if (!ContextualCheckTransaction(tx, state, chainparams, nHeight, true /* isMined */, IsInitialBlockDownload())) {
return false;
}

if (!IsFinalTx(tx, nHeight, block.GetBlockTime())) {
Expand Down

0 comments on commit bfd3fe4

Please sign in to comment.