@@ -1970,9 +1970,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
19701970 /// <https://github.com/lightningnetwork/lnd/issues/7682>.
19711971 sent_message_awaiting_response: Option<usize>,
19721972
1973- /// This channel's type, as negotiated during channel open
1974- channel_type: ChannelTypeFeatures,
1975-
19761973 // Our counterparty can offer us SCID aliases which they will map to this channel when routing
19771974 // outbound payments. These can be used in invoice route hints to avoid explicitly revealing
19781975 // the channel's funding UTXO.
@@ -2719,7 +2716,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27192716 funding_tx_broadcast_safe_event_emitted: false,
27202717 channel_ready_event_emitted: false,
27212718
2722- channel_type,
27232719 channel_keys_id,
27242720
27252721 local_initiated_shutdown: None,
@@ -2956,7 +2952,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29562952 funding_tx_broadcast_safe_event_emitted: false,
29572953 channel_ready_event_emitted: false,
29582954
2959- channel_type,
29602955 channel_keys_id,
29612956
29622957 blocked_monitor_updates: Vec::new(),
@@ -3183,7 +3178,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31833178 }
31843179
31853180 if let Some(ty) = &common_fields.channel_type {
3186- if * ty != self.channel_type {
3181+ if ty != funding.get_channel_type() {
31873182 return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
31883183 }
31893184 } else if their_features.supports_channel_type() {
@@ -3193,7 +3188,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31933188 if channel_type != ChannelTypeFeatures::only_static_remote_key() {
31943189 return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
31953190 }
3196- self.channel_type = channel_type.clone();
31973191 funding.channel_transaction_parameters.channel_type_features = channel_type;
31983192 }
31993193
@@ -3562,11 +3556,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35623556 for (idx, (htlc, mut source_opt)) in htlcs_cloned.drain(..).enumerate() {
35633557 if let Some(_) = htlc.transaction_output_index {
35643558 let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_data.stats.tx.feerate_per_kw(),
3565- funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, &self.channel_type ,
3559+ funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, funding.get_channel_type() ,
35663560 &holder_keys.broadcaster_delayed_payment_key, &holder_keys.revocation_key);
35673561
3568- let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &self.channel_type , &holder_keys);
3569- let htlc_sighashtype = if self.channel_type .supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
3562+ let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type() , &holder_keys);
3563+ let htlc_sighashtype = if funding.get_channel_type() .supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
35703564 let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
35713565 log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
35723566 log_bytes!(msg.htlc_signatures[idx].serialize_compact()[..]), log_bytes!(holder_keys.countersignatory_htlc_key.to_public_key().serialize()),
@@ -3964,9 +3958,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39643958 .checked_sub(dust_exposure_limiting_feerate);
39653959 let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
39663960 let extra_htlc_dust_exposure = on_counterparty_tx_dust_exposure_msat
3967- + 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;
3961+ + 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;
39683962 on_counterparty_tx_dust_exposure_msat
3969- += 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;
3963+ += 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;
39703964 extra_htlc_dust_exposure
39713965 });
39723966
@@ -4311,12 +4305,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43114305 }
43124306
43134307 let num_htlcs = included_htlcs + addl_htlcs;
4314- let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, &context.channel_type ) * 1000;
4308+ let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type() ) * 1000;
43154309 #[cfg(any(test, fuzzing))]
43164310 {
43174311 let mut fee = res;
43184312 if fee_spike_buffer_htlc.is_some() {
4319- fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, &context.channel_type ) * 1000;
4313+ fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type() ) * 1000;
43204314 }
43214315 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
43224316 + context.holding_cell_htlc_updates.len();
@@ -4408,12 +4402,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44084402 }
44094403
44104404 let num_htlcs = included_htlcs + addl_htlcs;
4411- let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, &context.channel_type ) * 1000;
4405+ let res = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type() ) * 1000;
44124406 #[cfg(any(test, fuzzing))]
44134407 if let Some(htlc) = &htlc {
44144408 let mut fee = res;
44154409 if fee_spike_buffer_htlc.is_some() {
4416- fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, &context.channel_type ) * 1000;
4410+ fee = commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type() ) * 1000;
44174411 }
44184412 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
44194413 let commitment_tx_info = CommitmentTxInfoCached {
@@ -4593,7 +4587,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
45934587 {
45944588 return Err(());
45954589 }
4596- if self.channel_type == ChannelTypeFeatures::only_static_remote_key() {
4590+ if funding.get_channel_type() == & ChannelTypeFeatures::only_static_remote_key() {
45974591 // We've exhausted our options
45984592 return Err(());
45994593 }
@@ -4606,16 +4600,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
46064600 // checks whether the counterparty supports every feature, this would only happen if the
46074601 // counterparty is advertising the feature, but rejecting channels proposing the feature for
46084602 // whatever reason.
4609- if self.channel_type.supports_anchors_zero_fee_htlc_tx() {
4610- self.channel_type.clear_anchors_zero_fee_htlc_tx();
4603+ let channel_type = &mut funding.channel_transaction_parameters.channel_type_features;
4604+ if channel_type.supports_anchors_zero_fee_htlc_tx() {
4605+ channel_type.clear_anchors_zero_fee_htlc_tx();
46114606 self.feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
4612- assert!(!funding.channel_transaction_parameters.channel_type_features .supports_anchors_nonzero_fee_htlc_tx());
4613- } else if self. channel_type.supports_scid_privacy() {
4614- self. channel_type.clear_scid_privacy();
4607+ assert!(!channel_type .supports_anchors_nonzero_fee_htlc_tx());
4608+ } else if channel_type.supports_scid_privacy() {
4609+ channel_type.clear_scid_privacy();
46154610 } else {
4616- self. channel_type = ChannelTypeFeatures::only_static_remote_key();
4611+ * channel_type = ChannelTypeFeatures::only_static_remote_key();
46174612 }
4618- funding.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
46194613 Ok(())
46204614 }
46214615
@@ -6641,7 +6635,7 @@ impl<SP: Deref> FundedChannel<SP> where
66416635 if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
66426636 return Err(ChannelError::WarnAndDisconnect("Got fee update message while quiescent".to_owned()));
66436637 }
6644- FundedChannel::<SP>::check_remote_fee(& self.context.channel_type , fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
6638+ FundedChannel::<SP>::check_remote_fee(self.funding.get_channel_type() , fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
66456639
66466640 self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
66476641 self.context.update_time_counter += 1;
@@ -8807,8 +8801,8 @@ impl<SP: Deref> FundedChannel<SP> where
88078801 debug_assert_eq!(htlc_signatures.len(), trusted_tx.htlcs().len());
88088802 for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(trusted_tx.htlcs()) {
88098803 log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {} in channel {}",
8810- encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.feerate_per_kw(), self.funding.get_holder_selected_contest_delay(), htlc, & self.context.channel_type , &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
8811- encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, & self.context.channel_type , &counterparty_keys)),
8804+ encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.feerate_per_kw(), self.funding.get_holder_selected_contest_delay(), htlc, self.funding.get_channel_type() , &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
8805+ encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, self.funding.get_channel_type() , &counterparty_keys)),
88128806 log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
88138807 log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
88148808 }
@@ -9409,7 +9403,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
94099403 Some(script) => script.clone().into_inner(),
94109404 None => Builder::new().into_script(),
94119405 }),
9412- channel_type: Some(self.context.channel_type .clone()),
9406+ channel_type: Some(self.funding.get_channel_type() .clone()),
94139407 },
94149408 push_msat: self.funding.get_value_satoshis() * 1000 - self.funding.value_to_self_msat,
94159409 channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
@@ -9670,7 +9664,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
96709664 Some(script) => script.clone().into_inner(),
96719665 None => Builder::new().into_script(),
96729666 }),
9673- channel_type: Some(self.context.channel_type .clone()),
9667+ channel_type: Some(self.funding.get_channel_type() .clone()),
96749668 },
96759669 channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
96769670 #[cfg(taproot)]
@@ -9907,7 +9901,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
99079901 Some(script) => script.clone().into_inner(),
99089902 None => Builder::new().into_script(),
99099903 }),
9910- channel_type: Some(self.context.channel_type .clone()),
9904+ channel_type: Some(self.funding.get_channel_type() .clone()),
99119905 },
99129906 funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
99139907 second_per_commitment_point,
@@ -10077,7 +10071,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1007710071 Some(script) => script.clone().into_inner(),
1007810072 None => Builder::new().into_script(),
1007910073 }),
10080- channel_type: Some(self.context.channel_type .clone()),
10074+ channel_type: Some(self.funding.get_channel_type() .clone()),
1008110075 },
1008210076 funding_satoshis: self.dual_funding_context.our_funding_satoshis,
1008310077 second_per_commitment_point,
@@ -10450,8 +10444,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1045010444 // older clients fail to deserialize this channel at all. If the type is
1045110445 // only-static-remote-key, we simply consider it "default" and don't write the channel type
1045210446 // out at all.
10453- let chan_type = if self.context.channel_type != ChannelTypeFeatures::only_static_remote_key() {
10454- Some(& self.context.channel_type ) } else { None };
10447+ let chan_type = if self.funding.get_channel_type() != & ChannelTypeFeatures::only_static_remote_key() {
10448+ Some(self.funding.get_channel_type() ) } else { None };
1045510449
1045610450 // The same logic applies for `holder_selected_channel_reserve_satoshis` values other than
1045710451 // the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
@@ -10878,7 +10872,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1087810872 }
1087910873 }
1088010874
10881- let chan_features = channel_type.as_ref(). unwrap();
10875+ let chan_features = channel_type.unwrap();
1088210876 if chan_features.supports_any_optional_bits() || chan_features.requires_unknown_bits_from(&our_supported_features) {
1088310877 // If the channel was written by a new version and negotiated with features we don't
1088410878 // understand yet, refuse to read it.
@@ -10887,7 +10881,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1088710881
1088810882 // ChannelTransactionParameters may have had an empty features set upon deserialization.
1088910883 // To account for that, we're proactively setting/overriding the field here.
10890- channel_parameters.channel_type_features = chan_features.clone() ;
10884+ channel_parameters.channel_type_features = chan_features;
1089110885
1089210886 let mut secp_ctx = Secp256k1::new();
1089310887 secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
@@ -11099,7 +11093,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1109911093 channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
1110011094 channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
1110111095
11102- channel_type: channel_type.unwrap(),
1110311096 channel_keys_id,
1110411097
1110511098 local_initiated_shutdown,
@@ -12638,7 +12631,7 @@ mod tests {
1263812631 &channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
1263912632 &config, 0, 42, None, &logger
1264012633 ).unwrap();
12641- assert!(!channel_a.context.channel_type .supports_anchors_zero_fee_htlc_tx());
12634+ assert!(!channel_a.funding.get_channel_type() .supports_anchors_zero_fee_htlc_tx());
1264212635
1264312636 let mut expected_channel_type = ChannelTypeFeatures::empty();
1264412637 expected_channel_type.set_static_remote_key_required();
@@ -12657,8 +12650,8 @@ mod tests {
1265712650 &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
1265812651 ).unwrap();
1265912652
12660- assert_eq!(channel_a.context.channel_type, expected_channel_type);
12661- assert_eq!(channel_b.context.channel_type, expected_channel_type);
12653+ assert_eq!(channel_a.funding.get_channel_type(), & expected_channel_type);
12654+ assert_eq!(channel_b.funding.get_channel_type(), & expected_channel_type);
1266212655 }
1266312656
1266412657 #[test]
0 commit comments