Skip to content

Commit 9088dae

Browse files
committed
Consider existing commitment transaction feerate when bumping
With anchors, we've yet to change the frequency or aggressiveness of feerate updates, so it's likely that commitment transactions have a good enough feerate to confirm on its own. In any case, when producing a child anchor transaction, we should already take into account the fees paid by the commitment transaction itself, allowing the user to save some satoshis. Unfortunately, in its current form, this will still result in overpaying by a small margin at the expense of making the coin selection API more complex.
1 parent 990c500 commit 9088dae

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lightning/src/events/bump_transaction.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use alloc::collections::BTreeMap;
1515
use core::ops::Deref;
1616

17-
use crate::chain::chaininterface::{BroadcasterInterface, compute_feerate_sat_per_1000_weight, fee_for_weight};
17+
use crate::chain::chaininterface::{BroadcasterInterface, compute_feerate_sat_per_1000_weight, fee_for_weight, FEERATE_FLOOR_SATS_PER_KW};
1818
use crate::chain::ClaimId;
1919
use crate::io_extras::sink;
2020
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
@@ -700,8 +700,21 @@ where
700700
&self, claim_id: ClaimId, package_target_feerate_sat_per_1000_weight: u32,
701701
commitment_tx: &Transaction, commitment_tx_fee_sat: u64, anchor_descriptor: &AnchorDescriptor,
702702
) -> Result<(), ()> {
703+
// Our commitment transaction already has fees allocated to it, so we should take them into
704+
// account. We compute its feerate and subtract it from the package target, using the result
705+
// as the target feerate for our anchor transaction. Unfortunately, this results in users
706+
// overpaying by a small margin since we don't yet know the anchor transaction size, and
707+
// avoiding the small overpayment only makes our API even more complex.
708+
let commitment_tx_sat_per_1000_weight: u32 = compute_feerate_sat_per_1000_weight(
709+
commitment_tx_fee_sat, commitment_tx.weight() as u64,
710+
);
711+
let anchor_target_feerate_sat_per_1000_weight = core::cmp::max(
712+
package_target_feerate_sat_per_1000_weight - commitment_tx_sat_per_1000_weight,
713+
FEERATE_FLOOR_SATS_PER_KW,
714+
);
715+
703716
let mut anchor_tx = self.build_anchor_tx(
704-
claim_id, package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_descriptor,
717+
claim_id, anchor_target_feerate_sat_per_1000_weight, commitment_tx, anchor_descriptor,
705718
)?;
706719
debug_assert_eq!(anchor_tx.output.len(), 1);
707720

0 commit comments

Comments
 (0)