Globals: Explicitly pass const CChainParams& to ContextualCheckTransaction()
This commit is contained in:
parent
7ef947c32b
commit
be94721953
|
@ -167,7 +167,7 @@ TEST(checktransaction_tests, BadTxnsOversize) {
|
|||
|
||||
// ... but fails contextual ones!
|
||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-oversize", false)).Times(1);
|
||||
EXPECT_FALSE(ContextualCheckTransaction(tx, state, 1, 100));
|
||||
EXPECT_FALSE(ContextualCheckTransaction(tx, state, Params(), 1, 100));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -188,7 +188,7 @@ TEST(checktransaction_tests, BadTxnsOversize) {
|
|||
|
||||
MockCValidationState state;
|
||||
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, 1, 100));
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 1, 100));
|
||||
|
||||
// Revert to default
|
||||
RegtestDeactivateSapling();
|
||||
|
@ -496,6 +496,7 @@ TEST(checktransaction_tests, bad_txns_prevout_null) {
|
|||
|
||||
TEST(checktransaction_tests, bad_txns_invalid_joinsplit_signature) {
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
auto chainparams = Params();
|
||||
|
||||
CMutableTransaction mtx = GetValidTransaction();
|
||||
mtx.joinSplitSig[0] += 1;
|
||||
|
@ -504,13 +505,14 @@ TEST(checktransaction_tests, bad_txns_invalid_joinsplit_signature) {
|
|||
MockCValidationState state;
|
||||
// during initial block download, DoS ban score should be zero, else 100
|
||||
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 0, 100, []() { return true; });
|
||||
ContextualCheckTransaction(tx, state, chainparams, 0, 100, []() { return true; });
|
||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 0, 100, []() { return false; });
|
||||
ContextualCheckTransaction(tx, state, chainparams, 0, 100, []() { return false; });
|
||||
}
|
||||
|
||||
TEST(checktransaction_tests, non_canonical_ed25519_signature) {
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
auto chainparams = Params();
|
||||
|
||||
CMutableTransaction mtx = GetValidTransaction();
|
||||
|
||||
|
@ -518,7 +520,7 @@ TEST(checktransaction_tests, non_canonical_ed25519_signature) {
|
|||
{
|
||||
CTransaction tx(mtx);
|
||||
MockCValidationState state;
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, 0, 100));
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, chainparams, 0, 100));
|
||||
}
|
||||
|
||||
// Copied from libsodium/crypto_sign/ed25519/ref10/open.c
|
||||
|
@ -540,9 +542,9 @@ TEST(checktransaction_tests, non_canonical_ed25519_signature) {
|
|||
MockCValidationState state;
|
||||
// during initial block download, DoS ban score should be zero, else 100
|
||||
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 0, 100, []() { return true; });
|
||||
ContextualCheckTransaction(tx, state, chainparams, 0, 100, []() { return true; });
|
||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 0, 100, []() { return false; });
|
||||
ContextualCheckTransaction(tx, state, chainparams, 0, 100, []() { return false; });
|
||||
}
|
||||
|
||||
TEST(checktransaction_tests, OverwinterConstructors) {
|
||||
|
@ -797,7 +799,7 @@ TEST(checktransaction_tests, OverwinterVersionNumberHigh) {
|
|||
UNSAFE_CTransaction tx(mtx);
|
||||
MockCValidationState state;
|
||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-tx-overwinter-version-too-high", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 1, 100);
|
||||
ContextualCheckTransaction(tx, state, Params(), 1, 100);
|
||||
|
||||
// Revert to default
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
|
||||
|
@ -822,6 +824,7 @@ TEST(checktransaction_tests, OverwinterBadVersionGroupId) {
|
|||
// This tests an Overwinter transaction checked against Sprout
|
||||
TEST(checktransaction_tests, OverwinterNotActive) {
|
||||
SelectParams(CBaseChainParams::TESTNET);
|
||||
auto chainparams = Params();
|
||||
|
||||
CMutableTransaction mtx = GetValidTransaction();
|
||||
mtx.fOverwintered = true;
|
||||
|
@ -833,9 +836,9 @@ TEST(checktransaction_tests, OverwinterNotActive) {
|
|||
MockCValidationState state;
|
||||
// during initial block download, DoS ban score should be zero, else 100
|
||||
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "tx-overwinter-not-active", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 1, 100, []() { return true; });
|
||||
ContextualCheckTransaction(tx, state, chainparams, 1, 100, []() { return true; });
|
||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "tx-overwinter-not-active", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 1, 100, []() { return false; });
|
||||
ContextualCheckTransaction(tx, state, chainparams, 1, 100, []() { return false; });
|
||||
}
|
||||
|
||||
// This tests a transaction without the fOverwintered flag set, against the Overwinter consensus rule set.
|
||||
|
@ -852,7 +855,7 @@ TEST(checktransaction_tests, OverwinterFlagNotSet) {
|
|||
CTransaction tx(mtx);
|
||||
MockCValidationState state;
|
||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "tx-overwinter-flag-not-set", false)).Times(1);
|
||||
ContextualCheckTransaction(tx, state, 1, 100);
|
||||
ContextualCheckTransaction(tx, state, Params(), 1, 100);
|
||||
|
||||
// Revert to default
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
|
||||
|
|
|
@ -106,7 +106,7 @@ TEST(TransactionBuilder, TransparentToSapling)
|
|||
EXPECT_EQ(tx.valueBalance, -40000);
|
||||
|
||||
CValidationState state;
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, 2, 0));
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 2, 0));
|
||||
EXPECT_EQ(state.GetRejectReason(), "");
|
||||
|
||||
// Revert to default
|
||||
|
@ -143,7 +143,7 @@ TEST(TransactionBuilder, SaplingToSapling) {
|
|||
EXPECT_EQ(tx.valueBalance, 10000);
|
||||
|
||||
CValidationState state;
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, 3, 0));
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 3, 0));
|
||||
EXPECT_EQ(state.GetRejectReason(), "");
|
||||
|
||||
// Revert to default
|
||||
|
@ -181,7 +181,7 @@ TEST(TransactionBuilder, SaplingToSprout) {
|
|||
EXPECT_EQ(tx.valueBalance, 35000);
|
||||
|
||||
CValidationState state;
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, 3, 0));
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 3, 0));
|
||||
EXPECT_EQ(state.GetRejectReason(), "");
|
||||
|
||||
// Revert to default
|
||||
|
@ -242,7 +242,7 @@ TEST(TransactionBuilder, SproutToSproutAndSapling) {
|
|||
EXPECT_EQ(tx.valueBalance, -5000);
|
||||
|
||||
CValidationState state;
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, 4, 0));
|
||||
EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 4, 0));
|
||||
EXPECT_EQ(state.GetRejectReason(), "");
|
||||
|
||||
// Revert to default
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -891,12 +891,13 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
|
|||
bool ContextualCheckTransaction(
|
||||
const CTransaction& tx,
|
||||
CValidationState &state,
|
||||
const CChainParams& chainparams,
|
||||
const int nHeight,
|
||||
const int dosLevel,
|
||||
bool (*isInitBlockDownload)())
|
||||
{
|
||||
bool overwinterActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
||||
bool saplingActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING);
|
||||
bool overwinterActive = NetworkUpgradeActive(nHeight, chainparams.GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
||||
bool saplingActive = NetworkUpgradeActive(nHeight, chainparams.GetConsensus(), Consensus::UPGRADE_SAPLING);
|
||||
bool isSprout = !overwinterActive;
|
||||
|
||||
// If Sprout rules apply, reject transactions which are intended for Overwinter and beyond
|
||||
|
@ -983,7 +984,7 @@ bool ContextualCheckTransaction(
|
|||
!tx.vShieldedSpend.empty() ||
|
||||
!tx.vShieldedOutput.empty())
|
||||
{
|
||||
auto consensusBranchId = CurrentEpochBranchId(nHeight, Params().GetConsensus());
|
||||
auto consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus());
|
||||
// Empty output script.
|
||||
CScript scriptCode;
|
||||
try {
|
||||
|
@ -1382,7 +1383,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
|||
|
||||
// DoS level set to 10 to be more forgiving.
|
||||
// Check transaction contextually against the set of consensus rules which apply in the next block to be mined.
|
||||
if (!ContextualCheckTransaction(tx, state, nextBlockHeight, 10)) {
|
||||
if (!ContextualCheckTransaction(tx, state, Params(), nextBlockHeight, 10)) {
|
||||
return error("AcceptToMemoryPool: ContextualCheckTransaction failed");
|
||||
}
|
||||
|
||||
|
@ -3852,7 +3853,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
|
|||
BOOST_FOREACH(const CTransaction& tx, block.vtx) {
|
||||
|
||||
// Check transaction contextually against consensus rules at block height
|
||||
if (!ContextualCheckTransaction(tx, state, nHeight, 100)) {
|
||||
if (!ContextualCheckTransaction(tx, state, Params(), nHeight, 100)) {
|
||||
return false; // Failure reason has been set in validation state object
|
||||
}
|
||||
|
||||
|
|
|
@ -341,7 +341,8 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons
|
|||
std::vector<CScriptCheck> *pvChecks = NULL);
|
||||
|
||||
/** Check a transaction contextually against a set of consensus rules */
|
||||
bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel,
|
||||
bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state,
|
||||
const CChainParams& chainparams, int nHeight, int dosLevel,
|
||||
bool (*isInitBlockDownload)() = IsInitialBlockDownload);
|
||||
|
||||
/** Apply the effects of this transaction on the UTXO set represented by view */
|
||||
|
|
|
@ -491,7 +491,7 @@ void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransa
|
|||
jsdesc->nullifiers[1] = GetRandHash();
|
||||
|
||||
BOOST_CHECK(CheckTransactionWithoutProofVerification(newTx, state));
|
||||
BOOST_CHECK(!ContextualCheckTransaction(newTx, state, 0, 100));
|
||||
BOOST_CHECK(!ContextualCheckTransaction(newTx, state, Params(), 0, 100));
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-txns-invalid-joinsplit-signature");
|
||||
|
||||
// Empty output script.
|
||||
|
@ -505,7 +505,7 @@ void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransa
|
|||
) == 0);
|
||||
|
||||
BOOST_CHECK(CheckTransactionWithoutProofVerification(newTx, state));
|
||||
BOOST_CHECK(ContextualCheckTransaction(newTx, state, 0, 100));
|
||||
BOOST_CHECK(ContextualCheckTransaction(newTx, state, Params(), 0, 100));
|
||||
}
|
||||
{
|
||||
// Ensure that values within the joinsplit are well-formed.
|
||||
|
|
Loading…
Reference in New Issue