From a447965b80ed763aea77b46aecaed9e94e292501 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 27 Jul 2022 14:59:49 -0700 Subject: [PATCH] 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. --- lightning/src/ln/chan_utils.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index d53863289..722693a43 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -616,12 +616,17 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte } else { htlc_success_tx_weight(opt_anchors) }; - let total_fee = feerate_per_kw as u64 * weight / 1000; + let output_value = if opt_anchors { + htlc.amount_msat / 1000 + } else { + let total_fee = feerate_per_kw as u64 * weight / 1000; + htlc.amount_msat / 1000 - total_fee + }; let mut txouts: Vec = Vec::new(); txouts.push(TxOut { script_pubkey: get_revokeable_redeemscript(revocation_key, contest_delay, broadcaster_delayed_payment_key).to_v0_p2wsh(), - 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) + value: output_value, }); Transaction { @@ -680,7 +685,8 @@ pub struct ChannelTransactionParameters { pub counterparty_parameters: Option, /// The late-bound funding outpoint pub funding_outpoint: Option, - /// Are anchors used for this channel. Boolean is serialization backwards-compatible + /// Are anchors (zero fee HTLC transaction variant) used for this channel. Boolean is + /// serialization backwards-compatible. pub opt_anchors: Option<()> } -- 2.39.5