Pull anchor check into helper function
authorElias Rohrer <dev@tnull.de>
Wed, 27 Mar 2024 10:43:55 +0000 (11:43 +0100)
committerElias Rohrer <dev@tnull.de>
Tue, 9 Apr 2024 11:08:25 +0000 (13:08 +0200)
lightning/src/ln/chan_utils.rs
lightning/src/sign/mod.rs

index c002dfaea25f62297518d9f8b94dcc898004c7da..b7676ddff15290b876854b007c3f1a05572f1be4 100644 (file)
@@ -852,6 +852,11 @@ impl ChannelTransactionParameters {
                self.counterparty_parameters.is_some() && self.funding_outpoint.is_some()
        }
 
+       /// Whether the channel supports zero-fee HTLC transaction anchors.
+       pub(crate) fn supports_anchors(&self) -> bool {
+               self.channel_type_features.supports_anchors_zero_fee_htlc_tx()
+       }
+
        /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
        /// given that the holder is the broadcaster.
        ///
index 2a5d19efd1c59f119fc1554cc60190c5cd239060..7b9dba0dcc953ddd70bdcf0cbc990c7eb9137dd2 100644 (file)
@@ -156,7 +156,7 @@ impl StaticPaymentOutputDescriptor {
        pub fn witness_script(&self) -> Option<ScriptBuf> {
                self.channel_transaction_parameters.as_ref()
                        .and_then(|channel_params|
-                                if channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx() {
+                                if channel_params.supports_anchors() {
                                        let payment_point = channel_params.holder_pubkeys.payment_point;
                                        Some(chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point))
                                 } else {
@@ -169,9 +169,7 @@ impl StaticPaymentOutputDescriptor {
        /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
        /// shorter.
        pub fn max_witness_length(&self) -> u64 {
-               if self.channel_transaction_parameters.as_ref()
-                       .map(|channel_params| channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
-                       .unwrap_or(false)
+               if self.channel_transaction_parameters.as_ref().map_or(false, |p| p.supports_anchors())
                {
                        let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ +
                                1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */;
@@ -356,8 +354,7 @@ impl SpendableOutputDescriptor {
                                        if !output_set.insert(descriptor.outpoint) { return Err(()); }
                                        let sequence =
                                                if descriptor.channel_transaction_parameters.as_ref()
-                                                       .map(|channel_params| channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
-                                                       .unwrap_or(false)
+                                                       .map_or(false, |p| p.supports_anchors())
                                                {
                                                        Sequence::from_consensus(1)
                                                } else {