Direct CCoins references
To prevent excessive copying of CCoins in and out of the CCoinsView implementations, introduce a GetCoins() function in CCoinsViewCache with returns a direct reference. The block validation and connection logic is updated to require caching CCoinsViews, and exploits the GetCoins() function heavily.
This commit is contained in:
23
src/main.h
23
src/main.h
@@ -88,6 +88,7 @@ class CDiskBlockPos;
|
||||
class CCoins;
|
||||
class CTxUndo;
|
||||
class CCoinsView;
|
||||
class CCoinsViewCache;
|
||||
|
||||
void RegisterWallet(CWallet* pwalletIn);
|
||||
void UnregisterWallet(CWallet* pwalletIn);
|
||||
@@ -480,7 +481,7 @@ public:
|
||||
@return True if all inputs (scriptSigs) use only standard transaction forms
|
||||
@see CTransaction::FetchInputs
|
||||
*/
|
||||
bool AreInputsStandard(CCoinsView& mapInputs) const;
|
||||
bool AreInputsStandard(CCoinsViewCache& mapInputs) const;
|
||||
|
||||
/** Count ECDSA signature operations the old-fashioned (pre-0.6) way
|
||||
@return number of sigops this transaction's outputs will produce when spent
|
||||
@@ -494,7 +495,7 @@ public:
|
||||
@return maximum number of sigops required to validate this transaction's inputs
|
||||
@see CTransaction::FetchInputs
|
||||
*/
|
||||
unsigned int GetP2SHSigOpCount(CCoinsView& mapInputs) const;
|
||||
unsigned int GetP2SHSigOpCount(CCoinsViewCache& mapInputs) const;
|
||||
|
||||
/** Amount of bitcoins spent by this transaction.
|
||||
@return sum of all outputs (note: does not include fees)
|
||||
@@ -519,7 +520,7 @@ public:
|
||||
@return Sum of value of all inputs (scriptSigs)
|
||||
@see CTransaction::FetchInputs
|
||||
*/
|
||||
int64 GetValueIn(CCoinsView& mapInputs) const;
|
||||
int64 GetValueIn(CCoinsViewCache& mapInputs) const;
|
||||
|
||||
static bool AllowFree(double dPriority)
|
||||
{
|
||||
@@ -570,14 +571,14 @@ public:
|
||||
bool ClientCheckInputs() const;
|
||||
|
||||
// Check whether all prevouts of this transaction are present in the UTXO set represented by view
|
||||
bool HaveInputs(CCoinsView &view) const;
|
||||
bool HaveInputs(CCoinsViewCache &view) const;
|
||||
|
||||
// Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts)
|
||||
// This does not modify the UTXO set
|
||||
bool CheckInputs(CCoinsView &view, enum CheckSig_mode csmode, bool fStrictPayToScriptHash=true, bool fStrictEncodings=true) const;
|
||||
bool CheckInputs(CCoinsViewCache &view, enum CheckSig_mode csmode, bool fStrictPayToScriptHash=true, bool fStrictEncodings=true) const;
|
||||
|
||||
// Apply the effects of this transaction on the UTXO set represented by view
|
||||
bool UpdateCoins(CCoinsView &view, CTxUndo &txundo, int nHeight, const uint256 &txhash) const;
|
||||
bool UpdateCoins(CCoinsViewCache &view, CTxUndo &txundo, int nHeight, const uint256 &txhash) const;
|
||||
|
||||
// Context-independent validity checks
|
||||
bool CheckTransaction() const;
|
||||
@@ -586,7 +587,7 @@ public:
|
||||
bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL);
|
||||
|
||||
protected:
|
||||
static CTxOut GetOutputFor(const CTxIn& input, CCoinsView& mapInputs);
|
||||
static const CTxOut &GetOutputFor(const CTxIn& input, CCoinsViewCache& mapInputs);
|
||||
};
|
||||
|
||||
/** wrapper for CTxOut that provides a more compact serialization */
|
||||
@@ -1225,10 +1226,10 @@ public:
|
||||
|
||||
|
||||
// Undo the effects of this block (with given index) on the UTXO set represented by coins
|
||||
bool DisconnectBlock(CBlockIndex *pindex, CCoinsView &coins);
|
||||
bool DisconnectBlock(CBlockIndex *pindex, CCoinsViewCache &coins);
|
||||
|
||||
// Apply the effects of this block (with given index) on the UTXO set represented by coins
|
||||
bool ConnectBlock(CBlockIndex *pindex, CCoinsView &coins, bool fJustCheck=false);
|
||||
bool ConnectBlock(CBlockIndex *pindex, CCoinsViewCache &coins, bool fJustCheck=false);
|
||||
|
||||
// Read a block from disk
|
||||
bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);
|
||||
@@ -1759,11 +1760,15 @@ public:
|
||||
bool GetCoins(uint256 txid, CCoins &coins);
|
||||
bool SetCoins(uint256 txid, const CCoins &coins);
|
||||
bool HaveCoins(uint256 txid);
|
||||
CCoins &GetCoins(uint256 txid);
|
||||
CBlockIndex *GetBestBlock();
|
||||
bool SetBestBlock(CBlockIndex *pindex);
|
||||
bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
|
||||
bool Flush();
|
||||
unsigned int GetCacheSize();
|
||||
|
||||
private:
|
||||
std::map<uint256,CCoins>::iterator FetchCoins(uint256 txid);
|
||||
};
|
||||
|
||||
/** CCoinsView that brings transactions from a memorypool into view.
|
||||
|
||||
Reference in New Issue
Block a user