// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// file COPYING or https://www.opensource.org/licenses/mit-license.php .
#ifndef BITCOIN_TXMEMPOOL_H
#define BITCOIN_TXMEMPOOL_H
#include "coins.h"
#include "primitives/transaction.h"
#include "sync.h"
+#include "addressindex.h"
+#include "spentindex.h"
#undef foreach
#include "boost/multi_index_container.hpp"
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
- bool hasReserve; //! keep track of transactions that spend a coinbase
+ bool hasReserve; //! keep track of transactions that hold reserve currency
uint32_t nBranchId; //! Branch ID this transaction is known to commit to, cached for efficiency
public:
class CTxMemPool
{
private:
- uint32_t nCheckFrequency; //! Value n means that n times in 2^32 we check.
+ uint32_t nCheckFrequency; //!< Value n means that n times in 2^32 we check.
unsigned int nTransactionsUpdated;
CBlockPolicyEstimator* minerPolicyEstimator;
- uint64_t totalTxSize = 0; //! sum of all mempool tx' byte sizes
- uint64_t cachedInnerUsage; //! sum of dynamic memory usage of all the map elements (NOT the maps themselves)
+ uint64_t totalTxSize = 0; //!< sum of all mempool tx' byte sizes
+ uint64_t cachedInnerUsage; //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
+
+ std::map<uint256, const CTransaction*> mapRecentlyAddedTx;
+ uint64_t nRecentlyAddedSequence = 0;
+ uint64_t nNotifiedSequence = 0;
std::map<uint256, const CTransaction*> mapSproutNullifiers;
std::map<uint256, const CTransaction*> mapSaplingNullifiers;
indexed_transaction_set mapTx;
private:
- typedef std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare> addressDeltaMap;
- addressDeltaMap mapAddress;
-
- typedef std::map<uint256, std::vector<CMempoolAddressDeltaKey> > addressDeltaMapInserted;
- addressDeltaMapInserted mapAddressInserted;
-
- typedef std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mapSpentIndex;
- mapSpentIndex mapSpent;
-
- typedef std::map<uint256, std::vector<CSpentIndexKey> > mapSpentIndexInserted;
- mapSpentIndexInserted mapSpentInserted;
+ std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare> mapAddress;
+ std::map<uint256, std::vector<CMempoolAddressDeltaKey> > mapAddressInserted;
+ std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mapSpent;
+ std::map<uint256, std::vector<CSpentIndexKey>> mapSpentInserted;
public:
std::map<COutPoint, CInPoint> mapNextTx;
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true);
void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
- bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses,
- std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
+ bool getAddressIndex(const std::vector<std::pair<uint160, int> > &addresses, std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
bool removeAddressIndex(const uint256 txhash);
void addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
- bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
+ bool getSpentIndex(const CSpentIndexKey &key, CSpentIndexValue &value);
bool removeSpentIndex(const uint256 txhash);
void remove(const CTransaction &tx, std::list<CTransaction>& removed, bool fRecursive = false);
void removeWithAnchor(const uint256 &invalidRoot, ShieldedType type);
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
+ bool checkNameConflicts(const CTransaction &tx, std::list<CTransaction> &conflicting);
void removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed);
void removeExpired(unsigned int nBlockHeight);
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
/** Affect CreateNewBlock prioritisation of transactions */
void PrioritiseTransaction(const uint256 &hash, const std::string strHash, double dPriorityDelta, const CAmount& nFeeDelta);
- void PrioritiseReserveTransaction(const CReserveTransactionDescriptor &txDesc, const CCurrencyState ¤cyState);
- bool IsKnownReserveTransaction(const uint256 &hash, CReserveTransactionDescriptor &txDesc) const; // know to be reserve transaction, get descriptor
+ bool PrioritiseReserveTransaction(const CReserveTransactionDescriptor &txDesc, const CCurrencyState ¤cyState);
+ bool IsKnownReserveTransaction(const uint256 &hash, CReserveTransactionDescriptor &txDesc); // know to be reserve transaction, get descriptor, update mempool
void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta);
void ClearPrioritisation(const uint256 hash);
bool nullifierExists(const uint256& nullifier, ShieldedType type) const;
+ void NotifyRecentlyAdded();
+ bool IsFullyNotified();
+
unsigned long size()
{
LOCK(cs);