@@ -688,7 +688,7 @@ class MemPoolAccept
688
688
bool ConsensusScriptChecks (const ATMPArgs& args, Workspace& ws) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
689
689
690
690
// Try to add the transaction to the mempool, removing any conflicts first.
691
- void FinalizeSubpackage (const ATMPArgs& args, std::vector<Workspace>& ws ) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
691
+ void FinalizeSubpackage (const ATMPArgs& args) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
692
692
693
693
// Submit all transactions to the mempool and call ConsensusScriptChecks to add to the script
694
694
// cache - should only be called after successful validation of all transactions in the package.
@@ -1283,34 +1283,48 @@ bool MemPoolAccept::ConsensusScriptChecks(const ATMPArgs& args, Workspace& ws)
1283
1283
return true ;
1284
1284
}
1285
1285
1286
- void MemPoolAccept::FinalizeSubpackage (const ATMPArgs& args, std::vector<Workspace>& workspaces )
1286
+ void MemPoolAccept::FinalizeSubpackage (const ATMPArgs& args)
1287
1287
{
1288
1288
AssertLockHeld (cs_main);
1289
1289
AssertLockHeld (m_pool.cs );
1290
- const CTransaction& tx = *workspaces.front ().m_ptx ;
1291
- const uint256& hash = workspaces.front ().m_hash ;
1292
1290
1293
1291
if (!m_subpackage.m_all_conflicts .empty ()) Assume (args.m_allow_replacement );
1294
1292
// Remove conflicting transactions from the mempool
1295
1293
for (CTxMemPool::txiter it : m_subpackage.m_all_conflicts )
1296
1294
{
1297
- LogDebug (BCLog::MEMPOOL, " replacing mempool tx %s (wtxid=%s, fees=%s, vsize=%s). New tx %s (wtxid=%s, fees=%s, vsize=%s)\n " ,
1298
- it->GetTx ().GetHash ().ToString (),
1299
- it->GetTx ().GetWitnessHash ().ToString (),
1300
- it->GetFee (),
1301
- it->GetTxSize (),
1302
- hash.ToString (),
1303
- tx.GetWitnessHash ().ToString (),
1304
- workspaces[0 ].m_tx_handle ->GetFee (),
1305
- workspaces[0 ].m_tx_handle ->GetTxSize ());
1295
+ std::string log_string = strprintf (" replacing mempool tx %s (wtxid=%s, fees=%s, vsize=%s). " ,
1296
+ it->GetTx ().GetHash ().ToString (),
1297
+ it->GetTx ().GetWitnessHash ().ToString (),
1298
+ it->GetFee (),
1299
+ it->GetTxSize ());
1300
+ FeeFrac feerate{m_subpackage.m_total_modified_fees , int32_t (m_subpackage.m_total_vsize )};
1301
+ uint256 tx_or_package_hash{};
1302
+ if (m_subpackage.m_changeset ->GetTxCount () == 1 ) {
1303
+ const CTransaction& tx = m_subpackage.m_changeset ->GetAddedTxn (0 );
1304
+ tx_or_package_hash = tx.GetHash ();
1305
+ log_string += strprintf (" New tx %s (wtxid=%s, fees=%s, vsize=%s)" ,
1306
+ tx.GetHash ().ToString (),
1307
+ tx.GetWitnessHash ().ToString (),
1308
+ feerate.fee ,
1309
+ feerate.size );
1310
+ } else {
1311
+ tx_or_package_hash = GetPackageHash (m_subpackage.m_changeset ->GetAddedTxns ());
1312
+ log_string += strprintf (" New package %s with %lu txs, fees=%s, vsize=%s" ,
1313
+ tx_or_package_hash.ToString (),
1314
+ m_subpackage.m_changeset ->GetTxCount (),
1315
+ feerate.fee ,
1316
+ feerate.size );
1317
+
1318
+ }
1319
+ LogDebug (BCLog::MEMPOOL, " %s\n " , log_string);
1306
1320
TRACEPOINT (mempool, replaced,
1307
1321
it->GetTx ().GetHash ().data (),
1308
1322
it->GetTxSize (),
1309
1323
it->GetFee (),
1310
1324
std::chrono::duration_cast<std::chrono::duration<std::uint64_t >>(it->GetTime ()).count (),
1311
- hash .data (),
1312
- workspaces[ 0 ]. m_tx_handle -> GetTxSize () ,
1313
- workspaces[ 0 ]. m_tx_handle -> GetFee ()
1325
+ tx_or_package_hash .data (),
1326
+ feerate. size ,
1327
+ feerate. fee
1314
1328
);
1315
1329
m_subpackage.m_replaced_transactions .push_back (it->GetSharedTx ());
1316
1330
}
@@ -1333,7 +1347,7 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
1333
1347
return !m_pool.exists (GenTxid::Txid (ws.m_ptx ->GetHash ())); }));
1334
1348
1335
1349
bool all_submitted = true ;
1336
- FinalizeSubpackage (args, workspaces );
1350
+ FinalizeSubpackage (args);
1337
1351
// ConsensusScriptChecks adds to the script cache and is therefore consensus-critical;
1338
1352
// CheckInputsFromMempoolAndCache asserts that transactions only spend coins available from the
1339
1353
// mempool or UTXO set. Submit each transaction to the mempool immediately after calling
@@ -1402,8 +1416,7 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
1402
1416
AssertLockHeld (cs_main);
1403
1417
LOCK (m_pool.cs ); // mempool "read lock" (held through m_pool.m_opts.signals->TransactionAddedToMempool())
1404
1418
1405
- std::vector<Workspace> workspaces{Workspace (ptx)};
1406
- Workspace &ws = workspaces.front ();
1419
+ Workspace ws (ptx);
1407
1420
const std::vector<Wtxid> single_wtxid{ws.m_ptx ->GetWitnessHash ()};
1408
1421
1409
1422
if (!PreChecks (args, ws)) {
@@ -1414,6 +1427,9 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
1414
1427
return MempoolAcceptResult::Failure (ws.m_state );
1415
1428
}
1416
1429
1430
+ m_subpackage.m_total_vsize = ws.m_vsize ;
1431
+ m_subpackage.m_total_modified_fees = ws.m_modified_fees ;
1432
+
1417
1433
// Individual modified feerate exceeded caller-defined max; abort
1418
1434
if (args.m_client_maxfeerate && CFeeRate (ws.m_modified_fees , ws.m_vsize ) > args.m_client_maxfeerate .value ()) {
1419
1435
ws.m_state .Invalid (TxValidationResult::TX_MEMPOOL_POLICY, " max feerate exceeded" , " " );
@@ -1451,12 +1467,9 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
1451
1467
ws.m_base_fees , effective_feerate, single_wtxid);
1452
1468
}
1453
1469
1454
- FinalizeSubpackage (args, workspaces );
1470
+ FinalizeSubpackage (args);
1455
1471
1456
- // trim mempool and check if tx was trimmed
1457
- // If we are validating a package, don't trim here because we could evict a previous transaction
1458
- // in the package. LimitMempoolSize() should be called at the very end to make sure the mempool
1459
- // is still within limits and package submission happens atomically.
1472
+ // Limit the mempool, if appropriate.
1460
1473
if (!args.m_package_submission && !args.m_bypass_limits ) {
1461
1474
LimitMempoolSize (m_pool, m_active_chainstate.CoinsTip ());
1462
1475
if (!m_pool.exists (GenTxid::Txid (ws.m_hash ))) {
0 commit comments