skip balance checks when assumevalid is active

This commit is contained in:
Gregory Sanders 2017-12-11 11:00:55 -05:00
parent 93cabbf1e9
commit 2ccbf87b04
4 changed files with 12 additions and 10 deletions

View file

@ -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());

View file

@ -764,7 +764,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
CValidationState state;
std::set<std::pair<uint256, COutPoint> > 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<std::pair<uint256, COutPoint> > 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);

View file

@ -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<std::pair<uint256, COutPoint> >& setPeginsSpent, std::vector<CCheck*> *pvChecks, const bool cacheStore)
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, std::set<std::pair<uint256, COutPoint> >& setPeginsSpent, std::vector<CCheck*> *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)

View file

@ -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<std::pair<uint256, COutPoint> >& setPeginsSpent, std::vector<CCheck*> *pvChecks, const bool cacheStore);
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, std::set<std::pair<uint256, COutPoint> >& setPeginsSpent, std::vector<CCheck*> *pvChecks, const bool cacheStore, bool fScriptChecks);
} // namespace Consensus