diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -275,8 +275,7 @@ uint64_t nPotentialBlockSize = nBlockSize; for (const CTxMemPool::txiter it : package) { CValidationState state; - if (!ContextualCheckTransaction(*config, it->GetTx(), state, - chainparams.GetConsensus(), nHeight, + if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, nLockTimeCutoff)) { return false; } @@ -326,8 +325,7 @@ // Must check that lock times are still valid. This can be removed once MTP // is always enforced as long as reorgs keep the mempool consistent. CValidationState state; - if (!ContextualCheckTransaction(*config, it->GetTx(), state, - chainparams.GetConsensus(), nHeight, + if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, nLockTimeCutoff)) { return false; } diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -540,8 +540,8 @@ // Locktime passes. GlobalConfig config; CValidationState state; - BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( - config, tx, state, chainparams.GetConsensus(), flags)); + BOOST_CHECK(ContextualCheckTransactionForCurrentBlock(config, tx, state, + flags)); } // Sequence locks fail. @@ -567,8 +567,8 @@ // Locktime passes. GlobalConfig config; CValidationState state; - BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( - config, tx, state, chainparams.GetConsensus(), flags)); + BOOST_CHECK(ContextualCheckTransactionForCurrentBlock(config, tx, state, + flags)); } // Sequence locks fail. @@ -601,8 +601,8 @@ // Locktime fails. GlobalConfig config; CValidationState state; - BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( - config, tx, state, chainparams.GetConsensus(), flags)); + BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock(config, tx, + state, flags)); BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); } @@ -614,8 +614,7 @@ GlobalConfig config; CValidationState state; BOOST_CHECK(ContextualCheckTransaction( - config, tx, state, chainparams.GetConsensus(), - chainActive.Tip()->nHeight + 2, + config, tx, state, chainActive.Tip()->nHeight + 2, chainActive.Tip()->GetMedianTimePast())); } @@ -631,8 +630,8 @@ // Locktime fails. GlobalConfig config; CValidationState state; - BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( - config, tx, state, chainparams.GetConsensus(), flags)); + BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock(config, tx, + state, flags)); BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); } @@ -644,8 +643,7 @@ GlobalConfig config; CValidationState state; BOOST_CHECK(ContextualCheckTransaction( - config, tx, state, chainparams.GetConsensus(), - chainActive.Tip()->nHeight + 1, + config, tx, state, chainActive.Tip()->nHeight + 1, chainActive.Tip()->GetMedianTimePast() + 1)); } @@ -659,8 +657,8 @@ // Locktime passes. GlobalConfig config; CValidationState state; - BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( - config, tx, state, chainparams.GetConsensus(), flags)); + BOOST_CHECK(ContextualCheckTransactionForCurrentBlock(config, tx, state, + flags)); } // Sequence locks pass. diff --git a/src/test/script_antireplay_tests.cpp b/src/test/script_antireplay_tests.cpp --- a/src/test/script_antireplay_tests.cpp +++ b/src/test/script_antireplay_tests.cpp @@ -73,7 +73,7 @@ // The anti replay rule start at uahfHeight and stops at // antiReplayOpReturnSunsetHeight. - const int nUAHFHeight = config.GetChainParams().GetConsensus().uahfHeight; + const int nUAHFHeight = params.uahfHeight; const int nSunsetHeight = params.antiReplayOpReturnSunsetHeight; const int64_t nUAHFStartTime = 123456; @@ -91,22 +91,22 @@ { // Base transaction is valid. CValidationState state; - BOOST_CHECK(ContextualCheckTransaction(config, tx, state, params, - nSunsetHeight, nUAHFStartTime)); + BOOST_CHECK(ContextualCheckTransaction(config, tx, state, nSunsetHeight, + nUAHFStartTime)); } { // Base transaction is still valid after sunset. CValidationState state; BOOST_CHECK(ContextualCheckTransaction( - config, tx, state, params, nSunsetHeight + 1, nUAHFStartTime)); + config, tx, state, nSunsetHeight + 1, nUAHFStartTime)); } { // Base transaction is valid before the fork. CValidationState state; BOOST_CHECK(ContextualCheckTransaction( - config, tx, state, params, nUAHFHeight - 1, nUAHFStartTime - 1)); + config, tx, state, nUAHFHeight - 1, nUAHFStartTime - 1)); } tx.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_0; @@ -114,8 +114,8 @@ { // Wrong commitment, still valid. CValidationState state; - BOOST_CHECK(ContextualCheckTransaction(config, tx, state, params, - nSunsetHeight, nUAHFStartTime)); + BOOST_CHECK(ContextualCheckTransaction(config, tx, state, nSunsetHeight, + nUAHFStartTime)); } tx.vout[0].scriptPubKey = CScript() << OP_RETURN @@ -124,15 +124,15 @@ { // Anti replay commitment, not valid anymore. CValidationState state; - BOOST_CHECK(!ContextualCheckTransaction(config, tx, state, params, - nUAHFHeight, nUAHFStartTime)); + BOOST_CHECK(!ContextualCheckTransaction(config, tx, state, nUAHFHeight, + nUAHFStartTime)); BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txn-replay"); } { // Anti replay commitment, not valid anymore. CValidationState state; - BOOST_CHECK(!ContextualCheckTransaction(config, tx, state, params, + BOOST_CHECK(!ContextualCheckTransaction(config, tx, state, nSunsetHeight, nUAHFStartTime)); BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txn-replay"); } @@ -141,14 +141,14 @@ // Anti replay commitment, disabled before start time. CValidationState state; BOOST_CHECK(ContextualCheckTransaction( - config, tx, state, params, nUAHFHeight - 1, nUAHFStartTime)); + config, tx, state, nUAHFHeight - 1, nUAHFStartTime)); } { // Anti replay commitment, disabled after sunset. CValidationState state; BOOST_CHECK(ContextualCheckTransaction( - config, tx, state, params, nSunsetHeight + 1, nUAHFStartTime)); + config, tx, state, nSunsetHeight + 1, nUAHFStartTime)); } } diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -565,9 +565,8 @@ auto &config = GetConfig(); CValidationState state; - if (!ContextualCheckTransactionForCurrentBlock( - config, tx, state, config.GetChainParams().GetConsensus(), - flags) || + if (!ContextualCheckTransactionForCurrentBlock(config, tx, state, + flags) || !CheckSequenceLocks(tx, flags, &lp, validLP)) { // Note if CheckSequenceLocks fails the LockPoints may still be // invalid. So it's critical that we remove the tx and not depend on diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -568,9 +568,8 @@ * activation/deactivation and CLTV. */ bool ContextualCheckTransaction(const Config &config, const CTransaction &tx, - CValidationState &state, - const Consensus::Params &consensusParams, - int nHeight, int64_t nLockTimeCutoff); + CValidationState &state, int nHeight, + int64_t nLockTimeCutoff); /** * This is a variant of ContextualCheckTransaction which computes the contextual @@ -578,9 +577,10 @@ * * See consensus/consensus.h for flag definitions. */ -bool ContextualCheckTransactionForCurrentBlock( - const Config &config, const CTransaction &tx, CValidationState &state, - const Consensus::Params &consensusParams, int flags = -1); +bool ContextualCheckTransactionForCurrentBlock(const Config &config, + const CTransaction &tx, + CValidationState &state, + int flags = -1); /** * Context-dependent validity checks. diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -704,8 +704,7 @@ // be mined yet. CValidationState ctxState; if (!ContextualCheckTransactionForCurrentBlock( - config, tx, ctxState, config.GetChainParams().GetConsensus(), - STANDARD_LOCKTIME_VERIFY_FLAGS)) { + config, tx, ctxState, STANDARD_LOCKTIME_VERIFY_FLAGS)) { // We copy the state from a dummy to ensure we don't increase the // ban score of peer for transaction that could be valid in the future. return state.DoS( @@ -3389,9 +3388,8 @@ } bool ContextualCheckTransaction(const Config &config, const CTransaction &tx, - CValidationState &state, - const Consensus::Params &consensusParams, - int nHeight, int64_t nLockTimeCutoff) { + CValidationState &state, int nHeight, + int64_t nLockTimeCutoff) { if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) { // While this is only one transaction, we use txns in the error to // ensure continuity with other clients. @@ -3399,6 +3397,9 @@ "non-final transaction"); } + const Consensus::Params &consensusParams = + config.GetChainParams().GetConsensus(); + if (IsUAHFenabled(config, nHeight) && nHeight <= consensusParams.antiReplayOpReturnSunsetHeight) { for (const CTxOut &o : tx.vout) { @@ -3413,9 +3414,10 @@ return true; } -bool ContextualCheckTransactionForCurrentBlock( - const Config &config, const CTransaction &tx, CValidationState &state, - const Consensus::Params &consensusParams, int flags) { +bool ContextualCheckTransactionForCurrentBlock(const Config &config, + const CTransaction &tx, + CValidationState &state, + int flags) { AssertLockHeld(cs_main); // By convention a negative value for flags indicates that the current @@ -3442,8 +3444,8 @@ ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - return ContextualCheckTransaction(config, tx, state, consensusParams, - nBlockHeight, nLockTimeCutoff); + return ContextualCheckTransaction(config, tx, state, nBlockHeight, + nLockTimeCutoff); } bool ContextualCheckBlock(const Config &config, const CBlock &block, @@ -3468,8 +3470,8 @@ // Check that all transactions are finalized for (const auto &tx : block.vtx) { - if (!ContextualCheckTransaction(config, *tx, state, consensusParams, - nHeight, nLockTimeCutoff)) { + if (!ContextualCheckTransaction(config, *tx, state, nHeight, + nLockTimeCutoff)) { // state set by ContextualCheckTransaction. return false; } diff --git a/src/wallet/finaltx.cpp b/src/wallet/finaltx.cpp --- a/src/wallet/finaltx.cpp +++ b/src/wallet/finaltx.cpp @@ -11,6 +11,5 @@ bool CheckFinalTx(const CTransaction &tx, int flags = -1) { auto &config = GetConfig(); CValidationState state; - return ContextualCheckTransactionForCurrentBlock( - config, tx, state, config.GetChainParams().GetConsensus(), flags); + return ContextualCheckTransactionForCurrentBlock(config, tx, state, flags); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -705,9 +705,8 @@ CValidationState state; if (wtx.IsCoinBase() || - !ContextualCheckTransactionForCurrentBlock( - config, *wtx.tx, state, - config.GetChainParams().GetConsensus())) { + !ContextualCheckTransactionForCurrentBlock(config, *wtx.tx, + state)) { continue; } @@ -777,9 +776,8 @@ const CWalletTx &wtx = (*it).second; CValidationState state; if (wtx.IsCoinBase() || - !ContextualCheckTransactionForCurrentBlock( - config, *wtx.tx, state, - config.GetChainParams().GetConsensus())) { + !ContextualCheckTransactionForCurrentBlock(config, *wtx.tx, + state)) { continue; } @@ -881,9 +879,8 @@ it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; CValidationState state; - if (!ContextualCheckTransactionForCurrentBlock( - config, wtx, state, - config.GetChainParams().GetConsensus()) || + if (!ContextualCheckTransactionForCurrentBlock(config, wtx, + state) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0) { continue; @@ -1380,9 +1377,8 @@ CValidationState state; if (wtx.IsCoinBase() || - !ContextualCheckTransactionForCurrentBlock( - config, *wtx.tx, state, - config.GetChainParams().GetConsensus())) { + !ContextualCheckTransactionForCurrentBlock(config, *wtx.tx, + state)) { continue; }