@@ -2041,9 +2041,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
20412041 /// <https://github.com/lightningnetwork/lnd/issues/7682>.
20422042 sent_message_awaiting_response: Option<usize>,
20432043
2044- /// This channel's type, as negotiated during channel open
2045- channel_type: ChannelTypeFeatures,
2046-
20472044 // Our counterparty can offer us SCID aliases which they will map to this channel when routing
20482045 // outbound payments. These can be used in invoice route hints to avoid explicitly revealing
20492046 // the channel's funding UTXO.
@@ -2790,7 +2787,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27902787 funding_tx_broadcast_safe_event_emitted: false,
27912788 channel_ready_event_emitted: false,
27922789
2793- channel_type,
27942790 channel_keys_id,
27952791
27962792 local_initiated_shutdown: None,
@@ -3027,7 +3023,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30273023 funding_tx_broadcast_safe_event_emitted: false,
30283024 channel_ready_event_emitted: false,
30293025
3030- channel_type,
30313026 channel_keys_id,
30323027
30333028 blocked_monitor_updates: Vec::new(),
@@ -3254,7 +3249,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32543249 }
32553250
32563251 if let Some(ty) = &common_fields.channel_type {
3257- if * ty != self.channel_type {
3252+ if ty != funding.get_channel_type() {
32583253 return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
32593254 }
32603255 } else if their_features.supports_channel_type() {
@@ -3264,7 +3259,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32643259 if channel_type != ChannelTypeFeatures::only_static_remote_key() {
32653260 return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
32663261 }
3267- self.channel_type = channel_type.clone();
32683262 funding.channel_transaction_parameters.channel_type_features = channel_type;
32693263 }
32703264
@@ -3633,11 +3627,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
36333627 for (idx, (htlc, mut source_opt)) in htlcs_cloned.into_iter().enumerate() {
36343628 if let Some(_) = htlc.transaction_output_index {
36353629 let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_data.stats.tx.feerate_per_kw(),
3636- funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, &self.channel_type ,
3630+ funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, funding.get_channel_type() ,
36373631 &holder_keys.broadcaster_delayed_payment_key, &holder_keys.revocation_key);
36383632
3639- let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &self.channel_type , &holder_keys);
3640- let htlc_sighashtype = if self.channel_type .supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
3633+ let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type() , &holder_keys);
3634+ let htlc_sighashtype = if funding.get_channel_type() .supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
36413635 let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
36423636 log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
36433637 log_bytes!(msg.htlc_signatures[idx].serialize_compact()[..]), log_bytes!(holder_keys.countersignatory_htlc_key.to_public_key().serialize()),
@@ -4035,9 +4029,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40354029 .checked_sub(dust_exposure_limiting_feerate);
40364030 let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
40374031 let extra_htlc_dust_exposure = on_counterparty_tx_dust_exposure_msat
4038- + 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;
4032+ + 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;
40394033 on_counterparty_tx_dust_exposure_msat
4040- += 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;
4034+ += 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;
40414035 extra_htlc_dust_exposure
40424036 });
40434037
@@ -4396,12 +4390,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43964390 }
43974391
43984392 let num_htlcs = included_htlcs + addl_htlcs;
4399- let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, &context.channel_type ) * 1000;
4393+ let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type() ) * 1000;
44004394 #[cfg(any(test, fuzzing))]
44014395 {
44024396 let mut fee = res;
44034397 if fee_spike_buffer_htlc.is_some() {
4404- fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, &context.channel_type ) * 1000;
4398+ fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type() ) * 1000;
44054399 }
44064400 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
44074401 + context.holding_cell_htlc_updates.len();
@@ -4493,12 +4487,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44934487 }
44944488
44954489 let num_htlcs = included_htlcs + addl_htlcs;
4496- let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, &context.channel_type ) * 1000;
4490+ let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type() ) * 1000;
44974491 #[cfg(any(test, fuzzing))]
44984492 if let Some(htlc) = &htlc {
44994493 let mut fee = res;
45004494 if fee_spike_buffer_htlc.is_some() {
4501- fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, &context.channel_type ) * 1000;
4495+ fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type() ) * 1000;
45024496 }
45034497 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
45044498 let commitment_tx_info = CommitmentTxInfoCached {
@@ -4678,7 +4672,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
46784672 {
46794673 return Err(());
46804674 }
4681- if self.channel_type == ChannelTypeFeatures::only_static_remote_key() {
4675+ if funding.get_channel_type() == & ChannelTypeFeatures::only_static_remote_key() {
46824676 // We've exhausted our options
46834677 return Err(());
46844678 }
@@ -4691,16 +4685,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
46914685 // checks whether the counterparty supports every feature, this would only happen if the
46924686 // counterparty is advertising the feature, but rejecting channels proposing the feature for
46934687 // whatever reason.
4694- if self.channel_type.supports_anchors_zero_fee_htlc_tx() {
4695- self.channel_type.clear_anchors_zero_fee_htlc_tx();
4688+ let channel_type = &mut funding.channel_transaction_parameters.channel_type_features;
4689+ if channel_type.supports_anchors_zero_fee_htlc_tx() {
4690+ channel_type.clear_anchors_zero_fee_htlc_tx();
46964691 self.feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
4697- assert!(!funding.channel_transaction_parameters.channel_type_features .supports_anchors_nonzero_fee_htlc_tx());
4698- } else if self. channel_type.supports_scid_privacy() {
4699- self. channel_type.clear_scid_privacy();
4692+ assert!(!channel_type .supports_anchors_nonzero_fee_htlc_tx());
4693+ } else if channel_type.supports_scid_privacy() {
4694+ channel_type.clear_scid_privacy();
47004695 } else {
4701- self. channel_type = ChannelTypeFeatures::only_static_remote_key();
4696+ * channel_type = ChannelTypeFeatures::only_static_remote_key();
47024697 }
4703- funding.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
47044698 Ok(())
47054699 }
47064700
@@ -6796,7 +6790,7 @@ impl<SP: Deref> FundedChannel<SP> where
67966790 if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
67976791 return Err(ChannelError::WarnAndDisconnect("Got fee update message while quiescent".to_owned()));
67986792 }
6799- FundedChannel::<SP>::check_remote_fee(& self.context.channel_type , fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
6793+ FundedChannel::<SP>::check_remote_fee(self.funding.get_channel_type() , fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
68006794
68016795 self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
68026796 self.context.update_time_counter += 1;
@@ -9003,8 +8997,8 @@ impl<SP: Deref> FundedChannel<SP> where
90038997 debug_assert_eq!(htlc_signatures.len(), trusted_tx.htlcs().len());
90048998 for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(trusted_tx.htlcs()) {
90058999 log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {} in channel {}",
9006- encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.feerate_per_kw(), funding.get_holder_selected_contest_delay(), htlc, &self.context.channel_type , &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
9007- encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, & self.context.channel_type , &counterparty_keys)),
9000+ encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.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)),
9001+ encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, self.funding.get_channel_type() , &counterparty_keys)),
90089002 log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
90099003 log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
90109004 }
@@ -9611,7 +9605,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
96119605 Some(script) => script.clone().into_inner(),
96129606 None => Builder::new().into_script(),
96139607 }),
9614- channel_type: Some(self.context.channel_type .clone()),
9608+ channel_type: Some(self.funding.get_channel_type() .clone()),
96159609 },
96169610 push_msat: self.funding.get_value_satoshis() * 1000 - self.funding.value_to_self_msat,
96179611 channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
@@ -9874,7 +9868,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
98749868 Some(script) => script.clone().into_inner(),
98759869 None => Builder::new().into_script(),
98769870 }),
9877- channel_type: Some(self.context.channel_type .clone()),
9871+ channel_type: Some(self.funding.get_channel_type() .clone()),
98789872 },
98799873 channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
98809874 #[cfg(taproot)]
@@ -10113,7 +10107,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1011310107 Some(script) => script.clone().into_inner(),
1011410108 None => Builder::new().into_script(),
1011510109 }),
10116- channel_type: Some(self.context.channel_type .clone()),
10110+ channel_type: Some(self.funding.get_channel_type() .clone()),
1011710111 },
1011810112 funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
1011910113 second_per_commitment_point,
@@ -10283,7 +10277,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1028310277 Some(script) => script.clone().into_inner(),
1028410278 None => Builder::new().into_script(),
1028510279 }),
10286- channel_type: Some(self.context.channel_type .clone()),
10280+ channel_type: Some(self.funding.get_channel_type() .clone()),
1028710281 },
1028810282 funding_satoshis: self.dual_funding_context.our_funding_satoshis,
1028910283 second_per_commitment_point,
@@ -10656,8 +10650,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1065610650 // older clients fail to deserialize this channel at all. If the type is
1065710651 // only-static-remote-key, we simply consider it "default" and don't write the channel type
1065810652 // out at all.
10659- let chan_type = if self.context.channel_type != ChannelTypeFeatures::only_static_remote_key() {
10660- Some(& self.context.channel_type ) } else { None };
10653+ let chan_type = if self.funding.get_channel_type() != & ChannelTypeFeatures::only_static_remote_key() {
10654+ Some(self.funding.get_channel_type() ) } else { None };
1066110655
1066210656 // The same logic applies for `holder_selected_channel_reserve_satoshis` values other than
1066310657 // the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
@@ -11088,7 +11082,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1108811082 }
1108911083 }
1109011084
11091- let chan_features = channel_type.as_ref(). unwrap();
11085+ let chan_features = channel_type.unwrap();
1109211086 if chan_features.supports_any_optional_bits() || chan_features.requires_unknown_bits_from(&our_supported_features) {
1109311087 // If the channel was written by a new version and negotiated with features we don't
1109411088 // understand yet, refuse to read it.
@@ -11097,7 +11091,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1109711091
1109811092 // ChannelTransactionParameters may have had an empty features set upon deserialization.
1109911093 // To account for that, we're proactively setting/overriding the field here.
11100- channel_parameters.channel_type_features = chan_features.clone() ;
11094+ channel_parameters.channel_type_features = chan_features;
1110111095
1110211096 let mut secp_ctx = Secp256k1::new();
1110311097 secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
@@ -11311,7 +11305,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1131111305 channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
1131211306 channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
1131311307
11314- channel_type: channel_type.unwrap(),
1131511308 channel_keys_id,
1131611309
1131711310 local_initiated_shutdown,
@@ -12850,7 +12843,7 @@ mod tests {
1285012843 &channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
1285112844 &config, 0, 42, None, &logger
1285212845 ).unwrap();
12853- assert!(!channel_a.context.channel_type .supports_anchors_zero_fee_htlc_tx());
12846+ assert!(!channel_a.funding.get_channel_type() .supports_anchors_zero_fee_htlc_tx());
1285412847
1285512848 let mut expected_channel_type = ChannelTypeFeatures::empty();
1285612849 expected_channel_type.set_static_remote_key_required();
@@ -12869,8 +12862,8 @@ mod tests {
1286912862 &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
1287012863 ).unwrap();
1287112864
12872- assert_eq!(channel_a.context.channel_type, expected_channel_type);
12873- assert_eq!(channel_b.context.channel_type, expected_channel_type);
12865+ assert_eq!(channel_a.funding.get_channel_type(), & expected_channel_type);
12866+ assert_eq!(channel_b.funding.get_channel_type(), & expected_channel_type);
1287412867 }
1287512868
1287612869 #[test]
0 commit comments