From c78eb8651b0949fefcafb22940512f4ef98d3358 Mon Sep 17 00:00:00 2001 From: glozow Date: Wed, 8 Sep 2021 09:44:39 +0100 Subject: [PATCH] [policy/refactor] pass in relay fee instead of using global --- src/policy/rbf.cpp | 5 +++-- src/policy/rbf.h | 2 ++ src/validation.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/policy/rbf.cpp b/src/policy/rbf.cpp index 15527afb8ac..cefc25a2251 100644 --- a/src/policy/rbf.cpp +++ b/src/policy/rbf.cpp @@ -150,6 +150,7 @@ std::optional PaysMoreThanConflicts(const CTxMemPool::setEntries& i std::optional PaysForRBF(CAmount original_fees, CAmount replacement_fees, size_t replacement_vsize, + CFeeRate relay_fee, const uint256& txid) { // The replacement must pay greater fees than the transactions it @@ -163,11 +164,11 @@ std::optional PaysForRBF(CAmount original_fees, // Finally in addition to paying more fees than the conflicts the // new transaction must pay for its own bandwidth. CAmount additional_fees = replacement_fees - original_fees; - if (additional_fees < ::incrementalRelayFee.GetFee(replacement_vsize)) { + if (additional_fees < relay_fee.GetFee(replacement_vsize)) { return strprintf("rejecting replacement %s, not enough additional fees to relay; %s < %s", txid.ToString(), FormatMoney(additional_fees), - FormatMoney(::incrementalRelayFee.GetFee(replacement_vsize))); + FormatMoney(relay_fee.GetFee(replacement_vsize))); } return std::nullopt; } diff --git a/src/policy/rbf.h b/src/policy/rbf.h index 56468a09b21..e8cfb2e6438 100644 --- a/src/policy/rbf.h +++ b/src/policy/rbf.h @@ -84,12 +84,14 @@ std::optional PaysMoreThanConflicts(const CTxMemPool::setEntries& i * @param[in] original_fees Total modified fees of original transaction(s). * @param[in] replacement_fees Total modified fees of replacement transaction(s). * @param[in] replacement_vsize Total virtual size of replacement transaction(s). + * @param[in] relay_fee The node's minimum feerate for transaction relay. * @param[in] txid Transaction ID, included in the error message if violation occurs. * @returns error string if fees are insufficient, otherwise std::nullopt. */ std::optional PaysForRBF(CAmount original_fees, CAmount replacement_fees, size_t replacement_vsize, + CFeeRate relay_fee, const uint256& txid); #endif // BITCOIN_POLICY_RBF_H diff --git a/src/validation.cpp b/src/validation.cpp index 8696f1af858..e4b8b62c5a6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -803,7 +803,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws) nConflictingFees += it->GetModifiedFee(); nConflictingSize += it->GetTxSize(); } - if (const auto err_string{PaysForRBF(nConflictingFees, nModifiedFees, nSize, hash)}) { + if (const auto err_string{PaysForRBF(nConflictingFees, nModifiedFees, nSize, ::incrementalRelayFee, hash)}) { return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "insufficient fee", *err_string); } }