@@ -461,9 +461,7 @@ class MemPoolAccept
461
461
// around easier.
462
462
struct ATMPArgs {
463
463
const CChainParams& m_chainparams;
464
- TxValidationState &m_state;
465
464
const int64_t m_accept_time;
466
- std::list<CTransactionRef> m_replaced_transactions;
467
465
const bool m_bypass_limits;
468
466
/*
469
467
* Return any outpoints which were not previously present in the coins
@@ -474,7 +472,6 @@ class MemPoolAccept
474
472
*/
475
473
std::vector<COutPoint>& m_coins_to_uncache;
476
474
const bool m_test_accept;
477
- CAmount m_fee_out;
478
475
};
479
476
480
477
// Single transaction acceptance
@@ -489,14 +486,17 @@ class MemPoolAccept
489
486
CTxMemPool::setEntries m_all_conflicting;
490
487
CTxMemPool::setEntries m_ancestors;
491
488
std::unique_ptr<CTxMemPoolEntry> m_entry;
489
+ std::list<CTransactionRef> m_replaced_transactions;
492
490
493
491
bool m_replacement_transaction;
492
+ CAmount m_fee_out;
494
493
CAmount m_modified_fees;
495
494
CAmount m_conflicting_fees;
496
495
size_t m_conflicting_size;
497
496
498
497
const CTransactionRef& m_ptx;
499
498
const uint256& m_hash;
499
+ TxValidationState m_state;
500
500
};
501
501
502
502
// Run the policy checks on a given transaction, excluding any script checks.
@@ -507,18 +507,18 @@ class MemPoolAccept
507
507
508
508
// Run the script checks using our policy flags. As this can be slow, we should
509
509
// only invoke this on transactions that have otherwise passed policy checks.
510
- bool PolicyScriptChecks (ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
510
+ bool PolicyScriptChecks (const ATMPArgs& args, Workspace& ws, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
511
511
512
512
// Re-run the script checks, using consensus flags, and try to cache the
513
513
// result in the scriptcache. This should be done after
514
514
// PolicyScriptChecks(). This requires that all inputs either be in our
515
515
// utxo set or in the mempool.
516
- bool ConsensusScriptChecks (ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData &txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
516
+ bool ConsensusScriptChecks (const ATMPArgs& args, Workspace& ws, PrecomputedTransactionData &txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
517
517
518
518
// Try to add the transaction to the mempool, removing any conflicts first.
519
519
// Returns true if the transaction is in the mempool after any size
520
520
// limiting is performed, false otherwise.
521
- bool Finalize (ATMPArgs& args, Workspace& ws) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
521
+ bool Finalize (const ATMPArgs& args, Workspace& ws) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
522
522
523
523
// Compare a package's feerate against minimum allowed.
524
524
bool CheckFeeRate (size_t package_size, CAmount package_fee, TxValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs)
@@ -556,12 +556,12 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
556
556
const uint256& hash = ws.m_hash ;
557
557
558
558
// Copy/alias what we need out of args
559
- TxValidationState &state = args.m_state ;
560
559
const int64_t nAcceptTime = args.m_accept_time ;
561
560
const bool bypass_limits = args.m_bypass_limits ;
562
561
std::vector<COutPoint>& coins_to_uncache = args.m_coins_to_uncache ;
563
562
564
563
// Alias what we need out of ws
564
+ TxValidationState &state = ws.m_state ;
565
565
std::set<uint256>& setConflicts = ws.m_conflicts ;
566
566
CTxMemPool::setEntries& allConflicting = ws.m_all_conflicting ;
567
567
CTxMemPool::setEntries& setAncestors = ws.m_ancestors ;
@@ -681,13 +681,10 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
681
681
if (!CheckSequenceLocks (m_pool, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
682
682
return state.Invalid (TxValidationResult::TX_PREMATURE_SPEND, " non-BIP68-final" );
683
683
684
- CAmount nFees = 0 ;
685
- if (!Consensus::CheckTxInputs (tx, state, m_view, g_chainman.m_blockman .GetSpendHeight (m_view), nFees)) {
684
+ if (!Consensus::CheckTxInputs (tx, state, m_view, g_chainman.m_blockman .GetSpendHeight (m_view), ws.m_fee_out )) {
686
685
return false ; // state filled in by CheckTxInputs
687
686
}
688
687
689
- args.m_fee_out = nFees;
690
-
691
688
// Check for non-standard pay-to-script-hash in inputs
692
689
const auto & params = args.m_chainparams .GetConsensus ();
693
690
auto taproot_state = VersionBitsState (::ChainActive ().Tip (), params, Consensus::DEPLOYMENT_TAPROOT, versionbitscache);
@@ -702,7 +699,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
702
699
int64_t nSigOpsCost = GetTransactionSigOpCost (tx, m_view, STANDARD_SCRIPT_VERIFY_FLAGS);
703
700
704
701
// nModifiedFees includes any fee deltas from PrioritiseTransaction
705
- nModifiedFees = nFees ;
702
+ nModifiedFees = ws. m_fee_out ;
706
703
m_pool.ApplyDelta (hash, nModifiedFees);
707
704
708
705
// Keep track of transactions that spend a coinbase, which we re-scan
@@ -716,7 +713,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
716
713
}
717
714
}
718
715
719
- entry.reset (new CTxMemPoolEntry (ptx, nFees , nAcceptTime, ::ChainActive ().Height (),
716
+ entry.reset (new CTxMemPoolEntry (ptx, ws. m_fee_out , nAcceptTime, ::ChainActive ().Height (),
720
717
fSpendsCoinbase , nSigOpsCost, lp));
721
718
unsigned int nSize = entry->GetTxSize ();
722
719
@@ -920,11 +917,10 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
920
917
return true ;
921
918
}
922
919
923
- bool MemPoolAccept::PolicyScriptChecks (ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData& txdata)
920
+ bool MemPoolAccept::PolicyScriptChecks (const ATMPArgs& args, Workspace& ws, PrecomputedTransactionData& txdata)
924
921
{
925
922
const CTransaction& tx = *ws.m_ptx ;
926
-
927
- TxValidationState &state = args.m_state ;
923
+ TxValidationState &state = ws.m_state ;
928
924
929
925
constexpr unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS;
930
926
@@ -947,12 +943,11 @@ bool MemPoolAccept::PolicyScriptChecks(ATMPArgs& args, const Workspace& ws, Prec
947
943
return true ;
948
944
}
949
945
950
- bool MemPoolAccept::ConsensusScriptChecks (ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData& txdata)
946
+ bool MemPoolAccept::ConsensusScriptChecks (const ATMPArgs& args, Workspace& ws, PrecomputedTransactionData& txdata)
951
947
{
952
948
const CTransaction& tx = *ws.m_ptx ;
953
949
const uint256& hash = ws.m_hash ;
954
-
955
- TxValidationState &state = args.m_state ;
950
+ TxValidationState &state = ws.m_state ;
956
951
const CChainParams& chainparams = args.m_chainparams ;
957
952
958
953
// Check again against the current block tip's script verification
@@ -979,11 +974,11 @@ bool MemPoolAccept::ConsensusScriptChecks(ATMPArgs& args, const Workspace& ws, P
979
974
return true ;
980
975
}
981
976
982
- bool MemPoolAccept::Finalize (ATMPArgs& args, Workspace& ws)
977
+ bool MemPoolAccept::Finalize (const ATMPArgs& args, Workspace& ws)
983
978
{
984
979
const CTransaction& tx = *ws.m_ptx ;
985
980
const uint256& hash = ws.m_hash ;
986
- TxValidationState &state = args .m_state ;
981
+ TxValidationState &state = ws .m_state ;
987
982
const bool bypass_limits = args.m_bypass_limits ;
988
983
989
984
CTxMemPool::setEntries& allConflicting = ws.m_all_conflicting ;
@@ -1002,7 +997,7 @@ bool MemPoolAccept::Finalize(ATMPArgs& args, Workspace& ws)
1002
997
hash.ToString (),
1003
998
FormatMoney (nModifiedFees - nConflictingFees),
1004
999
(int )entry->GetTxSize () - (int )nConflictingSize);
1005
- args .m_replaced_transactions .push_back (it->GetSharedTx ());
1000
+ ws .m_replaced_transactions .push_back (it->GetSharedTx ());
1006
1001
}
1007
1002
m_pool.RemoveStaged (allConflicting, false , MemPoolRemovalReason::REPLACED);
1008
1003
@@ -1032,28 +1027,28 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
1032
1027
1033
1028
Workspace workspace (ptx);
1034
1029
1035
- if (!PreChecks (args, workspace)) return MempoolAcceptResult (args .m_state );
1030
+ if (!PreChecks (args, workspace)) return MempoolAcceptResult (workspace .m_state );
1036
1031
1037
1032
// Only compute the precomputed transaction data if we need to verify
1038
1033
// scripts (ie, other policy checks pass). We perform the inexpensive
1039
1034
// checks first and avoid hashing and signature verification unless those
1040
1035
// checks pass, to mitigate CPU exhaustion denial-of-service attacks.
1041
1036
PrecomputedTransactionData txdata;
1042
1037
1043
- if (!PolicyScriptChecks (args, workspace, txdata)) return MempoolAcceptResult (args .m_state );
1038
+ if (!PolicyScriptChecks (args, workspace, txdata)) return MempoolAcceptResult (workspace .m_state );
1044
1039
1045
- if (!ConsensusScriptChecks (args, workspace, txdata)) return MempoolAcceptResult (args .m_state );
1040
+ if (!ConsensusScriptChecks (args, workspace, txdata)) return MempoolAcceptResult (workspace .m_state );
1046
1041
1047
1042
// Tx was accepted, but not added
1048
1043
if (args.m_test_accept ) {
1049
- return MempoolAcceptResult (std::move (args .m_replaced_transactions ), args .m_fee_out );
1044
+ return MempoolAcceptResult (std::move (workspace .m_replaced_transactions ), workspace .m_fee_out );
1050
1045
}
1051
1046
1052
- if (!Finalize (args, workspace)) return MempoolAcceptResult (args .m_state );
1047
+ if (!Finalize (args, workspace)) return MempoolAcceptResult (workspace .m_state );
1053
1048
1054
1049
GetMainSignals ().TransactionAddedToMempool (ptx, m_pool.GetAndIncrementSequence ());
1055
1050
1056
- return MempoolAcceptResult (std::move (args .m_replaced_transactions ), args .m_fee_out );
1051
+ return MempoolAcceptResult (std::move (workspace .m_replaced_transactions ), workspace .m_fee_out );
1057
1052
}
1058
1053
1059
1054
} // anon namespace
@@ -1064,9 +1059,8 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp
1064
1059
bool bypass_limits, bool test_accept)
1065
1060
EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1066
1061
{
1067
- TxValidationState state;
1068
1062
std::vector<COutPoint> coins_to_uncache;
1069
- MemPoolAccept::ATMPArgs args { chainparams, state, nAcceptTime, {}, bypass_limits, coins_to_uncache, test_accept, {} };
1063
+ MemPoolAccept::ATMPArgs args { chainparams, nAcceptTime, bypass_limits, coins_to_uncache, test_accept };
1070
1064
1071
1065
const MempoolAcceptResult result = MemPoolAccept (pool).AcceptSingleTransaction (tx, args);
1072
1066
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
0 commit comments