Skip to content

Commit 9134fdf

Browse files
committed
Method for ChannelTypeFeatures serialization forwards compatibility.
1 parent 4ffb677 commit 9134fdf

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,37 @@ pub fn build_htlc_input_witness(
769769
witness
770770
}
771771

772+
/// Pre-anchors channel type features did not use to get serialized in the following six structs:
773+
/// — [`ChannelTransactionParameters`]
774+
/// — [`CommitmentTransaction`]
775+
/// — [`CounterpartyOfferedHTLCOutput`]
776+
/// — [`CounterpartyReceivedHTLCOutput`]
777+
/// — [`HolderHTLCOutput`]
778+
/// — [`HolderFundingOutput`]
779+
///
780+
/// To ensure a forwards-compatible serialization, we use odd TLV fields. However, if new features
781+
/// are used that could break security, where old signers should be prevented from handling the
782+
/// serialized data, an optional even-field TLV will be used as a stand-in to break compatibility.
783+
///
784+
/// This method determines whether or not that option needs to be set based on the chanenl type
785+
/// features, and returns it.
786+
///
787+
/// [`CounterpartyOfferedHTLCOutput`]: crate::chain::package::CounterpartyOfferedHTLCOutput
788+
/// [`CounterpartyReceivedHTLCOutput`]: crate::chain::package::CounterpartyReceivedHTLCOutput
789+
/// [`HolderHTLCOutput`]: crate::chain::package::HolderHTLCOutput
790+
/// [`HolderFundingOutput`]: crate::chain::package::HolderFundingOutput
791+
pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features(features: &ChannelTypeFeatures) -> Option<()> {
792+
let mut legacy_version_bit_set = ChannelTypeFeatures::only_static_remote_key();
793+
legacy_version_bit_set.set_scid_privacy_required();
794+
legacy_version_bit_set.set_zero_conf_required();
795+
796+
if features.is_subset(&legacy_version_bit_set) {
797+
None
798+
} else {
799+
Some(())
800+
}
801+
}
802+
772803
/// Gets the witnessScript for the to_remote output when anchors are enabled.
773804
#[inline]
774805
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> Script {

0 commit comments

Comments
 (0)