// 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 <list>
+#include "addressindex.h"
+#include "spentindex.h"
#include "amount.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"
#include "boost/multi_index/ordered_index.hpp"
+#include "pbaas/reserves.h"
+
class CAutoFile;
inline double AllowFreeThreshold()
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 hold reserve currency
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, bool spendsCoinbase, uint32_t nBranchId);
+ bool poolHasNoInputsOf, bool spendsCoinbase, uint32_t nBranchId, bool hasreserve=false);
CTxMemPoolEntry();
CTxMemPoolEntry(const CTxMemPoolEntry& other);
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;
- void checkNullifiers(NullifierType type) const;
+ std::map<uint256, std::pair<double, CAmount> > mapDeltas;
+ std::map<uint256, CReserveTransactionDescriptor> mapReserveTransactions; // all reserve transactions in the mempool go here
+
+ void checkNullifiers(ShieldedType type) const;
public:
typedef boost::multi_index_container<
mutable CCriticalSection cs;
indexed_transaction_set mapTx;
+
+private:
+ 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;
- std::map<uint256, std::pair<double, CAmount> > mapDeltas;
CTxMemPool(const CFeeRate& _minRelayFee);
~CTxMemPool();
void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = static_cast<uint32_t>(dFrequency * 4294967295.0); }
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true);
+ void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
+ 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(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);
+ 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,
bool HasNoInputsOf(const CTransaction& tx) const;
/** Affect CreateNewBlock prioritisation of transactions */
- void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount& nFeeDelta);
+ void PrioritiseTransaction(const uint256 &hash, const std::string strHash, double dPriorityDelta, const CAmount& nFeeDelta);
+ 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, NullifierType type) const;
+ bool nullifierExists(const uint256& nullifier, ShieldedType type) const;
+
+ void NotifyRecentlyAdded();
+ bool IsFullyNotified();
unsigned long size()
{
public:
CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn);
- bool GetNullifier(const uint256 &txid, NullifierType type) const;
+ bool GetNullifier(const uint256 &txid, ShieldedType type) const;
bool GetCoins(const uint256 &txid, CCoins &coins) const;
bool HaveCoins(const uint256 &txid) const;
};