@@ -32,6 +32,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
32
32
nTxSize = ::GetSerializeSize (tx, SER_NETWORK, PROTOCOL_VERSION);
33
33
nModSize = tx.CalculateModifiedSize (nTxSize);
34
34
nUsageSize = tx.DynamicMemoryUsage ();
35
+ feeRate = CFeeRate (nFee, nTxSize);
35
36
}
36
37
37
38
CTxMemPoolEntry::CTxMemPoolEntry (const CTxMemPoolEntry& other)
@@ -96,8 +97,8 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
96
97
// Used by main.cpp AcceptToMemoryPool(), which DOES do
97
98
// all the appropriate checks.
98
99
LOCK (cs);
99
- mapTx[hash] = entry;
100
- const CTransaction& tx = mapTx[hash]. GetTx ();
100
+ mapTx. insert ( entry) ;
101
+ const CTransaction& tx = mapTx. find (hash)-> GetTx ();
101
102
for (unsigned int i = 0 ; i < tx.vin .size (); i++)
102
103
mapNextTx[tx.vin [i].prevout ] = CInPoint (&tx, i);
103
104
nTransactionsUpdated++;
@@ -134,7 +135,7 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
134
135
txToRemove.pop_front ();
135
136
if (!mapTx.count (hash))
136
137
continue ;
137
- const CTransaction& tx = mapTx[hash]. GetTx ();
138
+ const CTransaction& tx = mapTx. find (hash)-> GetTx ();
138
139
if (fRecursive ) {
139
140
for (unsigned int i = 0 ; i < tx.vout .size (); i++) {
140
141
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find (COutPoint (hash, i));
@@ -147,8 +148,8 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
147
148
mapNextTx.erase (txin.prevout );
148
149
149
150
removed.push_back (tx);
150
- totalTxSize -= mapTx[hash]. GetTxSize ();
151
- cachedInnerUsage -= mapTx[hash]. DynamicMemoryUsage ();
151
+ totalTxSize -= mapTx. find (hash)-> GetTxSize ();
152
+ cachedInnerUsage -= mapTx. find (hash)-> DynamicMemoryUsage ();
152
153
mapTx.erase (hash);
153
154
nTransactionsUpdated++;
154
155
minerPolicyEstimator->removeTx (hash);
@@ -161,10 +162,10 @@ void CTxMemPool::removeCoinbaseSpends(const CCoinsViewCache *pcoins, unsigned in
161
162
// Remove transactions spending a coinbase which are now immature
162
163
LOCK (cs);
163
164
list<CTransaction> transactionsToRemove;
164
- for (std::map<uint256, CTxMemPoolEntry> ::const_iterator it = mapTx.begin (); it != mapTx.end (); it++) {
165
- const CTransaction& tx = it->second . GetTx ();
165
+ for (indexed_transaction_set ::const_iterator it = mapTx.begin (); it != mapTx.end (); it++) {
166
+ const CTransaction& tx = it->GetTx ();
166
167
BOOST_FOREACH (const CTxIn& txin, tx.vin ) {
167
- std::map<uint256, CTxMemPoolEntry> ::const_iterator it2 = mapTx.find (txin.prevout .hash );
168
+ indexed_transaction_set ::const_iterator it2 = mapTx.find (txin.prevout .hash );
168
169
if (it2 != mapTx.end ())
169
170
continue ;
170
171
const CCoins *coins = pcoins->AccessCoins (txin.prevout .hash );
@@ -209,8 +210,10 @@ void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned i
209
210
BOOST_FOREACH (const CTransaction& tx, vtx)
210
211
{
211
212
uint256 hash = tx.GetHash ();
212
- if (mapTx.count (hash))
213
- entries.push_back (mapTx[hash]);
213
+
214
+ indexed_transaction_set::iterator i = mapTx.find (hash);
215
+ if (i != mapTx.end ())
216
+ entries.push_back (*i);
214
217
}
215
218
BOOST_FOREACH (const CTransaction& tx, vtx)
216
219
{
@@ -247,17 +250,17 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
247
250
248
251
LOCK (cs);
249
252
list<const CTxMemPoolEntry*> waitingOnDependants;
250
- for (std::map<uint256, CTxMemPoolEntry> ::const_iterator it = mapTx.begin (); it != mapTx.end (); it++) {
253
+ for (indexed_transaction_set ::const_iterator it = mapTx.begin (); it != mapTx.end (); it++) {
251
254
unsigned int i = 0 ;
252
- checkTotal += it->second . GetTxSize ();
253
- innerUsage += it->second . DynamicMemoryUsage ();
254
- const CTransaction& tx = it->second . GetTx ();
255
+ checkTotal += it->GetTxSize ();
256
+ innerUsage += it->DynamicMemoryUsage ();
257
+ const CTransaction& tx = it->GetTx ();
255
258
bool fDependsWait = false ;
256
259
BOOST_FOREACH (const CTxIn &txin, tx.vin ) {
257
260
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
258
- std::map<uint256, CTxMemPoolEntry> ::const_iterator it2 = mapTx.find (txin.prevout .hash );
261
+ indexed_transaction_set ::const_iterator it2 = mapTx.find (txin.prevout .hash );
259
262
if (it2 != mapTx.end ()) {
260
- const CTransaction& tx2 = it2->second . GetTx ();
263
+ const CTransaction& tx2 = it2->GetTx ();
261
264
assert (tx2.vout .size () > txin.prevout .n && !tx2.vout [txin.prevout .n ].IsNull ());
262
265
fDependsWait = true ;
263
266
} else {
@@ -272,7 +275,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
272
275
i++;
273
276
}
274
277
if (fDependsWait )
275
- waitingOnDependants.push_back (&it-> second );
278
+ waitingOnDependants.push_back (&(*it) );
276
279
else {
277
280
CValidationState state;
278
281
assert (CheckInputs (tx, state, mempoolDuplicate, false , 0 , false , NULL ));
@@ -296,8 +299,8 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
296
299
}
297
300
for (std::map<COutPoint, CInPoint>::const_iterator it = mapNextTx.begin (); it != mapNextTx.end (); it++) {
298
301
uint256 hash = it->second .ptx ->GetHash ();
299
- map<uint256, CTxMemPoolEntry> ::const_iterator it2 = mapTx.find (hash);
300
- const CTransaction& tx = it2->second . GetTx ();
302
+ indexed_transaction_set ::const_iterator it2 = mapTx.find (hash);
303
+ const CTransaction& tx = it2->GetTx ();
301
304
assert (it2 != mapTx.end ());
302
305
assert (&tx == it->second .ptx );
303
306
assert (tx.vin .size () > it->second .n );
@@ -314,16 +317,16 @@ void CTxMemPool::queryHashes(vector<uint256>& vtxid)
314
317
315
318
LOCK (cs);
316
319
vtxid.reserve (mapTx.size ());
317
- for (map<uint256, CTxMemPoolEntry> ::iterator mi = mapTx.begin (); mi != mapTx.end (); ++mi)
318
- vtxid.push_back ((*mi). first );
320
+ for (indexed_transaction_set ::iterator mi = mapTx.begin (); mi != mapTx.end (); ++mi)
321
+ vtxid.push_back (mi-> GetTx (). GetHash () );
319
322
}
320
323
321
324
bool CTxMemPool::lookup (uint256 hash, CTransaction& result) const
322
325
{
323
326
LOCK (cs);
324
- map<uint256, CTxMemPoolEntry> ::const_iterator i = mapTx.find (hash);
327
+ indexed_transaction_set ::const_iterator i = mapTx.find (hash);
325
328
if (i == mapTx.end ()) return false ;
326
- result = i->second . GetTx ();
329
+ result = i->GetTx ();
327
330
return true ;
328
331
}
329
332
@@ -429,5 +432,6 @@ bool CCoinsViewMemPool::HaveCoins(const uint256 &txid) const {
429
432
430
433
size_t CTxMemPool::DynamicMemoryUsage () const {
431
434
LOCK (cs);
432
- return memusage::DynamicUsage (mapTx) + memusage::DynamicUsage (mapNextTx) + memusage::DynamicUsage (mapDeltas) + cachedInnerUsage;
435
+ // Estimate the overhead of mapTx to be 5 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
436
+ return memusage::MallocUsage (sizeof (CTxMemPoolEntry) + 5 * sizeof (void *)) * mapTx.size () + memusage::DynamicUsage (mapNextTx) + memusage::DynamicUsage (mapDeltas) + cachedInnerUsage;
433
437
}
0 commit comments