mapNextTx: use pointer as key, simplify value
Saves about 10% of application memory usage once the mempool warms up. Since the mempool is DynamicUsage-regulated, this will translate to a larger mempool in the same amount of space. Map value type: eliminate the vin index; no users of the map need to know which input of the transaction is spending the prevout. Map key type: replace the COutPoint with a pointer to a COutPoint. A COutPoint is 36 bytes, but each COutPoint is accessible from the same map entry's value. A trivial DereferencingComparator functor allows indirect map keys, but the resulting syntax is misleading: `map.find(&outpoint)`. Implement an indirectmap that acts as a wrapper to a map that uses a DereferencingComparator, supporting a syntax that accurately reflect the container's semantics: inserts and iterators use pointers since they store pointers and need them to remain constant and dereferenceable, but lookup functions take const references.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "amount.h"
|
||||
#include "coins.h"
|
||||
#include "indirectmap.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "sync.h"
|
||||
|
||||
@@ -305,20 +306,6 @@ struct ancestor_score {};
|
||||
|
||||
class CBlockPolicyEstimator;
|
||||
|
||||
/** An inpoint - a combination of a transaction and an index n into its vin */
|
||||
class CInPoint
|
||||
{
|
||||
public:
|
||||
const CTransaction* ptx;
|
||||
uint32_t n;
|
||||
|
||||
CInPoint() { SetNull(); }
|
||||
CInPoint(const CTransaction* ptxIn, uint32_t nIn) { ptx = ptxIn; n = nIn; }
|
||||
void SetNull() { ptx = NULL; n = (uint32_t) -1; }
|
||||
bool IsNull() const { return (ptx == NULL && n == (uint32_t) -1); }
|
||||
size_t DynamicMemoryUsage() const { return 0; }
|
||||
};
|
||||
|
||||
/**
|
||||
* CTxMemPool stores valid-according-to-the-current-best-chain
|
||||
* transactions that may be included in the next block.
|
||||
@@ -477,7 +464,7 @@ private:
|
||||
void UpdateChild(txiter entry, txiter child, bool add);
|
||||
|
||||
public:
|
||||
std::map<COutPoint, CInPoint> mapNextTx;
|
||||
indirectmap<COutPoint, const CTransaction*> mapNextTx;
|
||||
std::map<uint256, std::pair<double, CAmount> > mapDeltas;
|
||||
|
||||
/** Create a new CTxMemPool.
|
||||
|
||||
Reference in New Issue
Block a user