| 1237 | } |
| 1238 | |
| 1239 | void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining) { |
| 1240 | AssertLockHeld(cs); |
| 1241 | |
| 1242 | unsigned nTxnRemoved = 0; |
| 1243 | CFeeRate maxFeeRateRemoved(0); |
| 1244 | while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) { |
| 1245 | indexed_transaction_set::index<descendant_score>::type::iterator it = mapTx.get<descendant_score>().begin(); |
| 1246 | |
| 1247 | // We set the new mempool min fee to the feerate of the removed set, plus the |
| 1248 | // "minimum reasonable fee rate" (ie some value under which we consider txn |
| 1249 | // to have 0 fee). This way, we don't allow txn to enter mempool with feerate |
| 1250 | // equal to txn which were removed with no block in between. |
| 1251 | CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants()); |
| 1252 | removed += incrementalRelayFee; |
| 1253 | trackPackageRemoved(removed); |
| 1254 | maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed); |
| 1255 | |
| 1256 | setEntries stage; |
| 1257 | CalculateDescendants(mapTx.project<0>(it), stage); |
| 1258 | nTxnRemoved += stage.size(); |
| 1259 | |
| 1260 | std::vector<CTransaction> txn; |
| 1261 | if (pvNoSpendsRemaining) { |
| 1262 | txn.reserve(stage.size()); |
| 1263 | for (txiter iter : stage) |
| 1264 | txn.push_back(iter->GetTx()); |
| 1265 | } |
| 1266 | RemoveStaged(stage, false, MemPoolRemovalReason::SIZELIMIT); |
| 1267 | if (pvNoSpendsRemaining) { |
| 1268 | for (const CTransaction& tx : txn) { |
| 1269 | for (const CTxIn& txin : tx.vin) { |
| 1270 | if (exists(GenTxid::Txid(txin.prevout.hash))) continue; |
| 1271 | pvNoSpendsRemaining->push_back(txin.prevout); |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | if (maxFeeRateRemoved > CFeeRate(0)) { |
| 1278 | LogPrint(BCLog::MEMPOOL, "Removed %u txn, rolling minimum fee bumped to %s\n", nTxnRemoved, maxFeeRateRemoved.ToString()); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const { |
| 1283 | // find parent with highest descendant count |