@@ -581,6 +581,57 @@ impl ChannelTypeFeatures {
581581 <sealed:: ChannelTypeContext as sealed:: StaticRemoteKey >:: set_required_bit ( & mut ret. flags ) ;
582582 ret
583583 }
584+
585+ #[ cfg( any( anchors, test) ) ]
586+ /// Constructs a ChannelTypeFeatures with anchors support
587+ pub ( crate ) fn static_remote_key_with_anchors ( ) -> Self {
588+ let mut ret = Self :: empty ( ) ;
589+ <sealed:: ChannelTypeContext as sealed:: StaticRemoteKey >:: set_required_bit ( & mut ret. flags ) ;
590+ <sealed:: ChannelTypeContext as sealed:: AnchorsZeroFeeHtlcTx >:: set_required_bit ( & mut ret. flags ) ;
591+ ret
592+ }
593+
594+ /// There are six legacy structs where we need [`ChannelTypeFeatures`] for keeping track of
595+ /// anchors and Taproot support. Those six structs are
596+ /// — [`ChannelTransactionParameters`]
597+ /// — [`CommitmentTransaction`]
598+ /// — [`CounterpartyOfferedHTLCOutput`]
599+ /// — [`CounterpartyReceivedHTLCOutput`]
600+ /// — [`HolderHTLCOutput`]
601+ /// — [`HolderFundingOutput`]
602+ /// Because pre-anchors versions of LDK do not expect additional fields on those structs,
603+ /// non-anchor channels must serialize non-anchor features as empty options, i. e. not
604+ /// serialize them at all.
605+ /// However, when instantiating those objects based on the full set of features determined
606+ /// at channel construction, any additional feature bits will be lost in legacy channels.
607+ /// That would typically trigger a pre- and post-serialization equality check failure, so to
608+ /// avoid that, we hereby introduce a method that creates a watered-down, deserialization-safe
609+ /// copy.
610+ /// Note: this issue only affects unit testing!
611+ ///
612+ /// [`ChannelTransactionParameters`]: crate::ln::chan_utils::ChannelTransactionParameters
613+ /// [`CommitmentTransaction`]: crate::ln::chan_utils::CommitmentTransaction
614+ /// [`CounterpartyOfferedHTLCOutput`]: crate::chain::package::CounterpartyOfferedHTLCOutput
615+ /// [`CounterpartyReceivedHTLCOutput`]: crate::chain::package::CounterpartyReceivedHTLCOutput
616+ /// [`HolderHTLCOutput`]: crate::chain::package::HolderHTLCOutput
617+ /// [`HolderFundingOutput`]: crate::chain::package::HolderFundingOutput
618+ pub ( crate ) fn legacy_serialization_safe_version ( & self ) -> Self {
619+ if self . supports_anchors_zero_fee_htlc_tx ( ) {
620+ self . clone ( )
621+ } else {
622+ Self :: only_static_remote_key ( )
623+ }
624+ }
625+
626+ /// To actually serialize the features in a manner that won't break the structs read by
627+ /// older versions of LDK, we should skip serialization entirely if anchors are not supported.
628+ /// This is a helper method to do just that.
629+ pub ( crate ) fn ldk_0_0_115_safe_serializable_option ( & self ) -> Option < Self > {
630+ if !self . supports_anchors_zero_fee_htlc_tx ( ) {
631+ return None ;
632+ }
633+ Some ( self . clone ( ) )
634+ }
584635}
585636
586637impl ToBase32 for InvoiceFeatures {
0 commit comments