Skip to content

Commit d564c5e

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

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use crate::util::transaction_utils::sort_outputs;
4040
use crate::ln::channel::{INITIAL_COMMITMENT_NUMBER, ANCHOR_OUTPUT_VALUE_SATOSHI};
4141
use core::ops::Deref;
4242
use crate::chain;
43+
use crate::ln::features::ChannelTypeFeatures;
4344
use crate::util::crypto::{sign, sign_with_aux_rand};
4445

4546
/// Maximum number of one-way in-flight HTLC (protocol-level value).
@@ -769,6 +770,37 @@ pub fn build_htlc_input_witness(
769770
witness
770771
}
771772

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+
772804
/// Gets the witnessScript for the to_remote output when anchors are enabled.
773805
#[inline]
774806
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> Script {

0 commit comments

Comments
 (0)