Browse Source

Merge pull request #5292

7329fdd Update comments in txmempool to be doxygen compatible (Michael Ford)
0.10
Wladimir J. van der Laan 10 years ago
parent
commit
47cb3606a3
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 38
      src/txmempool.cpp
  2. 44
      src/txmempool.h

38
src/txmempool.cpp

@ -1,6 +1,6 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2013 The Bitcoin developers // Copyright (c) 2009-2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "txmempool.h" #include "txmempool.h"
@ -45,9 +45,9 @@ CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const
return dResult; return dResult;
} }
// /**
// Keep track of fee/priority for transactions confirmed within N blocks * Keep track of fee/priority for transactions confirmed within N blocks
// */
class CBlockAverage class CBlockAverage
{ {
private: private:
@ -86,8 +86,10 @@ public:
return prioritySamples.size(); return prioritySamples.size();
} }
// Used as belt-and-suspenders check when reading to detect /**
// file corruption * Used as belt-and-suspenders check when reading to detect
* file corruption
*/
bool AreSane(const std::vector<CFeeRate>& vecFee, const CFeeRate& minRelayFee) bool AreSane(const std::vector<CFeeRate>& vecFee, const CFeeRate& minRelayFee)
{ {
BOOST_FOREACH(CFeeRate fee, vecFee) BOOST_FOREACH(CFeeRate fee, vecFee)
@ -139,16 +141,20 @@ public:
class CMinerPolicyEstimator class CMinerPolicyEstimator
{ {
private: private:
// Records observed averages transactions that confirmed within one block, two blocks, /**
// three blocks etc. * Records observed averages transactions that confirmed within one block, two blocks,
* three blocks etc.
*/
std::vector<CBlockAverage> history; std::vector<CBlockAverage> history;
std::vector<CFeeRate> sortedFeeSamples; std::vector<CFeeRate> sortedFeeSamples;
std::vector<double> sortedPrioritySamples; std::vector<double> sortedPrioritySamples;
int nBestSeenHeight; int nBestSeenHeight;
// nBlocksAgo is 0 based, i.e. transactions that confirmed in the highest seen block are /**
// nBlocksAgo == 0, transactions in the block before that are nBlocksAgo == 1 etc. * nBlocksAgo is 0 based, i.e. transactions that confirmed in the highest seen block are
* nBlocksAgo == 0, transactions in the block before that are nBlocksAgo == 1 etc.
*/
void seenTxConfirm(const CFeeRate& feeRate, const CFeeRate& minRelayFee, double dPriority, int nBlocksAgo) void seenTxConfirm(const CFeeRate& feeRate, const CFeeRate& minRelayFee, double dPriority, int nBlocksAgo)
{ {
// Last entry records "everything else". // Last entry records "everything else".
@ -248,7 +254,9 @@ public:
} }
} }
// Can return CFeeRate(0) if we don't have any data for that many blocks back. nBlocksToConfirm is 1 based. /**
* Can return CFeeRate(0) if we don't have any data for that many blocks back. nBlocksToConfirm is 1 based.
*/
CFeeRate estimateFee(int nBlocksToConfirm) CFeeRate estimateFee(int nBlocksToConfirm)
{ {
nBlocksToConfirm--; nBlocksToConfirm--;
@ -332,7 +340,7 @@ public:
size_t numEntries; size_t numEntries;
filein >> numEntries; filein >> numEntries;
if (numEntries <= 0 || numEntries > 10000) if (numEntries <= 0 || numEntries > 10000)
throw runtime_error("Corrupt estimates file. Must have between 1 and 10k entires."); throw runtime_error("Corrupt estimates file. Must have between 1 and 10k entries.");
std::vector<CBlockAverage> fileHistory; std::vector<CBlockAverage> fileHistory;
@ -462,7 +470,9 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
} }
} }
// Called when a block is connected. Removes from mempool and updates the miner fee estimator. /**
* Called when a block is connected. Removes from mempool and updates the miner fee estimator.
*/
void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight, void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
std::list<CTransaction>& conflicts) std::list<CTransaction>& conflicts)
{ {

44
src/txmempool.h

@ -1,6 +1,6 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2013 The Bitcoin developers // Copyright (c) 2009-2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TXMEMPOOL_H #ifndef BITCOIN_TXMEMPOOL_H
@ -25,19 +25,19 @@ inline bool AllowFree(double dPriority)
/** Fake height value used in CCoins to signify they are only in the memory pool (since 0.8) */ /** Fake height value used in CCoins to signify they are only in the memory pool (since 0.8) */
static const unsigned int MEMPOOL_HEIGHT = 0x7FFFFFFF; static const unsigned int MEMPOOL_HEIGHT = 0x7FFFFFFF;
/* /**
* CTxMemPool stores these: * CTxMemPool stores these:
*/ */
class CTxMemPoolEntry class CTxMemPoolEntry
{ {
private: private:
CTransaction tx; CTransaction tx;
CAmount nFee; // Cached to avoid expensive parent-transaction lookups CAmount nFee; //! Cached to avoid expensive parent-transaction lookups
size_t nTxSize; // ... and avoid recomputing tx size size_t nTxSize; //! ... and avoid recomputing tx size
size_t nModSize; // ... and modified size for priority size_t nModSize; //! ... and modified size for priority
int64_t nTime; // Local time when entering the mempool int64_t nTime; //! Local time when entering the mempool
double dPriority; // Priority when entering the mempool double dPriority; //! Priority when entering the mempool
unsigned int nHeight; // Chain height when entering the mempool unsigned int nHeight; //! Chain height when entering the mempool
public: public:
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee, CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
@ -68,7 +68,7 @@ public:
bool IsNull() const { return (ptx == NULL && n == (uint32_t) -1); } bool IsNull() const { return (ptx == NULL && n == (uint32_t) -1); }
}; };
/* /**
* CTxMemPool stores valid-according-to-the-current-best-chain * CTxMemPool stores valid-according-to-the-current-best-chain
* transactions that may be included in the next block. * transactions that may be included in the next block.
* *
@ -81,12 +81,12 @@ public:
class CTxMemPool class CTxMemPool
{ {
private: private:
bool fSanityCheck; // Normally false, true if -checkmempool or -regtest bool fSanityCheck; //! Normally false, true if -checkmempool or -regtest
unsigned int nTransactionsUpdated; unsigned int nTransactionsUpdated;
CMinerPolicyEstimator* minerPolicyEstimator; CMinerPolicyEstimator* minerPolicyEstimator;
CFeeRate minRelayFee; // Passed to constructor to avoid dependency on main CFeeRate minRelayFee; //! Passed to constructor to avoid dependency on main
uint64_t totalTxSize; // sum of all mempool tx' byte sizes uint64_t totalTxSize; //! sum of all mempool tx' byte sizes
public: public:
mutable CCriticalSection cs; mutable CCriticalSection cs;
@ -97,7 +97,7 @@ public:
CTxMemPool(const CFeeRate& _minRelayFee); CTxMemPool(const CFeeRate& _minRelayFee);
~CTxMemPool(); ~CTxMemPool();
/* /**
* If sanity-checking is turned on, check makes sure the pool is * If sanity-checking is turned on, check makes sure the pool is
* consistent (does not contain two transactions that spend the same inputs, * consistent (does not contain two transactions that spend the same inputs,
* all inputs are in the mapNextTx array). If sanity-checking is turned off, * all inputs are in the mapNextTx array). If sanity-checking is turned off,
@ -141,19 +141,21 @@ public:
bool lookup(uint256 hash, CTransaction& result) const; bool lookup(uint256 hash, CTransaction& result) const;
// Estimate fee rate needed to get into the next /** Estimate fee rate needed to get into the next nBlocks */
// nBlocks
CFeeRate estimateFee(int nBlocks) const; CFeeRate estimateFee(int nBlocks) const;
// Estimate priority needed to get into the next
// nBlocks /** Estimate priority needed to get into the next nBlocks */
double estimatePriority(int nBlocks) const; double estimatePriority(int nBlocks) const;
// Write/Read estimates to disk
/** Write/Read estimates to disk */
bool WriteFeeEstimates(CAutoFile& fileout) const; bool WriteFeeEstimates(CAutoFile& fileout) const;
bool ReadFeeEstimates(CAutoFile& filein); bool ReadFeeEstimates(CAutoFile& filein);
}; };
/** CCoinsView that brings transactions from a memorypool into view. /**
It does not check for spendings by memory pool transactions. */ * CCoinsView that brings transactions from a memorypool into view.
* It does not check for spendings by memory pool transactions.
*/
class CCoinsViewMemPool : public CCoinsViewBacked class CCoinsViewMemPool : public CCoinsViewBacked
{ {
protected: protected:

Loading…
Cancel
Save