@@ -581,6 +581,62 @@ 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+ /// Simplified accessor for checking if anchors are supported
595+ pub fn supports_anchors ( & self ) -> bool {
596+ self . supports_anchors_zero_fee_htlc_tx ( )
597+ }
598+
599+ /// There are six legacy structs where we need [`ChannelTypeFeatures`] for keeping track of
600+ /// anchors and Taproot support. Those six structs are
601+ /// — [`ChannelTransactionParameters`]
602+ /// — [`CommitmentTransaction`]
603+ /// — [`CounterpartyOfferedHTLCOutput`]
604+ /// — [`CounterpartyReceivedHTLCOutput`]
605+ /// — [`HolderHTLCOutput`]
606+ /// — [`HolderFundingOutput`]
607+ /// Because pre-anchors versions of LDK do not expect additional fields on those structs,
608+ /// non-anchor channels must serialize non-anchor features as empty options, i. e. not
609+ /// serialize them at all.
610+ /// However, when instantiating those objects based on the full set of features determined
611+ /// at channel construction, any additional feature bits will be lost in legacy channels.
612+ /// That would typically trigger a pre- and post-serialization equality check failure, so to
613+ /// avoid that, we hereby introduce a method that creates a watered-down, deserialization-safe
614+ /// copy.
615+ /// Note: this issue only affects unit testing!
616+ ///
617+ /// [`ChannelTransactionParameters`]: crate::ln::chan_utils::ChannelTransactionParameters
618+ /// [`CommitmentTransaction`]: crate::ln::chan_utils::CommitmentTransaction
619+ /// [`CounterpartyOfferedHTLCOutput`]: crate::chain::package::CounterpartyOfferedHTLCOutput
620+ /// [`CounterpartyReceivedHTLCOutput`]: crate::chain::package::CounterpartyReceivedHTLCOutput
621+ /// [`HolderHTLCOutput`]: crate::chain::package::HolderHTLCOutput
622+ /// [`HolderFundingOutput`]: crate::chain::package::HolderFundingOutput
623+ pub ( crate ) fn legacy_serialization_safe_version ( & self ) -> Self {
624+ if self . supports_anchors ( ) {
625+ self . clone ( )
626+ } else {
627+ Self :: only_static_remote_key ( )
628+ }
629+ }
630+
631+ /// To actually serialize the features in a manner that won't break the structs read by
632+ /// older versions of LDK, we should skip serialization entirely if anchors are not supported.
633+ /// This is a helper method to do just that.
634+ pub ( crate ) fn ldk_0_0_115_safe_serializable_option ( & self ) -> Option < Self > {
635+ if !self . supports_anchors ( ) {
636+ return None ;
637+ }
638+ Some ( self . clone ( ) )
639+ }
584640}
585641
586642impl ToBase32 for InvoiceFeatures {
0 commit comments