@@ -1379,22 +1379,21 @@ bool CScriptCheck::operator()() {
1379
1379
return true ;
1380
1380
}
1381
1381
1382
- bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, std::vector<CScriptCheck> *pvChecks )
1382
+ int GetSpendHeight (const CCoinsViewCache& inputs )
1383
1383
{
1384
- if (!tx. IsCoinBase ())
1385
- {
1386
- if (pvChecks)
1387
- pvChecks-> reserve (tx. vin . size ());
1384
+ LOCK (cs_main);
1385
+ CBlockIndex* pindexPrev = mapBlockIndex. find (inputs. GetBestBlock ())-> second ;
1386
+ return pindexPrev-> nHeight + 1 ;
1387
+ }
1388
1388
1389
+ namespace Consensus {
1390
+ bool CheckTxInputs (const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
1391
+ {
1389
1392
// This doesn't trigger the DoS code on purpose; if it did, it would make it easier
1390
1393
// for an attacker to attempt to split the network.
1391
1394
if (!inputs.HaveInputs (tx))
1392
1395
return state.Invalid (error (" CheckInputs(): %s inputs unavailable" , tx.GetHash ().ToString ()));
1393
1396
1394
- // While checking, GetBestBlock() refers to the parent block.
1395
- // This is also true for mempool checks.
1396
- CBlockIndex *pindexPrev = mapBlockIndex.find (inputs.GetBestBlock ())->second ;
1397
- int nSpendHeight = pindexPrev->nHeight + 1 ;
1398
1397
CAmount nValueIn = 0 ;
1399
1398
CAmount nFees = 0 ;
1400
1399
for (unsigned int i = 0 ; i < tx.vin .size (); i++)
@@ -1433,6 +1432,19 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
1433
1432
if (!MoneyRange (nFees))
1434
1433
return state.DoS (100 , error (" CheckInputs(): nFees out of range" ),
1435
1434
REJECT_INVALID, " bad-txns-fee-outofrange" );
1435
+ return true ;
1436
+ }
1437
+ }// namespace Consensus
1438
+
1439
+ bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, std::vector<CScriptCheck> *pvChecks)
1440
+ {
1441
+ if (!tx.IsCoinBase ())
1442
+ {
1443
+ if (!Consensus::CheckTxInputs (tx, state, inputs, GetSpendHeight (inputs)))
1444
+ return false ;
1445
+
1446
+ if (pvChecks)
1447
+ pvChecks->reserve (tx.vin .size ());
1436
1448
1437
1449
// The first loop above does all the inexpensive checks.
1438
1450
// Only if ALL inputs pass do we perform expensive ECDSA signature checks.
0 commit comments