]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use zero fee HTLC transactions for anchor channels
authorWilmer Paulino <wilmer.paulino@gmail.com>
Wed, 27 Jul 2022 21:59:49 +0000 (14:59 -0700)
committerWilmer Paulino <wilmer.paulino@gmail.com>
Tue, 13 Sep 2022 17:58:29 +0000 (10:58 -0700)
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

index d53863289bc5807464739f0707fbb390c25f9869..722693a430e57ebe8f5edae4c464ea335a1d5299 100644 (file)
@@ -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<TxOut> = 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<CounterpartyChannelTransactionParameters>,
        /// The late-bound funding outpoint
        pub funding_outpoint: Option<chain::transaction::OutPoint>,
-       /// 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<()>
 }