MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / TrimToSize

Method TrimToSize

src/txmempool.cpp:1008–1049  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1006}
1007
1008void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining) {
1009 LOCK(cs);
1010
1011 unsigned nTxnRemoved = 0;
1012 CFeeRate maxFeeRateRemoved(0);
1013 while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) {
1014 indexed_transaction_set::index<descendant_score>::type::iterator it = mapTx.get<descendant_score>().begin();
1015
1016 // We set the new mempool min fee to the feerate of the removed set, plus the
1017 // "minimum reasonable fee rate" (ie some value under which we consider txn
1018 // to have 0 fee). This way, we don't allow txn to enter mempool with feerate
1019 // equal to txn which were removed with no block in between.
1020 CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
1021 removed += incrementalRelayFee;
1022 trackPackageRemoved(removed);
1023 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1024
1025 setEntries stage;
1026 CalculateDescendants(mapTx.project<0>(it), stage);
1027 nTxnRemoved += stage.size();
1028
1029 std::vector<CTransaction> txn;
1030 if (pvNoSpendsRemaining) {
1031 txn.reserve(stage.size());
1032 for (txiter iter : stage)
1033 txn.push_back(iter->GetTx());
1034 }
1035 RemoveStaged(stage, false, MemPoolRemovalReason::SIZELIMIT);
1036 if (pvNoSpendsRemaining) {
1037 for (const CTransaction& tx : txn) {
1038 for (const CTxIn& txin : tx.vin) {
1039 if (exists(txin.prevout.hash)) continue;
1040 pvNoSpendsRemaining->push_back(txin.prevout);
1041 }
1042 }
1043 }
1044 }
1045
1046 if (maxFeeRateRemoved > CFeeRate(0)) {
1047 LogPrint(BCLog::MEMPOOL, "Removed %u txn, rolling minimum fee bumped to %s\n", nTxnRemoved, maxFeeRateRemoved.ToString());
1048 }
1049}
1050
1051uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
1052 // find parent with highest descendant count

Callers 3

LimitMempoolSizeFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
MempoolEvictionFunction · 0.80

Calls 10

maxFunction · 0.85
CFeeRateClass · 0.50
emptyMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
ToStringMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64