@@ -57,6 +57,34 @@ static feebumper::Result PreconditionChecks(interfaces::Chain::Lock& locked_chai
5757 return feebumper::Result::OK;
5858}
5959
60+ static CFeeRate EstimateFeeRate (CWallet* wallet, const CWalletTx& wtx, CCoinControl& coin_control, CAmount& old_fee)
61+ {
62+ // Get the fee rate of the original transaction. This is calculated from
63+ // the tx fee/vsize, so it may have been rounded down. Add 1 satoshi to the
64+ // result.
65+ old_fee = wtx.GetDebit (ISMINE_SPENDABLE) - wtx.tx ->GetValueOut ();
66+ int64_t txSize = GetVirtualTransactionSize (*(wtx.tx ));
67+ CFeeRate feerate (old_fee, txSize);
68+ feerate += CFeeRate (1 );
69+
70+ // The node has a configurable incremental relay fee. Increment the fee by
71+ // the minimum of that and the wallet's conservative
72+ // WALLET_INCREMENTAL_RELAY_FEE value to future proof against changes to
73+ // network wide policy for incremental relay fee that our node may not be
74+ // aware of. This ensures we're over the over the required relay fee rate
75+ // (BIP 125 rule 4). The replacement tx will be at least as large as the
76+ // original tx, so the total fee will be greater (BIP 125 rule 3)
77+ CFeeRate node_incremental_relay_fee = wallet->chain ().relayIncrementalFee ();
78+ CFeeRate wallet_incremental_relay_fee = CFeeRate (WALLET_INCREMENTAL_RELAY_FEE);
79+ feerate += std::max (node_incremental_relay_fee, wallet_incremental_relay_fee);
80+
81+ // Fee rate must also be at least the wallet's GetMinimumFeeRate
82+ CFeeRate min_feerate (GetMinimumFeeRate (*wallet, coin_control, /* feeCalc */ nullptr ));
83+
84+ // Set the required fee rate for the replacement transaction in coin control.
85+ return std::max (feerate, min_feerate);
86+ }
87+
6088namespace feebumper {
6189
6290bool TransactionCanBeBumped (const CWallet* wallet, const uint256& txid)
@@ -230,31 +258,7 @@ Result CreateRateBumpTransaction(CWallet* wallet, const uint256& txid, const CCo
230258 }
231259 }
232260
233- // Get the fee rate of the original transaction. This is calculated from
234- // the tx fee/vsize, so it may have been rounded down. Add 1 satoshi to the
235- // result.
236- old_fee = wtx.GetDebit (ISMINE_SPENDABLE) - wtx.tx ->GetValueOut ();
237- int64_t txSize = GetVirtualTransactionSize (*(wtx.tx ));
238- // Feerate of thing we are bumping
239- CFeeRate feerate (old_fee, txSize);
240- feerate += CFeeRate (1 );
241-
242- // The node has a configurable incremental relay fee. Increment the fee by
243- // the minimum of that and the wallet's conservative
244- // WALLET_INCREMENTAL_RELAY_FEE value to future proof against changes to
245- // network wide policy for incremental relay fee that our node may not be
246- // aware of. This ensures we're over the over the required relay fee rate
247- // (BIP 125 rule 4). The replacement tx will be at least as large as the
248- // original tx, so the total fee will be greater (BIP 125 rule 3)
249- CFeeRate node_incremental_relay_fee = wallet->chain ().relayIncrementalFee ();
250- CFeeRate wallet_incremental_relay_fee = CFeeRate (WALLET_INCREMENTAL_RELAY_FEE);
251- feerate += std::max (node_incremental_relay_fee, wallet_incremental_relay_fee);
252-
253- // Fee rate must also be at least the wallet's GetMinimumFeeRate
254- CFeeRate min_feerate (GetMinimumFeeRate (*wallet, new_coin_control, /* feeCalc */ nullptr ));
255-
256- // Set the required fee rate for the replacement transaction in coin control.
257- new_coin_control.m_feerate = std::max (feerate, min_feerate);
261+ new_coin_control.m_feerate = EstimateFeeRate (wallet, wtx, new_coin_control, old_fee);
258262
259263 // Fill in required inputs we are double-spending(all of them)
260264 // N.B.: bip125 doesn't require all the inputs in the replaced transaction to be
0 commit comments