Skip to content

Commit 0628cb1

Browse files
committed
Use zero fee HTLC transactions for anchor channels
This is based on the assumption that we only support the zero HTLC transaction fee variant of anchor channels.
1 parent 69b0a61 commit 0628cb1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,17 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
616616
} else {
617617
htlc_success_tx_weight(opt_anchors)
618618
};
619-
let total_fee = feerate_per_kw as u64 * weight / 1000;
619+
let output_value = if opt_anchors {
620+
htlc.amount_msat / 1000
621+
} else {
622+
let total_fee = feerate_per_kw as u64 * weight / 1000;
623+
htlc.amount_msat / 1000 - total_fee
624+
};
620625

621626
let mut txouts: Vec<TxOut> = Vec::new();
622627
txouts.push(TxOut {
623628
script_pubkey: get_revokeable_redeemscript(revocation_key, contest_delay, broadcaster_delayed_payment_key).to_v0_p2wsh(),
624-
value: htlc.amount_msat / 1000 - total_fee //TODO: BOLT 3 does not specify if we should add amount_msat before dividing or if we should divide by 1000 before subtracting (as we do here)
629+
value: output_value,
625630
});
626631

627632
Transaction {
@@ -680,7 +685,8 @@ pub struct ChannelTransactionParameters {
680685
pub counterparty_parameters: Option<CounterpartyChannelTransactionParameters>,
681686
/// The late-bound funding outpoint
682687
pub funding_outpoint: Option<chain::transaction::OutPoint>,
683-
/// Are anchors used for this channel. Boolean is serialization backwards-compatible
688+
/// Are anchors (zero fee HTLC transaction variant) used for this channel. Boolean is
689+
/// serialization backwards-compatible.
684690
pub opt_anchors: Option<()>
685691
}
686692

0 commit comments

Comments
 (0)