@@ -40,6 +40,7 @@ use crate::util::transaction_utils::sort_outputs;
40
40
use crate :: ln:: channel:: { INITIAL_COMMITMENT_NUMBER , ANCHOR_OUTPUT_VALUE_SATOSHI } ;
41
41
use core:: ops:: Deref ;
42
42
use crate :: chain;
43
+ use crate :: ln:: features:: ChannelTypeFeatures ;
43
44
use crate :: util:: crypto:: { sign, sign_with_aux_rand} ;
44
45
45
46
/// Maximum number of one-way in-flight HTLC (protocol-level value).
@@ -769,6 +770,37 @@ pub fn build_htlc_input_witness(
769
770
witness
770
771
}
771
772
773
+ /// Pre-anchors channel type features did not use to get serialized in the following six structs:
774
+ /// — [`ChannelTransactionParameters`]
775
+ /// — [`CommitmentTransaction`]
776
+ /// — [`CounterpartyOfferedHTLCOutput`]
777
+ /// — [`CounterpartyReceivedHTLCOutput`]
778
+ /// — [`HolderHTLCOutput`]
779
+ /// — [`HolderFundingOutput`]
780
+ ///
781
+ /// To ensure a forwards-compatible serialization, we use odd TLV fields. However, if new features
782
+ /// are used that could break security, where old signers should be prevented from handling the
783
+ /// serialized data, an optional even-field TLV will be used as a stand-in to break compatibility.
784
+ ///
785
+ /// This method determines whether or not that option needs to be set based on the chanenl type
786
+ /// features, and returns it.
787
+ ///
788
+ /// [`CounterpartyOfferedHTLCOutput`]: crate::chain::package::CounterpartyOfferedHTLCOutput
789
+ /// [`CounterpartyReceivedHTLCOutput`]: crate::chain::package::CounterpartyReceivedHTLCOutput
790
+ /// [`HolderHTLCOutput`]: crate::chain::package::HolderHTLCOutput
791
+ /// [`HolderFundingOutput`]: crate::chain::package::HolderFundingOutput
792
+ pub ( crate ) fn legacy_deserialization_prevention_marker_for_channel_type_features ( features : & ChannelTypeFeatures ) -> Option < ( ) > {
793
+ let mut legacy_version_bit_set = ChannelTypeFeatures :: only_static_remote_key ( ) ;
794
+ legacy_version_bit_set. set_scid_privacy_required ( ) ;
795
+ legacy_version_bit_set. set_zero_conf_required ( ) ;
796
+
797
+ if features. is_subset ( & legacy_version_bit_set) {
798
+ None
799
+ } else {
800
+ Some ( ( ) )
801
+ }
802
+ }
803
+
772
804
/// Gets the witnessScript for the to_remote output when anchors are enabled.
773
805
#[ inline]
774
806
pub fn get_to_countersignatory_with_anchors_redeemscript ( payment_point : & PublicKey ) -> Script {
0 commit comments