@@ -584,7 +584,7 @@ bool AreInputsStandard(const CTransaction& tx, const MapPrevTx& mapInputs)
584584
585585 for (unsigned int i = 0 ; i < tx.vin .size (); i++)
586586 {
587- const CTxOut& prev = tx.GetOutputFor (tx.vin [i], mapInputs, false );
587+ const CTxOut& prev = tx.GetOutputFor (tx.vin [i], mapInputs);
588588
589589 vector<vector<unsigned char > > vSolutions;
590590 txnouttype whichType;
@@ -662,7 +662,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const MapPrevTx& inputs)
662662 unsigned int nSigOps = 0 ;
663663 for (unsigned int i = 0 ; i < tx.vin .size (); i++)
664664 {
665- const CTxOut& prevout = tx.GetOutputFor (tx.vin [i], inputs, false );
665+ const CTxOut& prevout = tx.GetOutputFor (tx.vin [i], inputs);
666666 if (prevout.scriptPubKey .IsPayToScriptHash ())
667667 nSigOps += prevout.scriptPubKey .GetSigOpCount (tx.vin [i].scriptSig );
668668 }
@@ -735,24 +735,6 @@ double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSiz
735735 return dPriorityInputs / nTxSize;
736736}
737737
738- void CTransaction::GetMapTxInputs (MapPrevTx& mapInputs, bool fAcceptBlock ) const
739- {
740- // Load TX inputs
741- CTxDB txdb (" r" );
742- map<uint256, CTxIndex> mapUnused;
743- bool fInvalid = false ;
744-
745- // Ensure we can fetch inputs
746- if (!this ->FetchInputs (txdb, mapUnused, false , false , mapInputs, fInvalid , fAcceptBlock ))
747- {
748- if (fInvalid )
749- {
750- LogPrintf (" Invalid TX attempted to set in GetMapTXInputs\n " );
751- return ;
752- }
753- }
754- }
755-
756738bool CTransaction::CheckTransaction () const
757739{
758740 // Basic checks that don't depend on any context
@@ -912,7 +894,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool fLimitFree,
912894 MapPrevTx mapInputs;
913895 map<uint256, CTxIndex> mapUnused;
914896 bool fInvalid = false ;
915- if (!tx.FetchInputs (txdb, mapUnused, false , false , mapInputs, fInvalid , false ))
897+ if (!tx.FetchInputs (txdb, mapUnused, false , false , mapInputs, fInvalid ))
916898 {
917899 if (fInvalid )
918900 return error (" AcceptToMemoryPool : FetchInputs found invalid tx %s" , hash.ToString ());
@@ -935,8 +917,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool fLimitFree,
935917 error (" AcceptToMemoryPool : too many sigops %s, %d > %d" ,
936918 hash.ToString (), nSigOps, MAX_TX_SIGOPS));
937919
938- int64_t nFees = tx.GetValueMapIn (mapInputs, false )-tx.GetValueOut ();
939- if (tx.GetValueMapIn (mapInputs, false ) < tx.GetValueOut ()) {
920+ int64_t nFees = tx.GetValueMapIn (mapInputs)-tx.GetValueOut ();
921+ if (tx.GetValueMapIn (mapInputs) < tx.GetValueOut ()) {
940922 LogPrintf (" AcceptToMemoryPool : tx input is less that output\n " );
941923 return tx.DoS (100 , error (" AcceptToMemoryPool : tx input is less that output" ));
942924 }
@@ -1078,7 +1060,7 @@ bool AcceptableInputs(CTxMemPool& pool, const CTransaction &txo, bool fLimitFree
10781060 MapPrevTx mapInputs;
10791061 map<uint256, CTxIndex> mapUnused;
10801062 bool fInvalid = false ;
1081- if (!tx.FetchInputs (txdb, mapUnused, false , false , mapInputs, fInvalid , false ))
1063+ if (!tx.FetchInputs (txdb, mapUnused, false , false , mapInputs, fInvalid ))
10821064 {
10831065 if (fInvalid )
10841066 return error (" AcceptableInputs : FetchInputs found invalid tx %s" , hash.ToString ());
@@ -1101,8 +1083,8 @@ bool AcceptableInputs(CTxMemPool& pool, const CTransaction &txo, bool fLimitFree
11011083 error (" AcceptableInputs : too many sigops %s, %d > %d" ,
11021084 hash.ToString (), nSigOps, MAX_TX_SIGOPS));
11031085
1104- int64_t nFees = tx.GetValueMapIn (mapInputs, false )-tx.GetValueOut ();
1105- if (tx.GetValueMapIn (mapInputs, false ) < tx.GetValueOut ()) {
1086+ int64_t nFees = tx.GetValueMapIn (mapInputs)-tx.GetValueOut ();
1087+ if (tx.GetValueMapIn (mapInputs) < tx.GetValueOut ()) {
11061088 LogPrintf (" AcceptableInputs : tx input is less that output\n " );
11071089 return error (" AcceptableInputs : tx input is less than output" );
11081090 }
@@ -1594,7 +1576,7 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
15941576
15951577
15961578bool CTransaction::FetchInputs (CTxDB& txdb, const map<uint256, CTxIndex>& mapTestPool,
1597- bool fBlock , bool fMiner , MapPrevTx& inputsRet, bool & fInvalid , bool fAcceptBlock ) const
1579+ bool fBlock , bool fMiner , MapPrevTx& inputsRet, bool & fInvalid ) const
15981580{
15991581 // FetchInputs can return false either because we just haven't seen some inputs
16001582 // (in which case the transaction should be stored as an orphan)
@@ -1632,54 +1614,39 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTes
16321614 if (!fFound || txindex.pos == CDiskTxPos (1 ,1 ,1 ))
16331615 {
16341616 // Get prev tx from single transactions in memory
1635- if (!mempool.lookup (prevout.hash , txPrev)) {
1636- if (!fAcceptBlock ) {
1637- return error (" FetchInputs() : %s mempool Tx prev not found %s" , GetHash ().ToString (), prevout.hash .ToString ());
1638- } else {
1639- LogPrintf (" FetchInputs() : fAcceptBlock toggled, Skipping mempool Tx prev not found error \n " );
1640- }
1641- }
1642- if (!fFound ) {
1617+ if (!mempool.lookup (prevout.hash , txPrev))
1618+ return error (" FetchInputs() : %s mempool Tx prev not found %s" , GetHash ().ToString (), prevout.hash .ToString ());
1619+ if (!fFound )
16431620 txindex.vSpent .resize (txPrev.vout .size ());
1644- }
16451621 }
16461622 else
16471623 {
16481624 // Get prev tx from disk
1649- if (!txPrev.ReadFromDisk (txindex.pos )) {
1650- if (!fAcceptBlock ) {
1651- return error (" FetchInputs() : %s ReadFromDisk prev tx %s failed" , GetHash ().ToString (), prevout.hash .ToString ());
1652- } else {
1653- LogPrintf (" FetchInputs() : fAcceptBlock toggled, Skipping ReadFromDisk Tx prev not found error \n " );
1654- }
1655- }
1625+ if (!txPrev.ReadFromDisk (txindex.pos ))
1626+ return error (" FetchInputs() : %s ReadFromDisk prev tx %s failed" , GetHash ().ToString (), prevout.hash .ToString ());
16561627 }
16571628 }
16581629
1659- if (!fAcceptBlock ) {
1660- // Make sure all prevout.n indexes are valid:
1661- for (unsigned int i = 0 ; i < vin.size (); i++)
1630+ // Make sure all prevout.n indexes are valid:
1631+ for (unsigned int i = 0 ; i < vin.size (); i++)
1632+ {
1633+ const COutPoint prevout = vin[i].prevout ;
1634+ assert (inputsRet.count (prevout.hash ) != 0 );
1635+ const CTxIndex& txindex = inputsRet[prevout.hash ].first ;
1636+ const CTransaction& txPrev = inputsRet[prevout.hash ].second ;
1637+ if (prevout.n >= txPrev.vout .size () || prevout.n >= txindex.vSpent .size ())
16621638 {
1663- const COutPoint prevout = vin[i].prevout ;
1664- assert (inputsRet.count (prevout.hash ) != 0 );
1665- const CTxIndex& txindex = inputsRet[prevout.hash ].first ;
1666- const CTransaction& txPrev = inputsRet[prevout.hash ].second ;
1667- if (prevout.n >= txPrev.vout .size () || prevout.n >= txindex.vSpent .size ())
1668- {
1669- // Revisit this if/when transaction replacement is implemented and allows
1670- // adding inputs:
1671- fInvalid = true ;
1672- return DoS (100 , error (" FetchInputs() : %s prevout.n out of range %d %u %u prev tx %s\n %s" , GetHash ().ToString (), prevout.n , txPrev.vout .size (), txindex.vSpent .size (), prevout.hash .ToString (), txPrev.ToString ()));
1673- }
1639+ // Revisit this if/when transaction replacement is implemented and allows
1640+ // adding inputs:
1641+ fInvalid = true ;
1642+ return DoS (100 , error (" FetchInputs() : %s prevout.n out of range %d %u %u prev tx %s\n %s" , GetHash ().ToString (), prevout.n , txPrev.vout .size (), txindex.vSpent .size (), prevout.hash .ToString (), txPrev.ToString ()));
16741643 }
1675- } else {
1676- LogPrintf (" FetchInputs() : fAcceptBlock toggled, Skipping prevout.n validation \n " );
16771644 }
16781645
16791646 return true ;
16801647}
16811648
1682- const CTxOut& CTransaction::GetOutputFor (const CTxIn& input, const MapPrevTx& inputs, bool fAcceptBlock ) const
1649+ const CTxOut& CTransaction::GetOutputFor (const CTxIn& input, const MapPrevTx& inputs) const
16831650{
16841651 MapPrevTx::const_iterator mi = inputs.find (input.prevout .hash );
16851652 if (mi == inputs.end ()) {
@@ -1689,26 +1656,22 @@ const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& in
16891656 const CTransaction& txPrev = (mi->second ).second ;
16901657 // Don't allow oversized outputs
16911658 if (input.prevout .n >= txPrev.vout .size ()) {
1692- // Skip if queried by AcceptBlock()
1693- if (!fAcceptBlock ) {
1694- throw std::runtime_error (" CTransaction::GetOutputFor() : prevout.n out of range" );
1695- }
1659+ throw std::runtime_error (" CTransaction::GetOutputFor() : prevout.n out of range" );
16961660 }
16971661
16981662 return txPrev.vout [input.prevout .n ];
16991663}
17001664
1701- int64_t CTransaction::GetValueMapIn (const MapPrevTx& inputs, bool fAcceptBlock ) const
1665+ int64_t CTransaction::GetValueMapIn (const MapPrevTx& inputs) const
17021666{
17031667 if (IsCoinBase ())
17041668 return 0 ;
17051669
17061670 int64_t nResult = 0 ;
17071671 for (unsigned int i = 0 ; i < vin.size (); i++)
17081672 {
1709- nResult += GetOutputFor (vin[i], inputs, fAcceptBlock ).nValue ;
1673+ nResult += GetOutputFor (vin[i], inputs).nValue ;
17101674 }
1711-
17121675 return nResult;
17131676
17141677}
@@ -1927,7 +1890,7 @@ void CBlock::RebuildAddressIndex(CTxDB& txdb)
19271890 MapPrevTx mapInputs;
19281891 map<uint256, CTxIndex> mapQueuedChangesT;
19291892 bool fInvalid ;
1930- if (!tx.FetchInputs (txdb, mapQueuedChangesT, true , false , mapInputs, fInvalid , false ))
1893+ if (!tx.FetchInputs (txdb, mapQueuedChangesT, true , false , mapInputs, fInvalid ))
19311894 return ;
19321895
19331896 MapPrevTx::const_iterator mi;
@@ -2010,7 +1973,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
20101973 else
20111974 {
20121975 bool fInvalid ;
2013- if (!tx.FetchInputs (txdb, mapQueuedChanges, true , false , mapInputs, fInvalid , false ))
1976+ if (!tx.FetchInputs (txdb, mapQueuedChanges, true , false , mapInputs, fInvalid ))
20141977 return false ;
20151978
20161979 // Add in sigops done by pay-to-script-hash inputs;
@@ -2020,7 +1983,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
20201983 if (nSigOps > MAX_BLOCK_SIGOPS)
20211984 return DoS (100 , error (" ConnectBlock() : too many sigops" ));
20221985
2023- int64_t nTxValueIn = tx.GetValueMapIn (mapInputs, false );
1986+ int64_t nTxValueIn = tx.GetValueMapIn (mapInputs);
20241987 int64_t nTxValueOut = tx.GetValueOut ();
20251988 nValueIn += nTxValueIn;
20261989 nValueOut += nTxValueOut;
@@ -2092,7 +2055,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
20922055 MapPrevTx mapInputs;
20932056 map<uint256, CTxIndex> mapQueuedChangesT;
20942057 bool fInvalid ;
2095- if (!tx.FetchInputs (txdb, mapQueuedChangesT, true , false , mapInputs, fInvalid , false ))
2058+ if (!tx.FetchInputs (txdb, mapQueuedChangesT, true , false , mapInputs, fInvalid ))
20962059 return false ;
20972060
20982061 MapPrevTx::const_iterator mi;
@@ -2965,42 +2928,12 @@ bool CBlock::AcceptBlock()
29652928 if (GetBlockTime () <= pindexPrev->GetPastTimeLimit () || FutureDrift (GetBlockTime ()) < pindexPrev->GetBlockTime ())
29662929 return error (" AcceptBlock() : block's timestamp is too early" );
29672930
2968- // Set logged values
2969- CAmount tx_inputs_values = 0 ;
2970- CAmount tx_outputs_values = 0 ;
2971- CAmount tx_MapIn_values = 0 ;
2972- CAmount tx_threshold = (300 * COIN);
29732931 // Check that all transactions are finalized
29742932 BOOST_FOREACH (const CTransaction& tx, vtx)
29752933 {
29762934 if (!IsFinalTx (tx, nHeight, GetBlockTime ())) {
29772935 return DoS (10 , error (" AcceptBlock() : contains a non-final transaction" ));
29782936 }
2979- // Log inputs/output values
2980- MapPrevTx mapInputs;
2981- tx.GetMapTxInputs (mapInputs, true );
2982- tx_MapIn_values = tx.GetValueMapIn (mapInputs, true );
2983- // Log inputs/output values
2984- if ((tx_inputs_values + tx_MapIn_values) >= 0 )
2985- {
2986- tx_inputs_values += tx_MapIn_values;
2987- } else {
2988- return DoS (10 , error (" AcceptBlock() : overflow detected tx_inputs_values + tx.GetValueMapIn(mapInputs)" ));
2989- }
2990- if (tx_outputs_values + tx.GetValueOut () >= 0 )
2991- {
2992- tx_outputs_values += tx.GetValueOut ();
2993- } else {
2994- return DoS (10 , error (" AcceptBlock() : overflow detected tx_outputs_values + tx.GetValueOut()" ));
2995- }
2996- }
2997-
2998- // Ensure input/output sanity of transactions in the block
2999- if ((tx_inputs_values + tx_threshold) < tx_outputs_values)
3000- {
3001- if (nHeight > 175 ) {
3002- return DoS (100 , error (" AcceptBlock() : block contains a tx input that is less that output" ));
3003- }
30042937 }
30052938
30062939 // Check that the block chain matches the known block chain up to a checkpoint
0 commit comments