@@ -1395,22 +1395,21 @@ bool CScriptCheck::operator()() {
13951395 return true ;
13961396}
13971397
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 )
13991399{
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+ }
14041404
1405+ namespace Consensus {
1406+ bool CheckTxInputs (const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
1407+ {
14051408 // This doesn't trigger the DoS code on purpose; if it did, it would make it easier
14061409 // for an attacker to attempt to split the network.
14071410 if (!inputs.HaveInputs (tx))
14081411 return state.Invalid (error (" CheckInputs(): %s inputs unavailable" , tx.GetHash ().ToString ()));
14091412
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 ;
14141413 CAmount nValueIn = 0 ;
14151414 CAmount nFees = 0 ;
14161415 for (unsigned int i = 0 ; i < tx.vin .size (); i++)
@@ -1449,6 +1448,19 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
14491448 if (!MoneyRange (nFees))
14501449 return state.DoS (100 , error (" CheckInputs(): nFees out of range" ),
14511450 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 ());
14521464
14531465 // The first loop above does all the inexpensive checks.
14541466 // Only if ALL inputs pass do we perform expensive ECDSA signature checks.
0 commit comments