Remove transactions when ensuring size limit

This commit is contained in:
Eirik Ogilvie-Wigley 2019-09-30 10:46:15 -06:00
parent 0b2c5cfcc2
commit 1407fd10a1
3 changed files with 16 additions and 15 deletions

View File

@ -1637,12 +1637,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
pool.addSpentIndex(entry, view);
}
// In normal circumstances the following should be boost::none
boost::optional<uint256> maybeDropTxId;
list<CTransaction> removed;
while ((maybeDropTxId = pool.ensureSizeLimit()).is_initialized()) {
pool.remove(pool.mapTx.find(maybeDropTxId.get())->GetTx(), removed, true);
}
pool.ensureSizeLimit();
}
}

View File

@ -68,6 +68,8 @@ CTxMemPool::CTxMemPool(const CFeeRate& _minRelayFee) :
CTxMemPool::~CTxMemPool()
{
delete minerPolicyEstimator;
delete recentlyEvicted;
delete weightedTxList;
}
void CTxMemPool::pruneSpent(const uint256 &hashTx, CCoins &coins)
@ -819,16 +821,20 @@ void CTxMemPool::setMempoolCostLimit(int64_t totalCostLimit, int64_t evictionMem
}
bool CTxMemPool::isRecentlyEvicted(const uint256& txId) {
if (!recentlyEvicted) {
return false;
}
LOCK(cs);
assert(recentlyEvicted);
return recentlyEvicted->contains(txId);
}
boost::optional<uint256> CTxMemPool::ensureSizeLimit() {
auto maybeDrop = weightedTxList->maybeDropRandom(false);
if (maybeDrop) {
return maybeDrop.get().txId;
void CTxMemPool::ensureSizeLimit() {
AssertLockHeld(cs);
assert(recentlyEvicted);
assert(weightedTxList);
boost::optional<WeightedTxInfo> maybeDrop;
std::list<CTransaction> removed;
while ((maybeDrop = weightedTxList->maybeDropRandom(false)).is_initialized()) {
uint256 txId = maybeDrop.get().txId;
recentlyEvicted->add(txId);
remove(mapTx.find(txId)->GetTx(), removed, true);
}
return boost::none;
}

View File

@ -268,7 +268,7 @@ public:
// Returns true if a transaction has been recently evicted
bool isRecentlyEvicted(const uint256& txId);
// Returns a txid if a transaction is evicted from the mempool
boost::optional<uint256> ensureSizeLimit();
void ensureSizeLimit();
};
/**