Merge branch 'dev' of https://github.com/jl777/komodo into trunk-merge
* 'dev' of https://github.com/jl777/komodo: (1062 commits) Delay PoW check until connect block Declare KOMODO_NEWBLOCKS Prevent autorewind if syncing. Not a critical update Change n0/n1 size to int32_t Syntax Fix n -> static n0/n1 Test Test Test KOMODO_LONGESTCHAIN = height; Sync main.cpp to jl777 -print -USD/EUR readme curl fix -print Fix buffer overflows and reduce KMD men usage -print Test ...
This commit is contained in:
@@ -15,6 +15,10 @@
|
||||
#include "primitives/transaction.h"
|
||||
#include "sync.h"
|
||||
|
||||
#undef foreach
|
||||
#include "boost/multi_index_container.hpp"
|
||||
#include "boost/multi_index/ordered_index.hpp"
|
||||
|
||||
class CAutoFile;
|
||||
|
||||
inline double AllowFreeThreshold()
|
||||
@@ -43,25 +47,54 @@ private:
|
||||
size_t nTxSize; //! ... and avoid recomputing tx size
|
||||
size_t nModSize; //! ... and modified size for priority
|
||||
size_t nUsageSize; //! ... and total memory usage
|
||||
CFeeRate feeRate; //! ... and fee per kB
|
||||
int64_t nTime; //! Local time when entering the mempool
|
||||
double dPriority; //! Priority when entering the mempool
|
||||
unsigned int nHeight; //! Chain height when entering the mempool
|
||||
bool hadNoDependencies; //! Not dependent on any other txs when it entered the mempool
|
||||
bool spendsCoinbase; //! keep track of transactions that spend a coinbase
|
||||
uint32_t nBranchId; //! Branch ID this transaction is known to commit to, cached for efficiency
|
||||
|
||||
public:
|
||||
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
|
||||
int64_t _nTime, double _dPriority, unsigned int _nHeight, bool poolHasNoInputsOf = false);
|
||||
int64_t _nTime, double _dPriority, unsigned int _nHeight,
|
||||
bool poolHasNoInputsOf, bool spendsCoinbase, uint32_t nBranchId);
|
||||
CTxMemPoolEntry();
|
||||
CTxMemPoolEntry(const CTxMemPoolEntry& other);
|
||||
|
||||
const CTransaction& GetTx() const { return this->tx; }
|
||||
double GetPriority(unsigned int currentHeight) const;
|
||||
CAmount GetFee() const { return nFee; }
|
||||
CFeeRate GetFeeRate() const { return feeRate; }
|
||||
size_t GetTxSize() const { return nTxSize; }
|
||||
int64_t GetTime() const { return nTime; }
|
||||
unsigned int GetHeight() const { return nHeight; }
|
||||
bool WasClearAtEntry() const { return hadNoDependencies; }
|
||||
size_t DynamicMemoryUsage() const { return nUsageSize; }
|
||||
|
||||
bool GetSpendsCoinbase() const { return spendsCoinbase; }
|
||||
uint32_t GetValidatedBranchId() const { return nBranchId; }
|
||||
};
|
||||
|
||||
// extracts a TxMemPoolEntry's transaction hash
|
||||
struct mempoolentry_txid
|
||||
{
|
||||
typedef uint256 result_type;
|
||||
result_type operator() (const CTxMemPoolEntry &entry) const
|
||||
{
|
||||
return entry.GetTx().GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
class CompareTxMemPoolEntryByFee
|
||||
{
|
||||
public:
|
||||
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b)
|
||||
{
|
||||
if (a.GetFeeRate() == b.GetFeeRate())
|
||||
return a.GetTime() < b.GetTime();
|
||||
return a.GetFeeRate() > b.GetFeeRate();
|
||||
}
|
||||
};
|
||||
|
||||
class CBlockPolicyEstimator;
|
||||
@@ -93,7 +126,7 @@ public:
|
||||
class CTxMemPool
|
||||
{
|
||||
private:
|
||||
bool fSanityCheck; //! Normally false, true if -checkmempool or -regtest
|
||||
uint32_t nCheckFrequency; //! Value n means that n times in 2^32 we check.
|
||||
unsigned int nTransactionsUpdated;
|
||||
CBlockPolicyEstimator* minerPolicyEstimator;
|
||||
|
||||
@@ -101,8 +134,21 @@ private:
|
||||
uint64_t cachedInnerUsage; //! sum of dynamic memory usage of all the map elements (NOT the maps themselves)
|
||||
|
||||
public:
|
||||
typedef boost::multi_index_container<
|
||||
CTxMemPoolEntry,
|
||||
boost::multi_index::indexed_by<
|
||||
// sorted by txid
|
||||
boost::multi_index::ordered_unique<mempoolentry_txid>,
|
||||
// sorted by fee rate
|
||||
boost::multi_index::ordered_non_unique<
|
||||
boost::multi_index::identity<CTxMemPoolEntry>,
|
||||
CompareTxMemPoolEntryByFee
|
||||
>
|
||||
>
|
||||
> indexed_transaction_set;
|
||||
|
||||
mutable CCriticalSection cs;
|
||||
std::map<uint256, CTxMemPoolEntry> mapTx;
|
||||
indexed_transaction_set mapTx;
|
||||
|
||||
private:
|
||||
typedef std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare> addressDeltaMap;
|
||||
@@ -132,7 +178,7 @@ public:
|
||||
* check does nothing.
|
||||
*/
|
||||
void check(const CCoinsViewCache *pcoins) const;
|
||||
void setSanityCheck(bool _fSanityCheck) { fSanityCheck = _fSanityCheck; }
|
||||
void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967296.0; }
|
||||
|
||||
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true);
|
||||
void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
|
||||
@@ -145,10 +191,12 @@ public:
|
||||
bool removeSpentIndex(const uint256 txhash);
|
||||
void remove(const CTransaction &tx, std::list<CTransaction>& removed, bool fRecursive = false);
|
||||
void removeWithAnchor(const uint256 &invalidRoot);
|
||||
void removeCoinbaseSpends(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight);
|
||||
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
|
||||
void removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed);
|
||||
void removeExpired(unsigned int nBlockHeight);
|
||||
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
|
||||
std::list<CTransaction>& conflicts, bool fCurrentEstimate = true);
|
||||
void removeWithoutBranchId(uint32_t nMemPoolBranchId);
|
||||
void clear();
|
||||
void queryHashes(std::vector<uint256>& vtxid);
|
||||
void pruneSpent(const uint256& hash, CCoins &coins);
|
||||
|
||||
Reference in New Issue
Block a user