Skip to content

Commit aaef672

Browse files
authored
Merge pull request #3656 from TheBlueMatt/2025-03-zfc-part-1
Misc refactors and cleanups in advance of zero-fee commitments
2 parents f10b854 + 68b16e2 commit aaef672

File tree

16 files changed

+207
-197
lines changed

16 files changed

+207
-197
lines changed

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ mod tests {
11411141
ext_from_hex("030020", &mut test);
11421142
// init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
11431143
ext_from_hex(
1144-
"0010 00021aaa 0008aaa20aaa2a0a9aaa 03000000000000000000000000000000",
1144+
"0010 00021aaa 0008aaa208aa2a0a9aaa 03000000000000000000000000000000",
11451145
&mut test,
11461146
);
11471147

@@ -1245,7 +1245,7 @@ mod tests {
12451245
ext_from_hex("030120", &mut test);
12461246
// init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
12471247
ext_from_hex(
1248-
"0010 00021aaa 0008aaa20aaa2a0a9aaa 01000000000000000000000000000000",
1248+
"0010 00021aaa 0008aaa208aa2a0a9aaa 01000000000000000000000000000000",
12491249
&mut test,
12501250
);
12511251

lightning-types/src/features.rs

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
//! (see [BOLT PR #1110](https://github.com/lightning/bolts/pull/1110) for more info).
7777
//! - `Quiescence` - protocol to quiesce a channel by indicating that "SomeThing Fundamental is Underway"
7878
//! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#channel-quiescence) for more information).
79+
//! - `ZeroFeeCommitments` - A channel type which always uses zero transaction fee on commitment transactions.
80+
//! (see [BOLT PR #1228](https://github.com/lightning/bolts/pull/1228) for more info).
7981
//!
8082
//! LDK knows about the following features, but does not support them:
8183
//! - `AnchorsNonzeroFeeHtlcTx` - the initial version of anchor outputs, which was later found to be
@@ -156,7 +158,7 @@ mod sealed {
156158
// Byte 4
157159
Quiescence | OnionMessages,
158160
// Byte 5
159-
ProvideStorage | ChannelType | SCIDPrivacy,
161+
ProvideStorage | ChannelType | SCIDPrivacy | AnchorZeroFeeCommitments,
160162
// Byte 6
161163
ZeroConf,
162164
// Byte 7
@@ -177,7 +179,7 @@ mod sealed {
177179
// Byte 4
178180
Quiescence | OnionMessages,
179181
// Byte 5
180-
ProvideStorage | ChannelType | SCIDPrivacy,
182+
ProvideStorage | ChannelType | SCIDPrivacy | AnchorZeroFeeCommitments,
181183
// Byte 6
182184
ZeroConf | Keysend,
183185
// Byte 7
@@ -242,7 +244,7 @@ mod sealed {
242244
// Byte 4
243245
,
244246
// Byte 5
245-
SCIDPrivacy,
247+
SCIDPrivacy | AnchorZeroFeeCommitments,
246248
// Byte 6
247249
ZeroConf,
248250
]);
@@ -251,7 +253,7 @@ mod sealed {
251253
/// useful for manipulating feature flags.
252254
macro_rules! define_feature {
253255
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr, $optional_setter: ident,
254-
$required_setter: ident, $supported_getter: ident) => {
256+
$required_setter: ident, $clear: ident, $supported_getter: ident) => {
255257
#[doc = $doc]
256258
///
257259
/// See [BOLT #9] for details.
@@ -354,6 +356,11 @@ mod sealed {
354356
<T as $feature>::set_required_bit(&mut self.flags);
355357
}
356358

359+
/// Unsets this feature.
360+
pub fn $clear(&mut self) {
361+
<T as $feature>::clear_bits(&mut self.flags);
362+
}
363+
357364
/// Checks if this feature is supported.
358365
pub fn $supported_getter(&self) -> bool {
359366
<T as $feature>::supports_feature(&self.flags)
@@ -377,8 +384,8 @@ mod sealed {
377384
)*
378385
};
379386
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr, $optional_setter: ident,
380-
$required_setter: ident, $supported_getter: ident, $required_getter: ident) => {
381-
define_feature!($odd_bit, $feature, [$($context),+], $doc, $optional_setter, $required_setter, $supported_getter);
387+
$required_setter: ident, $clear: ident, $supported_getter: ident, $required_getter: ident) => {
388+
define_feature!($odd_bit, $feature, [$($context),+], $doc, $optional_setter, $required_setter, $clear, $supported_getter);
382389
impl <T: $feature> Features<T> {
383390
/// Checks if this feature is required.
384391
pub fn $required_getter(&self) -> bool {
@@ -395,6 +402,7 @@ mod sealed {
395402
"Feature flags for `option_data_loss_protect`.",
396403
set_data_loss_protect_optional,
397404
set_data_loss_protect_required,
405+
clear_data_loss_protect,
398406
supports_data_loss_protect,
399407
requires_data_loss_protect
400408
);
@@ -406,6 +414,7 @@ mod sealed {
406414
"Feature flags for `initial_routing_sync`.",
407415
set_initial_routing_sync_optional,
408416
set_initial_routing_sync_required,
417+
clear_initial_routing_sync,
409418
initial_routing_sync
410419
);
411420
define_feature!(
@@ -415,6 +424,7 @@ mod sealed {
415424
"Feature flags for `option_upfront_shutdown_script`.",
416425
set_upfront_shutdown_script_optional,
417426
set_upfront_shutdown_script_required,
427+
clear_upfront_shutdown_script,
418428
supports_upfront_shutdown_script,
419429
requires_upfront_shutdown_script
420430
);
@@ -425,6 +435,7 @@ mod sealed {
425435
"Feature flags for `gossip_queries`.",
426436
set_gossip_queries_optional,
427437
set_gossip_queries_required,
438+
clear_gossip_queries,
428439
supports_gossip_queries,
429440
requires_gossip_queries
430441
);
@@ -435,6 +446,7 @@ mod sealed {
435446
"Feature flags for `var_onion_optin`.",
436447
set_variable_length_onion_optional,
437448
set_variable_length_onion_required,
449+
clear_variable_length_onion,
438450
supports_variable_length_onion,
439451
requires_variable_length_onion
440452
);
@@ -445,6 +457,7 @@ mod sealed {
445457
"Feature flags for `option_static_remotekey`.",
446458
set_static_remote_key_optional,
447459
set_static_remote_key_required,
460+
clear_static_remote_key,
448461
supports_static_remote_key,
449462
requires_static_remote_key
450463
);
@@ -455,6 +468,7 @@ mod sealed {
455468
"Feature flags for `payment_secret`.",
456469
set_payment_secret_optional,
457470
set_payment_secret_required,
471+
clear_payment_secret,
458472
supports_payment_secret,
459473
requires_payment_secret
460474
);
@@ -465,6 +479,7 @@ mod sealed {
465479
"Feature flags for `basic_mpp`.",
466480
set_basic_mpp_optional,
467481
set_basic_mpp_required,
482+
clear_basic_mpp,
468483
supports_basic_mpp,
469484
requires_basic_mpp
470485
);
@@ -475,6 +490,7 @@ mod sealed {
475490
"Feature flags for `option_support_large_channel` (aka wumbo channels).",
476491
set_wumbo_optional,
477492
set_wumbo_required,
493+
clear_wumbo,
478494
supports_wumbo,
479495
requires_wumbo
480496
);
@@ -485,6 +501,7 @@ mod sealed {
485501
"Feature flags for `option_anchors_nonzero_fee_htlc_tx`.",
486502
set_anchors_nonzero_fee_htlc_tx_optional,
487503
set_anchors_nonzero_fee_htlc_tx_required,
504+
clear_anchors_nonzero_fee_htlc_tx,
488505
supports_anchors_nonzero_fee_htlc_tx,
489506
requires_anchors_nonzero_fee_htlc_tx
490507
);
@@ -495,6 +512,7 @@ mod sealed {
495512
"Feature flags for `option_anchors_zero_fee_htlc_tx`.",
496513
set_anchors_zero_fee_htlc_tx_optional,
497514
set_anchors_zero_fee_htlc_tx_required,
515+
clear_anchors_zero_fee_htlc_tx,
498516
supports_anchors_zero_fee_htlc_tx,
499517
requires_anchors_zero_fee_htlc_tx
500518
);
@@ -505,6 +523,7 @@ mod sealed {
505523
"Feature flags for `option_route_blinding`.",
506524
set_route_blinding_optional,
507525
set_route_blinding_required,
526+
clear_route_blinding,
508527
supports_route_blinding,
509528
requires_route_blinding
510529
);
@@ -515,6 +534,7 @@ mod sealed {
515534
"Feature flags for `opt_shutdown_anysegwit`.",
516535
set_shutdown_any_segwit_optional,
517536
set_shutdown_any_segwit_required,
537+
clear_shutdown_anysegwit,
518538
supports_shutdown_anysegwit,
519539
requires_shutdown_anysegwit
520540
);
@@ -525,6 +545,7 @@ mod sealed {
525545
"Feature flags for `option_dual_fund`.",
526546
set_dual_fund_optional,
527547
set_dual_fund_required,
548+
clear_dual_fund,
528549
supports_dual_fund,
529550
requires_dual_fund
530551
);
@@ -535,6 +556,7 @@ mod sealed {
535556
"Feature flags for `option_taproot`.",
536557
set_taproot_optional,
537558
set_taproot_required,
559+
clear_taproot,
538560
supports_taproot,
539561
requires_taproot
540562
);
@@ -545,6 +567,7 @@ mod sealed {
545567
"Feature flags for `option_quiesce`.",
546568
set_quiescence_optional,
547569
set_quiescence_required,
570+
clear_quiescence,
548571
supports_quiescence,
549572
requires_quiescence
550573
);
@@ -555,16 +578,29 @@ mod sealed {
555578
"Feature flags for `option_onion_messages`.",
556579
set_onion_messages_optional,
557580
set_onion_messages_required,
581+
clear_onion_messages,
558582
supports_onion_messages,
559583
requires_onion_messages
560584
);
585+
define_feature!(
586+
41,
587+
AnchorZeroFeeCommitments,
588+
[InitContext, NodeContext, ChannelTypeContext],
589+
"Feature flags for `option_zero_fee_commitments`.",
590+
set_anchor_zero_fee_commitments_optional,
591+
set_anchor_zero_fee_commitments_required,
592+
clear_anchor_zero_fee_commitments,
593+
supports_anchor_zero_fee_commitments,
594+
requires_anchor_zero_fee_commitments
595+
);
561596
define_feature!(
562597
43,
563598
ProvideStorage,
564599
[InitContext, NodeContext],
565600
"Feature flags for `option_provide_storage`.",
566601
set_provide_storage_optional,
567602
set_provide_storage_required,
603+
clear_provide_storage,
568604
supports_provide_storage,
569605
requires_provide_storage
570606
);
@@ -575,19 +611,28 @@ mod sealed {
575611
"Feature flags for `option_channel_type`.",
576612
set_channel_type_optional,
577613
set_channel_type_required,
614+
clear_channel_type,
578615
supports_channel_type,
579616
requires_channel_type
580617
);
581-
define_feature!(47, SCIDPrivacy, [InitContext, NodeContext, ChannelTypeContext],
618+
define_feature!(47,
619+
SCIDPrivacy,
620+
[InitContext, NodeContext, ChannelTypeContext],
582621
"Feature flags for only forwarding with SCID aliasing. Called `option_scid_alias` in the BOLTs",
583-
set_scid_privacy_optional, set_scid_privacy_required, supports_scid_privacy, requires_scid_privacy);
622+
set_scid_privacy_optional,
623+
set_scid_privacy_required,
624+
clear_scid_privacy,
625+
supports_scid_privacy,
626+
requires_scid_privacy
627+
);
584628
define_feature!(
585629
49,
586630
PaymentMetadata,
587631
[Bolt11InvoiceContext],
588632
"Feature flags for payment metadata in invoices.",
589633
set_payment_metadata_optional,
590634
set_payment_metadata_required,
635+
clear_payment_metadata,
591636
supports_payment_metadata,
592637
requires_payment_metadata
593638
);
@@ -601,6 +646,7 @@ mod sealed {
601646
"Feature flags for keysend payments.",
602647
set_keysend_optional,
603648
set_keysend_required,
649+
clear_keysend,
604650
supports_keysend,
605651
requires_keysend
606652
);
@@ -611,6 +657,7 @@ mod sealed {
611657
"Feature flags for Trampoline routing.",
612658
set_trampoline_routing_optional,
613659
set_trampoline_routing_required,
660+
clear_trampoline_routing,
614661
supports_trampoline_routing,
615662
requires_trampoline_routing
616663
);
@@ -621,6 +668,7 @@ mod sealed {
621668
"Feature flags for DNS resolving.",
622669
set_dns_resolution_optional,
623670
set_dns_resolution_required,
671+
clear_dns_resolution,
624672
supports_dns_resolution,
625673
requires_dns_resolution
626674
);
@@ -643,6 +691,7 @@ mod sealed {
643691
"Feature flags for an unknown feature used in testing.",
644692
set_unknown_feature_optional,
645693
set_unknown_feature_required,
694+
clear_unknown_feature,
646695
supports_unknown_test_feature,
647696
requires_unknown_test_feature
648697
);
@@ -1038,51 +1087,6 @@ impl<T: sealed::Context> Features<T> {
10381087
}
10391088
}
10401089

1041-
impl<T: sealed::UpfrontShutdownScript> Features<T> {
1042-
/// Unsets the `upfront_shutdown_script` feature
1043-
pub fn clear_upfront_shutdown_script(mut self) -> Self {
1044-
<T as sealed::UpfrontShutdownScript>::clear_bits(&mut self.flags);
1045-
self
1046-
}
1047-
}
1048-
1049-
impl<T: sealed::ShutdownAnySegwit> Features<T> {
1050-
/// Unsets the `shutdown_anysegwit` feature
1051-
pub fn clear_shutdown_anysegwit(mut self) -> Self {
1052-
<T as sealed::ShutdownAnySegwit>::clear_bits(&mut self.flags);
1053-
self
1054-
}
1055-
}
1056-
1057-
impl<T: sealed::Wumbo> Features<T> {
1058-
/// Unsets the `wumbo` feature
1059-
pub fn clear_wumbo(mut self) -> Self {
1060-
<T as sealed::Wumbo>::clear_bits(&mut self.flags);
1061-
self
1062-
}
1063-
}
1064-
1065-
impl<T: sealed::SCIDPrivacy> Features<T> {
1066-
/// Unsets the `scid_privacy` feature
1067-
pub fn clear_scid_privacy(&mut self) {
1068-
<T as sealed::SCIDPrivacy>::clear_bits(&mut self.flags);
1069-
}
1070-
}
1071-
1072-
impl<T: sealed::AnchorsZeroFeeHtlcTx> Features<T> {
1073-
/// Unsets the `anchors_zero_fee_htlc_tx` feature
1074-
pub fn clear_anchors_zero_fee_htlc_tx(&mut self) {
1075-
<T as sealed::AnchorsZeroFeeHtlcTx>::clear_bits(&mut self.flags);
1076-
}
1077-
}
1078-
1079-
impl<T: sealed::RouteBlinding> Features<T> {
1080-
/// Unsets the `route_blinding` feature
1081-
pub fn clear_route_blinding(&mut self) {
1082-
<T as sealed::RouteBlinding>::clear_bits(&mut self.flags);
1083-
}
1084-
}
1085-
10861090
#[cfg(any(test, feature = "_test_utils"))]
10871091
impl<T: sealed::UnknownFeature> Features<T> {
10881092
/// Sets an unknown feature for testing

lightning/src/chain/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5149,7 +5149,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
51495149
{
51505150
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
51515151
counterparty_payment_script =
5152-
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
5152+
chan_utils::get_to_countersigner_keyed_anchor_redeemscript(&payment_point).to_p2wsh();
51535153
}
51545154

51555155
let channel_id = channel_id.unwrap_or(ChannelId::v1_from_funding_outpoint(outpoint));

lightning/src/chain/onchaintx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
666666

667667
// We'll locate an anchor output we can spend within the commitment transaction.
668668
let funding_pubkey = &self.channel_transaction_parameters.holder_pubkeys.funding_pubkey;
669-
match chan_utils::get_anchor_output(&tx.0, funding_pubkey) {
669+
match chan_utils::get_keyed_anchor_output(&tx.0, funding_pubkey) {
670670
// An anchor output was found, so we should yield a funding event externally.
671671
Some((idx, _)) => {
672672
// TODO: Use a lower confirmation target when both our and the

0 commit comments

Comments
 (0)