@@ -2038,9 +2038,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
20382038 /// <https://github.com/lightningnetwork/lnd/issues/7682>.
20392039 sent_message_awaiting_response: Option<usize>,
20402040
2041- /// This channel's type, as negotiated during channel open
2042- channel_type: ChannelTypeFeatures,
2043-
20442041 // Our counterparty can offer us SCID aliases which they will map to this channel when routing
20452042 // outbound payments. These can be used in invoice route hints to avoid explicitly revealing
20462043 // the channel's funding UTXO.
@@ -2785,7 +2782,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27852782 funding_tx_broadcast_safe_event_emitted: false,
27862783 channel_ready_event_emitted: false,
27872784
2788- channel_type,
27892785 channel_keys_id,
27902786
27912787 local_initiated_shutdown: None,
@@ -3022,7 +3018,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30223018 funding_tx_broadcast_safe_event_emitted: false,
30233019 channel_ready_event_emitted: false,
30243020
3025- channel_type,
30263021 channel_keys_id,
30273022
30283023 blocked_monitor_updates: Vec::new(),
@@ -3249,7 +3244,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32493244 }
32503245
32513246 if let Some(ty) = &common_fields.channel_type {
3252- if * ty != self.channel_type {
3247+ if ty != funding.get_channel_type() {
32533248 return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
32543249 }
32553250 } else if their_features.supports_channel_type() {
@@ -3259,7 +3254,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32593254 if channel_type != ChannelTypeFeatures::only_static_remote_key() {
32603255 return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
32613256 }
3262- self.channel_type = channel_type.clone();
32633257 funding.channel_transaction_parameters.channel_type_features = channel_type;
32643258 }
32653259
@@ -3627,11 +3621,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
36273621 for (idx, (htlc, mut source_opt)) in htlcs_cloned.into_iter().enumerate() {
36283622 if let Some(_) = htlc.transaction_output_index {
36293623 let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_stats.feerate_per_kw,
3630- funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, &self.channel_type ,
3624+ funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, funding.get_channel_type() ,
36313625 &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
36323626
3633- let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &self.channel_type , &keys);
3634- let htlc_sighashtype = if self.channel_type .supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
3627+ let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type() , &keys);
3628+ let htlc_sighashtype = if funding.get_channel_type() .supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
36353629 let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
36363630 log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
36373631 log_bytes!(msg.htlc_signatures[idx].serialize_compact()[..]), log_bytes!(keys.countersignatory_htlc_key.to_public_key().serialize()),
@@ -4058,9 +4052,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40584052 .checked_sub(dust_exposure_limiting_feerate);
40594053 let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
40604054 let extra_htlc_dust_exposure = on_counterparty_tx_dust_exposure_msat
4061- + chan_utils::commit_and_htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, &self.channel_type ) * 1000;
4055+ + chan_utils::commit_and_htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type() ) * 1000;
40624056 on_counterparty_tx_dust_exposure_msat
4063- += chan_utils::commit_and_htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs, on_counterparty_tx_offered_nondust_htlcs, &self.channel_type ) * 1000;
4057+ += chan_utils::commit_and_htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type() ) * 1000;
40644058 extra_htlc_dust_exposure
40654059 });
40664060
@@ -4419,12 +4413,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44194413 }
44204414
44214415 let num_htlcs = included_htlcs + addl_htlcs;
4422- let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, &context.channel_type ) * 1000;
4416+ let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type() ) * 1000;
44234417 #[cfg(any(test, fuzzing))]
44244418 {
44254419 let mut fee = res;
44264420 if fee_spike_buffer_htlc.is_some() {
4427- fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, &context.channel_type ) * 1000;
4421+ fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type() ) * 1000;
44284422 }
44294423 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
44304424 + context.holding_cell_htlc_updates.len();
@@ -4516,12 +4510,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
45164510 }
45174511
45184512 let num_htlcs = included_htlcs + addl_htlcs;
4519- let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, &context.channel_type ) * 1000;
4513+ let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type() ) * 1000;
45204514 #[cfg(any(test, fuzzing))]
45214515 if let Some(htlc) = &htlc {
45224516 let mut fee = res;
45234517 if fee_spike_buffer_htlc.is_some() {
4524- fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, &context.channel_type ) * 1000;
4518+ fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type() ) * 1000;
45254519 }
45264520 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
45274521 let commitment_tx_info = CommitmentTxInfoCached {
@@ -4701,7 +4695,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
47014695 {
47024696 return Err(());
47034697 }
4704- if self.channel_type == ChannelTypeFeatures::only_static_remote_key() {
4698+ if funding.get_channel_type() == & ChannelTypeFeatures::only_static_remote_key() {
47054699 // We've exhausted our options
47064700 return Err(());
47074701 }
@@ -4714,16 +4708,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
47144708 // checks whether the counterparty supports every feature, this would only happen if the
47154709 // counterparty is advertising the feature, but rejecting channels proposing the feature for
47164710 // whatever reason.
4717- if self.channel_type.supports_anchors_zero_fee_htlc_tx() {
4718- self.channel_type.clear_anchors_zero_fee_htlc_tx();
4711+ let channel_type = &mut funding.channel_transaction_parameters.channel_type_features;
4712+ if channel_type.supports_anchors_zero_fee_htlc_tx() {
4713+ channel_type.clear_anchors_zero_fee_htlc_tx();
47194714 self.feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
4720- assert!(!funding.channel_transaction_parameters.channel_type_features .supports_anchors_nonzero_fee_htlc_tx());
4721- } else if self. channel_type.supports_scid_privacy() {
4722- self. channel_type.clear_scid_privacy();
4715+ assert!(!channel_type .supports_anchors_nonzero_fee_htlc_tx());
4716+ } else if channel_type.supports_scid_privacy() {
4717+ channel_type.clear_scid_privacy();
47234718 } else {
4724- self. channel_type = ChannelTypeFeatures::only_static_remote_key();
4719+ * channel_type = ChannelTypeFeatures::only_static_remote_key();
47254720 }
4726- funding.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
47274721 Ok(())
47284722 }
47294723
@@ -6816,7 +6810,7 @@ impl<SP: Deref> FundedChannel<SP> where
68166810 if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
68176811 return Err(ChannelError::WarnAndDisconnect("Got fee update message while quiescent".to_owned()));
68186812 }
6819- FundedChannel::<SP>::check_remote_fee(& self.context.channel_type , fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
6813+ FundedChannel::<SP>::check_remote_fee(self.funding.get_channel_type() , fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
68206814
68216815 self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
68226816 self.context.update_time_counter += 1;
@@ -9019,8 +9013,8 @@ impl<SP: Deref> FundedChannel<SP> where
90199013
90209014 for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(htlcs) {
90219015 log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {} in channel {}",
9022- encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_txid, commitment_stats.feerate_per_kw, funding.get_holder_selected_contest_delay(), htlc, & self.context.channel_type , &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
9023- encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, & self.context.channel_type , &counterparty_keys)),
9016+ encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_txid, commitment_stats.feerate_per_kw, funding.get_holder_selected_contest_delay(), htlc, self.funding.get_channel_type() , &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
9017+ encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, self.funding.get_channel_type() , &counterparty_keys)),
90249018 log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
90259019 log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
90269020 }
@@ -9625,7 +9619,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
96259619 Some(script) => script.clone().into_inner(),
96269620 None => Builder::new().into_script(),
96279621 }),
9628- channel_type: Some(self.context.channel_type .clone()),
9622+ channel_type: Some(self.funding.get_channel_type() .clone()),
96299623 },
96309624 push_msat: self.funding.get_value_satoshis() * 1000 - self.funding.value_to_self_msat,
96319625 channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
@@ -9888,7 +9882,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
98889882 Some(script) => script.clone().into_inner(),
98899883 None => Builder::new().into_script(),
98909884 }),
9891- channel_type: Some(self.context.channel_type .clone()),
9885+ channel_type: Some(self.funding.get_channel_type() .clone()),
98929886 },
98939887 channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
98949888 #[cfg(taproot)]
@@ -10127,7 +10121,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1012710121 Some(script) => script.clone().into_inner(),
1012810122 None => Builder::new().into_script(),
1012910123 }),
10130- channel_type: Some(self.context.channel_type .clone()),
10124+ channel_type: Some(self.funding.get_channel_type() .clone()),
1013110125 },
1013210126 funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
1013310127 second_per_commitment_point,
@@ -10297,7 +10291,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1029710291 Some(script) => script.clone().into_inner(),
1029810292 None => Builder::new().into_script(),
1029910293 }),
10300- channel_type: Some(self.context.channel_type .clone()),
10294+ channel_type: Some(self.funding.get_channel_type() .clone()),
1030110295 },
1030210296 funding_satoshis: self.dual_funding_context.our_funding_satoshis,
1030310297 second_per_commitment_point,
@@ -10670,8 +10664,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1067010664 // older clients fail to deserialize this channel at all. If the type is
1067110665 // only-static-remote-key, we simply consider it "default" and don't write the channel type
1067210666 // out at all.
10673- let chan_type = if self.context.channel_type != ChannelTypeFeatures::only_static_remote_key() {
10674- Some(& self.context.channel_type ) } else { None };
10667+ let chan_type = if self.funding.get_channel_type() != & ChannelTypeFeatures::only_static_remote_key() {
10668+ Some(self.funding.get_channel_type() ) } else { None };
1067510669
1067610670 // The same logic applies for `holder_selected_channel_reserve_satoshis` values other than
1067710671 // the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
@@ -11102,7 +11096,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1110211096 }
1110311097 }
1110411098
11105- let chan_features = channel_type.as_ref(). unwrap();
11099+ let chan_features = channel_type.unwrap();
1110611100 if chan_features.supports_any_optional_bits() || chan_features.requires_unknown_bits_from(&our_supported_features) {
1110711101 // If the channel was written by a new version and negotiated with features we don't
1110811102 // understand yet, refuse to read it.
@@ -11111,7 +11105,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1111111105
1111211106 // ChannelTransactionParameters may have had an empty features set upon deserialization.
1111311107 // To account for that, we're proactively setting/overriding the field here.
11114- channel_parameters.channel_type_features = chan_features.clone() ;
11108+ channel_parameters.channel_type_features = chan_features;
1111511109
1111611110 let mut secp_ctx = Secp256k1::new();
1111711111 secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
@@ -11325,7 +11319,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1132511319 channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
1132611320 channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
1132711321
11328- channel_type: channel_type.unwrap(),
1132911322 channel_keys_id,
1133011323
1133111324 local_initiated_shutdown,
@@ -12873,7 +12866,7 @@ mod tests {
1287312866 &channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
1287412867 &config, 0, 42, None, &logger
1287512868 ).unwrap();
12876- assert!(!channel_a.context.channel_type .supports_anchors_zero_fee_htlc_tx());
12869+ assert!(!channel_a.funding.get_channel_type() .supports_anchors_zero_fee_htlc_tx());
1287712870
1287812871 let mut expected_channel_type = ChannelTypeFeatures::empty();
1287912872 expected_channel_type.set_static_remote_key_required();
@@ -12892,8 +12885,8 @@ mod tests {
1289212885 &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
1289312886 ).unwrap();
1289412887
12895- assert_eq!(channel_a.context.channel_type, expected_channel_type);
12896- assert_eq!(channel_b.context.channel_type, expected_channel_type);
12888+ assert_eq!(channel_a.funding.get_channel_type(), & expected_channel_type);
12889+ assert_eq!(channel_b.funding.get_channel_type(), & expected_channel_type);
1289712890 }
1289812891
1289912892 #[test]
0 commit comments