Skip to content

Commit 5cc3215

Browse files
committed
Pull anchor check into helper function
1 parent 113b0f1 commit 5cc3215

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,11 @@ impl ChannelTransactionParameters {
852852
self.counterparty_parameters.is_some() && self.funding_outpoint.is_some()
853853
}
854854

855+
/// Whether the channel supports zero-fee HTLC transaction anchors.
856+
pub(crate) fn supports_anchors(&self) -> bool {
857+
self.channel_type_features.supports_anchors_zero_fee_htlc_tx()
858+
}
859+
855860
/// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
856861
/// given that the holder is the broadcaster.
857862
///

lightning/src/sign/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl StaticPaymentOutputDescriptor {
156156
pub fn witness_script(&self) -> Option<ScriptBuf> {
157157
self.channel_transaction_parameters.as_ref()
158158
.and_then(|channel_params|
159-
if channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx() {
159+
if channel_params.supports_anchors() {
160160
let payment_point = channel_params.holder_pubkeys.payment_point;
161161
Some(chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point))
162162
} else {
@@ -169,9 +169,7 @@ impl StaticPaymentOutputDescriptor {
169169
/// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
170170
/// shorter.
171171
pub fn max_witness_length(&self) -> u64 {
172-
if self.channel_transaction_parameters.as_ref()
173-
.map(|channel_params| channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
174-
.unwrap_or(false)
172+
if self.channel_transaction_parameters.as_ref().map_or(false, |p| p.supports_anchors())
175173
{
176174
let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ +
177175
1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */;
@@ -356,8 +354,7 @@ impl SpendableOutputDescriptor {
356354
if !output_set.insert(descriptor.outpoint) { return Err(()); }
357355
let sequence =
358356
if descriptor.channel_transaction_parameters.as_ref()
359-
.map(|channel_params| channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
360-
.unwrap_or(false)
357+
.map_or(false, |p| p.supports_anchors())
361358
{
362359
Sequence::from_consensus(1)
363360
} else {

0 commit comments

Comments
 (0)