spend: change parameter type for rbf

The parameter has been renamed and changed to `Option` as it is
only required when creating a replacement transaction using RBF.
This commit is contained in:
jp1ac4 2024-04-05 21:26:09 +01:00
parent 6376909ea1
commit 43ecd94a46
No known key found for this signature in database
GPG Key ID: A7ACD32423568D7B
2 changed files with 11 additions and 15 deletions

View File

@ -897,10 +897,10 @@ impl DaemonControl {
if !is_cancel { if !is_cancel {
candidate_coins.extend(&confirmed_cands); candidate_coins.extend(&confirmed_cands);
} }
// The min fee is the fee of the transaction being replaced and its descendants. Coin selection // The replaced fee is the fee of the transaction being replaced and its descendants. Coin selection
// will ensure that the replacement transaction additionally pays for its own weight as per // will ensure that the replacement transaction additionally pays for its own weight as per
// RBF rule 4. // RBF rule 4.
let min_fee = descendant_fees.to_sat(); let replaced_fee = descendant_fees.to_sat();
// This loop can have up to 2 iterations in the case of cancel and otherwise only 1. // This loop can have up to 2 iterations in the case of cancel and otherwise only 1.
loop { loop {
match create_spend( match create_spend(
@ -909,7 +909,7 @@ impl DaemonControl {
&mut tx_getter, &mut tx_getter,
&destinations, &destinations,
&candidate_coins, &candidate_coins,
SpendTxFees::Rbf(feerate_vb, min_fee), SpendTxFees::Rbf(feerate_vb, replaced_fee),
change_address.clone(), change_address.clone(),
) { ) {
Ok(CreateSpendRes { Ok(CreateSpendRes {

View File

@ -264,10 +264,10 @@ impl bdk_coin_select::BnbMetric for LowestFeeChangeCondition {
/// and change may result in a slightly lower feerate than this as the underlying /// and change may result in a slightly lower feerate than this as the underlying
/// function instead uses a minimum feerate of `feerate_vb / 4.0` sats/wu. /// function instead uses a minimum feerate of `feerate_vb / 4.0` sats/wu.
/// ///
/// If this is a replacement spend using RBF, then `min_fee` should be set to /// If this is a replacement spend using RBF, then `replaced_fee` should be set to
/// the total fees (in sats) of the transaction(s) being replaced, including any /// the total fees (in sats) of the transaction(s) being replaced, including any
/// descendants, which will ensure that RBF rule 4 is satisfied. /// descendants, which will ensure that RBF rule 4 is satisfied.
/// Otherwise, it should be set to 0. /// Otherwise, it should be `None`.
/// ///
/// `max_sat_weight` is the maximum weight difference of an input in the /// `max_sat_weight` is the maximum weight difference of an input in the
/// transaction before and after satisfaction. /// transaction before and after satisfaction.
@ -279,7 +279,7 @@ fn select_coins_for_spend(
base_tx: bitcoin::Transaction, base_tx: bitcoin::Transaction,
change_txo: bitcoin::TxOut, change_txo: bitcoin::TxOut,
feerate_vb: f32, feerate_vb: f32,
min_fee: u64, replaced_fee: Option<u64>,
max_sat_weight: u32, max_sat_weight: u32,
must_have_change: bool, must_have_change: bool,
) -> Result<CoinSelectionRes, InsufficientFunds> { ) -> Result<CoinSelectionRes, InsufficientFunds> {
@ -380,11 +380,7 @@ fn select_coins_for_spend(
// Finally, run the coin selection algorithm. We use an opportunistic BnB and if it couldn't // Finally, run the coin selection algorithm. We use an opportunistic BnB and if it couldn't
// find any solution we fall back to selecting coins by descending value. // find any solution we fall back to selecting coins by descending value.
let replace = if min_fee > 0 { let replace = replaced_fee.map(Replace::new);
Some(Replace::new(min_fee))
} else {
None
};
let target_fee = TargetFee { let target_fee = TargetFee {
rate: feerate, rate: feerate,
replace, replace,
@ -617,9 +613,9 @@ pub fn create_spend(
// 4. Finalize the PSBT and sanity check it before returning it. // 4. Finalize the PSBT and sanity check it before returning it.
let mut warnings = Vec::new(); let mut warnings = Vec::new();
let (feerate_vb, min_fee) = match fees { let (feerate_vb, replaced_fee) = match fees {
SpendTxFees::Regular(feerate) => (feerate, 0), SpendTxFees::Regular(feerate) => (feerate, None),
SpendTxFees::Rbf(feerate, fee) => (feerate, fee), SpendTxFees::Rbf(feerate, fee) => (feerate, Some(fee)),
}; };
let is_self_send = destinations.is_empty(); let is_self_send = destinations.is_empty();
if feerate_vb < 1 { if feerate_vb < 1 {
@ -696,7 +692,7 @@ pub fn create_spend(
tx.clone(), tx.clone(),
change_txo.clone(), change_txo.clone(),
feerate_vb, feerate_vb,
min_fee, replaced_fee,
max_sat_wu, max_sat_wu,
is_self_send, is_self_send,
) )