@@ -2038,9 +2038,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
2038
2038
/// <https://github.com/lightningnetwork/lnd/issues/7682>.
2039
2039
sent_message_awaiting_response: Option<usize>,
2040
2040
2041
- /// This channel's type, as negotiated during channel open
2042
- channel_type: ChannelTypeFeatures,
2043
-
2044
2041
// Our counterparty can offer us SCID aliases which they will map to this channel when routing
2045
2042
// outbound payments. These can be used in invoice route hints to avoid explicitly revealing
2046
2043
// the channel's funding UTXO.
@@ -2785,7 +2782,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2785
2782
funding_tx_broadcast_safe_event_emitted: false,
2786
2783
channel_ready_event_emitted: false,
2787
2784
2788
- channel_type,
2789
2785
channel_keys_id,
2790
2786
2791
2787
local_initiated_shutdown: None,
@@ -3022,7 +3018,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3022
3018
funding_tx_broadcast_safe_event_emitted: false,
3023
3019
channel_ready_event_emitted: false,
3024
3020
3025
- channel_type,
3026
3021
channel_keys_id,
3027
3022
3028
3023
blocked_monitor_updates: Vec::new(),
@@ -3249,7 +3244,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3249
3244
}
3250
3245
3251
3246
if let Some(ty) = &common_fields.channel_type {
3252
- if * ty != self.channel_type {
3247
+ if ty != funding.get_channel_type() {
3253
3248
return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
3254
3249
}
3255
3250
} else if their_features.supports_channel_type() {
@@ -3259,7 +3254,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3259
3254
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
3260
3255
return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
3261
3256
}
3262
- self.channel_type = channel_type.clone();
3263
3257
funding.channel_transaction_parameters.channel_type_features = channel_type;
3264
3258
}
3265
3259
@@ -3627,11 +3621,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3627
3621
for (idx, (htlc, mut source_opt)) in htlcs_cloned.into_iter().enumerate() {
3628
3622
if let Some(_) = htlc.transaction_output_index {
3629
3623
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() ,
3631
3625
&keys.broadcaster_delayed_payment_key, &keys.revocation_key);
3632
3626
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 };
3635
3629
let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
3636
3630
log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
3637
3631
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 {
4058
4052
.checked_sub(dust_exposure_limiting_feerate);
4059
4053
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
4060
4054
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;
4062
4056
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;
4064
4058
extra_htlc_dust_exposure
4065
4059
});
4066
4060
@@ -4419,12 +4413,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4419
4413
}
4420
4414
4421
4415
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;
4423
4417
#[cfg(any(test, fuzzing))]
4424
4418
{
4425
4419
let mut fee = res;
4426
4420
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;
4428
4422
}
4429
4423
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
4430
4424
+ context.holding_cell_htlc_updates.len();
@@ -4516,12 +4510,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4516
4510
}
4517
4511
4518
4512
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;
4520
4514
#[cfg(any(test, fuzzing))]
4521
4515
if let Some(htlc) = &htlc {
4522
4516
let mut fee = res;
4523
4517
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;
4525
4519
}
4526
4520
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
4527
4521
let commitment_tx_info = CommitmentTxInfoCached {
@@ -4701,7 +4695,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4701
4695
{
4702
4696
return Err(());
4703
4697
}
4704
- if self.channel_type == ChannelTypeFeatures::only_static_remote_key() {
4698
+ if funding.get_channel_type() == & ChannelTypeFeatures::only_static_remote_key() {
4705
4699
// We've exhausted our options
4706
4700
return Err(());
4707
4701
}
@@ -4714,16 +4708,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4714
4708
// checks whether the counterparty supports every feature, this would only happen if the
4715
4709
// counterparty is advertising the feature, but rejecting channels proposing the feature for
4716
4710
// 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();
4719
4714
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();
4723
4718
} else {
4724
- self. channel_type = ChannelTypeFeatures::only_static_remote_key();
4719
+ * channel_type = ChannelTypeFeatures::only_static_remote_key();
4725
4720
}
4726
- funding.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
4727
4721
Ok(())
4728
4722
}
4729
4723
@@ -6816,7 +6810,7 @@ impl<SP: Deref> FundedChannel<SP> where
6816
6810
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
6817
6811
return Err(ChannelError::WarnAndDisconnect("Got fee update message while quiescent".to_owned()));
6818
6812
}
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)?;
6820
6814
6821
6815
self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
6822
6816
self.context.update_time_counter += 1;
@@ -9019,8 +9013,8 @@ impl<SP: Deref> FundedChannel<SP> where
9019
9013
9020
9014
for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(htlcs) {
9021
9015
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)),
9024
9018
log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
9025
9019
log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
9026
9020
}
@@ -9625,7 +9619,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9625
9619
Some(script) => script.clone().into_inner(),
9626
9620
None => Builder::new().into_script(),
9627
9621
}),
9628
- channel_type: Some(self.context.channel_type .clone()),
9622
+ channel_type: Some(self.funding.get_channel_type() .clone()),
9629
9623
},
9630
9624
push_msat: self.funding.get_value_satoshis() * 1000 - self.funding.value_to_self_msat,
9631
9625
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
@@ -9888,7 +9882,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9888
9882
Some(script) => script.clone().into_inner(),
9889
9883
None => Builder::new().into_script(),
9890
9884
}),
9891
- channel_type: Some(self.context.channel_type .clone()),
9885
+ channel_type: Some(self.funding.get_channel_type() .clone()),
9892
9886
},
9893
9887
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
9894
9888
#[cfg(taproot)]
@@ -10127,7 +10121,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
10127
10121
Some(script) => script.clone().into_inner(),
10128
10122
None => Builder::new().into_script(),
10129
10123
}),
10130
- channel_type: Some(self.context.channel_type .clone()),
10124
+ channel_type: Some(self.funding.get_channel_type() .clone()),
10131
10125
},
10132
10126
funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
10133
10127
second_per_commitment_point,
@@ -10297,7 +10291,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
10297
10291
Some(script) => script.clone().into_inner(),
10298
10292
None => Builder::new().into_script(),
10299
10293
}),
10300
- channel_type: Some(self.context.channel_type .clone()),
10294
+ channel_type: Some(self.funding.get_channel_type() .clone()),
10301
10295
},
10302
10296
funding_satoshis: self.dual_funding_context.our_funding_satoshis,
10303
10297
second_per_commitment_point,
@@ -10670,8 +10664,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10670
10664
// older clients fail to deserialize this channel at all. If the type is
10671
10665
// only-static-remote-key, we simply consider it "default" and don't write the channel type
10672
10666
// 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 };
10675
10669
10676
10670
// The same logic applies for `holder_selected_channel_reserve_satoshis` values other than
10677
10671
// 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
11102
11096
}
11103
11097
}
11104
11098
11105
- let chan_features = channel_type.as_ref(). unwrap();
11099
+ let chan_features = channel_type.unwrap();
11106
11100
if chan_features.supports_any_optional_bits() || chan_features.requires_unknown_bits_from(&our_supported_features) {
11107
11101
// If the channel was written by a new version and negotiated with features we don't
11108
11102
// 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
11111
11105
11112
11106
// ChannelTransactionParameters may have had an empty features set upon deserialization.
11113
11107
// 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;
11115
11109
11116
11110
let mut secp_ctx = Secp256k1::new();
11117
11111
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
11325
11319
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
11326
11320
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
11327
11321
11328
- channel_type: channel_type.unwrap(),
11329
11322
channel_keys_id,
11330
11323
11331
11324
local_initiated_shutdown,
@@ -12873,7 +12866,7 @@ mod tests {
12873
12866
&channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
12874
12867
&config, 0, 42, None, &logger
12875
12868
).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());
12877
12870
12878
12871
let mut expected_channel_type = ChannelTypeFeatures::empty();
12879
12872
expected_channel_type.set_static_remote_key_required();
@@ -12892,8 +12885,8 @@ mod tests {
12892
12885
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
12893
12886
).unwrap();
12894
12887
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);
12897
12890
}
12898
12891
12899
12892
#[test]
0 commit comments