@@ -503,6 +503,9 @@ class MemPoolAccept
503
503
std::unique_ptr<CTxMemPoolEntry> m_entry;
504
504
std::list<CTransactionRef> m_replaced_transactions;
505
505
506
+ /* * Virtual size of the transaction as used by the mempool, calculated using serialized size
507
+ * of the transaction and sigops. */
508
+ int64_t m_vsize;
506
509
CAmount m_base_fees;
507
510
CAmount m_modified_fees;
508
511
/* * Total modified fees of all transactions being replaced. */
@@ -732,15 +735,15 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
732
735
733
736
entry.reset (new CTxMemPoolEntry (ptx, ws.m_base_fees , nAcceptTime, m_active_chainstate.m_chain .Height (),
734
737
fSpendsCoinbase , nSigOpsCost, lp));
735
- unsigned int nSize = entry->GetTxSize ();
738
+ ws. m_vsize = entry->GetTxSize ();
736
739
737
740
if (nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST)
738
741
return state.Invalid (TxValidationResult::TX_NOT_STANDARD, " bad-txns-too-many-sigops" ,
739
742
strprintf (" %d" , nSigOpsCost));
740
743
741
744
// No transactions are allowed below minRelayTxFee except from disconnected
742
745
// blocks
743
- if (!bypass_limits && !CheckFeeRate (nSize , nModifiedFees, state)) return false ;
746
+ if (!bypass_limits && !CheckFeeRate (ws. m_vsize , nModifiedFees, state)) return false ;
744
747
745
748
const CTxMemPool::setEntries setIterConflicting = m_pool.GetIterSet (setConflicts);
746
749
// Calculate in-mempool ancestors, up to a limit.
@@ -795,7 +798,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
795
798
// to be secure by simply only having two immediately-spendable
796
799
// outputs - one for each counterparty. For more info on the uses for
797
800
// this, see https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-November/016518.html
798
- if (nSize > EXTRA_DESCENDANT_TX_SIZE_LIMIT ||
801
+ if (ws. m_vsize > EXTRA_DESCENDANT_TX_SIZE_LIMIT ||
799
802
!m_pool.CalculateMemPoolAncestors (*entry, setAncestors, 2 , m_limit_ancestor_size, m_limit_descendants + 1 , m_limit_descendant_size + EXTRA_DESCENDANT_TX_SIZE_LIMIT, dummy_err_string)) {
800
803
return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY, " too-long-mempool-chain" , errString);
801
804
}
@@ -813,7 +816,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
813
816
814
817
m_rbf = !setConflicts.empty ();
815
818
if (m_rbf) {
816
- CFeeRate newFeeRate (nModifiedFees, nSize );
819
+ CFeeRate newFeeRate (nModifiedFees, ws. m_vsize );
817
820
// It's possible that the replacement pays more fees than its direct conflicts but not more
818
821
// than all conflicts (i.e. the direct conflicts have high-fee descendants). However, if the
819
822
// replacement doesn't pay more fees than its direct conflicts, then we can be sure it's not
@@ -841,7 +844,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
841
844
nConflictingFees += it->GetModifiedFee ();
842
845
nConflictingSize += it->GetTxSize ();
843
846
}
844
- if (const auto err_string{PaysForRBF (nConflictingFees, nModifiedFees, nSize, ::incrementalRelayFee, hash)}) {
847
+ if (const auto err_string{PaysForRBF (nConflictingFees, nModifiedFees, ws.m_vsize ,
848
+ ::incrementalRelayFee, hash)}) {
845
849
return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY, " insufficient fee" , *err_string);
846
850
}
847
851
}
@@ -967,14 +971,14 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
967
971
968
972
// Tx was accepted, but not added
969
973
if (args.m_test_accept ) {
970
- return MempoolAcceptResult::Success (std::move (ws.m_replaced_transactions ), ws.m_base_fees );
974
+ return MempoolAcceptResult::Success (std::move (ws.m_replaced_transactions ), ws.m_vsize , ws. m_base_fees );
971
975
}
972
976
973
977
if (!Finalize (args, ws)) return MempoolAcceptResult::Failure (ws.m_state );
974
978
975
979
GetMainSignals ().TransactionAddedToMempool (ptx, m_pool.GetAndIncrementSequence ());
976
980
977
- return MempoolAcceptResult::Success (std::move (ws.m_replaced_transactions ), ws.m_base_fees );
981
+ return MempoolAcceptResult::Success (std::move (ws.m_replaced_transactions ), ws.m_vsize , ws. m_base_fees );
978
982
}
979
983
980
984
PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions (const std::vector<CTransactionRef>& txns, ATMPArgs& args)
@@ -1033,7 +1037,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
1033
1037
// When test_accept=true, transactions that pass PolicyScriptChecks are valid because there are
1034
1038
// no further mempool checks (passing PolicyScriptChecks implies passing ConsensusScriptChecks).
1035
1039
results.emplace (ws.m_ptx ->GetWitnessHash (),
1036
- MempoolAcceptResult::Success (std::move (ws.m_replaced_transactions ), ws.m_base_fees ));
1040
+ MempoolAcceptResult::Success (std::move (ws.m_replaced_transactions ),
1041
+ ws.m_vsize , ws.m_base_fees ));
1037
1042
}
1038
1043
}
1039
1044
0 commit comments