From 2ccbf87b04f20a40b16f07290e93eebe9ccef972 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Mon, 11 Dec 2017 11:00:55 -0500 Subject: [PATCH] skip balance checks when assumevalid is active --- src/test/pegin_witness_tests.cpp | 6 +++--- src/txmempool.cpp | 4 ++-- src/validation.cpp | 10 ++++++---- src/validation.h | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/pegin_witness_tests.cpp b/src/test/pegin_witness_tests.cpp index 5c86ff4e52..170d65a634 100644 --- a/src/test/pegin_witness_tests.cpp +++ b/src/test/pegin_witness_tests.cpp @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(witness_valid) CValidationState state; CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy); - BOOST_CHECK(Consensus::CheckTxInputs(tx, state, coins, 0, setPeginsSpent, nullptr, false)); + BOOST_CHECK(Consensus::CheckTxInputs(tx, state, coins, 0, setPeginsSpent, nullptr, false, true)); BOOST_CHECK(setPeginsSpent.size() == 1); setPeginsSpent.clear(); @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(witness_valid) CMutableTransaction mtxn(tx); mtxn.wit.vtxinwit[0].m_pegin_witness.SetNull(); CTransaction tx2(mtxn); - BOOST_CHECK(!Consensus::CheckTxInputs(tx2, state, coins, 0, setPeginsSpent, nullptr, false)); + BOOST_CHECK(!Consensus::CheckTxInputs(tx2, state, coins, 0, setPeginsSpent, nullptr, false, true)); BOOST_CHECK(setPeginsSpent.empty()); // Invalidate peg-in (and spending) authorization by pegin marker. @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(witness_valid) CMutableTransaction mtxn2(tx); mtxn2.vin[0].m_is_pegin = false; CTransaction tx3(mtxn2); - BOOST_CHECK(!Consensus::CheckTxInputs(tx3, state, coins, 0, setPeginsSpent, nullptr, false)); + BOOST_CHECK(!Consensus::CheckTxInputs(tx3, state, coins, 0, setPeginsSpent, nullptr, false, true)); BOOST_CHECK(setPeginsSpent.empty()); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 6610015ba0..8704eb94c7 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -764,7 +764,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const CValidationState state; std::set > setPeginsSpent; bool fCheckResult = tx.IsCoinBase() || - Consensus::CheckTxInputs(tx, state, mempoolDuplicate, nSpendHeight, setPeginsSpent, NULL, false); + Consensus::CheckTxInputs(tx, state, mempoolDuplicate, nSpendHeight, setPeginsSpent, NULL, false, true); assert(fCheckResult); UpdateCoins(tx, mempoolDuplicate, 1000000); assert(setPeginsSpent == it->setPeginsSpent); @@ -785,7 +785,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const } else { std::set > setPeginsSpent; bool fCheckResult = entry->GetTx().IsCoinBase() || - Consensus::CheckTxInputs(entry->GetTx(), state, mempoolDuplicate, nSpendHeight, setPeginsSpent, NULL, false); + Consensus::CheckTxInputs(entry->GetTx(), state, mempoolDuplicate, nSpendHeight, setPeginsSpent, NULL, false, true); assert(fCheckResult); UpdateCoins(entry->GetTx(), mempoolDuplicate, 1000000); assert(setPeginsSpent == entry->setPeginsSpent); diff --git a/src/validation.cpp b/src/validation.cpp index 2c62dedfcb..e2f2e57ce5 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1844,7 +1844,7 @@ int GetSpendHeight(const CCoinsViewCache& inputs) } namespace Consensus { -bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, std::set >& setPeginsSpent, std::vector *pvChecks, const bool cacheStore) +bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, std::set >& setPeginsSpent, std::vector *pvChecks, const bool cacheStore, bool fScriptChecks) { // This doesn't trigger the DoS code on purpose; if it did, it would make it easier // for an attacker to attempt to split the network. @@ -1893,11 +1893,13 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins } // Tally transaction fees - if (!tx.HasValidFee()) + if (!tx.HasValidFee()) { return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-outofrange"); - if (!VerifyAmounts(inputs, tx, pvChecks, cacheStore)) + } + if (fScriptChecks && !VerifyAmounts(inputs, tx, pvChecks, cacheStore)) { return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-ne-out", false, strprintf("value in (%s) != value out", FormatMoney(nValueIn))); + } return true; } @@ -1907,7 +1909,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi { if (!tx.IsCoinBase()) { - if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs), setPeginsSpent, pvChecks, cacheStore)) + if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs), setPeginsSpent, pvChecks, cacheStore, fScriptChecks)) return false; if (pvChecks) diff --git a/src/validation.h b/src/validation.h index 3a424b479a..6695ee53b6 100644 --- a/src/validation.h +++ b/src/validation.h @@ -392,7 +392,7 @@ namespace Consensus { * This does not modify the UTXO set. This does not check scripts and sigs. * Preconditions: tx.IsCoinBase() is false. */ -bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, std::set >& setPeginsSpent, std::vector *pvChecks, const bool cacheStore); +bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, std::set >& setPeginsSpent, std::vector *pvChecks, const bool cacheStore, bool fScriptChecks); } // namespace Consensus