[policy/refactor] pass in relay fee instead of using global

This commit is contained in:
glozow 2021-09-08 09:44:39 +01:00
parent 60881158c8
commit c78eb8651b
3 changed files with 6 additions and 3 deletions

View file

@ -150,6 +150,7 @@ std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& i
std::optional<std::string> 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<std::string> 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;
}

View file

@ -84,12 +84,14 @@ std::optional<std::string> 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<std::string> PaysForRBF(CAmount original_fees,
CAmount replacement_fees,
size_t replacement_vsize,
CFeeRate relay_fee,
const uint256& txid);
#endif // BITCOIN_POLICY_RBF_H

View file

@ -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);
}
}