@@ -1492,13 +1492,13 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
1492
1492
1493
1493
// Check against previous transactions
1494
1494
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
1495
- CachedHashes cachedHashes (tx);
1496
- if (!CheckInputs (tx, state, view, true , scriptVerifyFlags, true , cachedHashes )) {
1495
+ PrecomputedTransactionData txdata (tx);
1496
+ if (!CheckInputs (tx, state, view, true , scriptVerifyFlags, true , txdata )) {
1497
1497
// SCRIPT_VERIFY_CLEANSTACK requires SCRIPT_VERIFY_WITNESS, so we
1498
1498
// need to turn both off, and compare against just turning off CLEANSTACK
1499
1499
// to see if the failure is specifically due to witness validation.
1500
- if (CheckInputs (tx, state, view, true , scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true , cachedHashes ) &&
1501
- !CheckInputs (tx, state, view, true , scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true , cachedHashes )) {
1500
+ if (CheckInputs (tx, state, view, true , scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true , txdata ) &&
1501
+ !CheckInputs (tx, state, view, true , scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true , txdata )) {
1502
1502
// Only the witness is wrong, so the transaction itself may be fine.
1503
1503
state.SetCorruptionPossible ();
1504
1504
}
@@ -1514,7 +1514,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
1514
1514
// There is a similar check in CreateNewBlock() to prevent creating
1515
1515
// invalid blocks, however allowing such transactions into the mempool
1516
1516
// can be exploited as a DoS attack.
1517
- if (!CheckInputs (tx, state, view, true , MANDATORY_SCRIPT_VERIFY_FLAGS, true , cachedHashes ))
1517
+ if (!CheckInputs (tx, state, view, true , MANDATORY_SCRIPT_VERIFY_FLAGS, true , txdata ))
1518
1518
{
1519
1519
return error (" %s: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s, %s" ,
1520
1520
__func__, hash.ToString (), FormatStateMessage (state));
@@ -1911,7 +1911,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight)
1911
1911
bool CScriptCheck::operator ()() {
1912
1912
const CScript &scriptSig = ptxTo->vin [nIn].scriptSig ;
1913
1913
const CScriptWitness *witness = (nIn < ptxTo->wit .vtxinwit .size ()) ? &ptxTo->wit .vtxinwit [nIn].scriptWitness : NULL ;
1914
- if (!VerifyScript (scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker (ptxTo, nIn, amount, cacheStore, *cachedHashes ), &error)) {
1914
+ if (!VerifyScript (scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker (ptxTo, nIn, amount, cacheStore, *txdata ), &error)) {
1915
1915
return false ;
1916
1916
}
1917
1917
return true ;
@@ -1970,7 +1970,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
1970
1970
}
1971
1971
}// namespace Consensus
1972
1972
1973
- bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, CachedHashes& cachedHashes , std::vector<CScriptCheck> *pvChecks)
1973
+ bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, PrecomputedTransactionData& txdata , std::vector<CScriptCheck> *pvChecks)
1974
1974
{
1975
1975
if (!tx.IsCoinBase ())
1976
1976
{
@@ -1997,7 +1997,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
1997
1997
assert (coins);
1998
1998
1999
1999
// Verify signature
2000
- CScriptCheck check (*coins, tx, i, flags, cacheStore, &cachedHashes );
2000
+ CScriptCheck check (*coins, tx, i, flags, cacheStore, &txdata );
2001
2001
if (pvChecks) {
2002
2002
pvChecks->push_back (CScriptCheck ());
2003
2003
check.swap (pvChecks->back ());
@@ -2010,7 +2010,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
2010
2010
// avoid splitting the network between upgraded and
2011
2011
// non-upgraded nodes.
2012
2012
CScriptCheck check2 (*coins, tx, i,
2013
- flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheStore, &cachedHashes );
2013
+ flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheStore, &txdata );
2014
2014
if (check2 ())
2015
2015
return state.Invalid (false , REJECT_NONSTANDARD, strprintf (" non-mandatory-script-verify-flag (%s)" , ScriptErrorString (check.GetScriptError ())));
2016
2016
}
@@ -2406,8 +2406,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2406
2406
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
2407
2407
vPos.reserve (block.vtx .size ());
2408
2408
blockundo.vtxundo .reserve (block.vtx .size () - 1 );
2409
- std::vector<CachedHashes> cachedHashes ;
2410
- cachedHashes .reserve (block.vtx .size ()); // Required so that pointers to individual CachedHashes don't get invalidated
2409
+ std::vector<PrecomputedTransactionData> txdata ;
2410
+ txdata .reserve (block.vtx .size ()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated
2411
2411
for (unsigned int i = 0 ; i < block.vtx .size (); i++)
2412
2412
{
2413
2413
const CTransaction &tx = block.vtx [i];
@@ -2454,14 +2454,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2454
2454
return state.DoS (100 , error (" ConnectBlock(): too many sigops" ),
2455
2455
REJECT_INVALID, " bad-blk-sigops" );
2456
2456
2457
- cachedHashes .emplace_back (tx);
2457
+ txdata .emplace_back (tx);
2458
2458
if (!tx.IsCoinBase ())
2459
2459
{
2460
2460
nFees += view.GetValueIn (tx)-tx.GetValueOut ();
2461
2461
2462
2462
std::vector<CScriptCheck> vChecks;
2463
2463
bool fCacheResults = fJustCheck ; /* Don't cache results if we're actually connecting blocks (still consult the cache, though) */
2464
- if (!CheckInputs (tx, state, view, fScriptChecks , flags, fCacheResults , cachedHashes [i], nScriptCheckThreads ? &vChecks : NULL ))
2464
+ if (!CheckInputs (tx, state, view, fScriptChecks , flags, fCacheResults , txdata [i], nScriptCheckThreads ? &vChecks : NULL ))
2465
2465
return error (" ConnectBlock(): CheckInputs on %s failed with %s" ,
2466
2466
tx.GetHash ().ToString (), FormatStateMessage (state));
2467
2467
control.Add (vChecks);
0 commit comments