@@ -1395,22 +1395,21 @@ bool CScriptCheck::operator()() {
1395
1395
return true ;
1396
1396
}
1397
1397
1398
- bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, std::vector<CScriptCheck> *pvChecks )
1398
+ int GetSpendHeight (const CCoinsViewCache& inputs )
1399
1399
{
1400
- if (!tx. IsCoinBase ())
1401
- {
1402
- if (pvChecks)
1403
- pvChecks-> reserve (tx. vin . size ());
1400
+ LOCK (cs_main);
1401
+ CBlockIndex* pindexPrev = mapBlockIndex. find (inputs. GetBestBlock ())-> second ;
1402
+ return pindexPrev-> nHeight + 1 ;
1403
+ }
1404
1404
1405
+ namespace Consensus {
1406
+ bool CheckTxInputs (const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
1407
+ {
1405
1408
// This doesn't trigger the DoS code on purpose; if it did, it would make it easier
1406
1409
// for an attacker to attempt to split the network.
1407
1410
if (!inputs.HaveInputs (tx))
1408
1411
return state.Invalid (error (" CheckInputs(): %s inputs unavailable" , tx.GetHash ().ToString ()));
1409
1412
1410
- // While checking, GetBestBlock() refers to the parent block.
1411
- // This is also true for mempool checks.
1412
- CBlockIndex *pindexPrev = mapBlockIndex.find (inputs.GetBestBlock ())->second ;
1413
- int nSpendHeight = pindexPrev->nHeight + 1 ;
1414
1413
CAmount nValueIn = 0 ;
1415
1414
CAmount nFees = 0 ;
1416
1415
for (unsigned int i = 0 ; i < tx.vin .size (); i++)
@@ -1449,6 +1448,19 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
1449
1448
if (!MoneyRange (nFees))
1450
1449
return state.DoS (100 , error (" CheckInputs(): nFees out of range" ),
1451
1450
REJECT_INVALID, " bad-txns-fee-outofrange" );
1451
+ return true ;
1452
+ }
1453
+ }// namespace Consensus
1454
+
1455
+ bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, std::vector<CScriptCheck> *pvChecks)
1456
+ {
1457
+ if (!tx.IsCoinBase ())
1458
+ {
1459
+ if (!Consensus::CheckTxInputs (tx, state, inputs, GetSpendHeight (inputs)))
1460
+ return false ;
1461
+
1462
+ if (pvChecks)
1463
+ pvChecks->reserve (tx.vin .size ());
1452
1464
1453
1465
// The first loop above does all the inexpensive checks.
1454
1466
// Only if ALL inputs pass do we perform expensive ECDSA signature checks.
0 commit comments