@@ -1970,9 +1970,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1970
1970
/// <https://github.com/lightningnetwork/lnd/issues/7682>.
1971
1971
sent_message_awaiting_response: Option<usize>,
1972
1972
1973
- /// This channel's type, as negotiated during channel open
1974
- channel_type: ChannelTypeFeatures,
1975
-
1976
1973
// Our counterparty can offer us SCID aliases which they will map to this channel when routing
1977
1974
// outbound payments. These can be used in invoice route hints to avoid explicitly revealing
1978
1975
// the channel's funding UTXO.
@@ -2719,7 +2716,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2719
2716
funding_tx_broadcast_safe_event_emitted: false,
2720
2717
channel_ready_event_emitted: false,
2721
2718
2722
- channel_type,
2723
2719
channel_keys_id,
2724
2720
2725
2721
local_initiated_shutdown: None,
@@ -2956,7 +2952,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2956
2952
funding_tx_broadcast_safe_event_emitted: false,
2957
2953
channel_ready_event_emitted: false,
2958
2954
2959
- channel_type,
2960
2955
channel_keys_id,
2961
2956
2962
2957
blocked_monitor_updates: Vec::new(),
@@ -3183,7 +3178,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3183
3178
}
3184
3179
3185
3180
if let Some(ty) = &common_fields.channel_type {
3186
- if * ty != self.channel_type {
3181
+ if ty != funding.get_channel_type() {
3187
3182
return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
3188
3183
}
3189
3184
} else if their_features.supports_channel_type() {
@@ -3193,7 +3188,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3193
3188
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
3194
3189
return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
3195
3190
}
3196
- self.channel_type = channel_type.clone();
3197
3191
funding.channel_transaction_parameters.channel_type_features = channel_type;
3198
3192
}
3199
3193
@@ -3562,11 +3556,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3562
3556
for (idx, (htlc, mut source_opt)) in htlcs_cloned.drain(..).enumerate() {
3563
3557
if let Some(_) = htlc.transaction_output_index {
3564
3558
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() ,
3566
3560
&holder_keys.broadcaster_delayed_payment_key, &holder_keys.revocation_key);
3567
3561
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 };
3570
3564
let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
3571
3565
log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
3572
3566
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 {
3964
3958
.checked_sub(dust_exposure_limiting_feerate);
3965
3959
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
3966
3960
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;
3968
3962
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;
3970
3964
extra_htlc_dust_exposure
3971
3965
});
3972
3966
@@ -4311,12 +4305,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4311
4305
}
4312
4306
4313
4307
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;
4315
4309
#[cfg(any(test, fuzzing))]
4316
4310
{
4317
4311
let mut fee = res;
4318
4312
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;
4320
4314
}
4321
4315
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
4322
4316
+ context.holding_cell_htlc_updates.len();
@@ -4408,12 +4402,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4408
4402
}
4409
4403
4410
4404
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;
4412
4406
#[cfg(any(test, fuzzing))]
4413
4407
if let Some(htlc) = &htlc {
4414
4408
let mut fee = res;
4415
4409
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;
4417
4411
}
4418
4412
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
4419
4413
let commitment_tx_info = CommitmentTxInfoCached {
@@ -4593,7 +4587,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4593
4587
{
4594
4588
return Err(());
4595
4589
}
4596
- if self.channel_type == ChannelTypeFeatures::only_static_remote_key() {
4590
+ if funding.get_channel_type() == & ChannelTypeFeatures::only_static_remote_key() {
4597
4591
// We've exhausted our options
4598
4592
return Err(());
4599
4593
}
@@ -4606,16 +4600,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4606
4600
// checks whether the counterparty supports every feature, this would only happen if the
4607
4601
// counterparty is advertising the feature, but rejecting channels proposing the feature for
4608
4602
// 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();
4611
4606
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();
4615
4610
} else {
4616
- self. channel_type = ChannelTypeFeatures::only_static_remote_key();
4611
+ * channel_type = ChannelTypeFeatures::only_static_remote_key();
4617
4612
}
4618
- funding.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
4619
4613
Ok(())
4620
4614
}
4621
4615
@@ -6641,7 +6635,7 @@ impl<SP: Deref> FundedChannel<SP> where
6641
6635
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
6642
6636
return Err(ChannelError::WarnAndDisconnect("Got fee update message while quiescent".to_owned()));
6643
6637
}
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)?;
6645
6639
6646
6640
self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
6647
6641
self.context.update_time_counter += 1;
@@ -8807,8 +8801,8 @@ impl<SP: Deref> FundedChannel<SP> where
8807
8801
debug_assert_eq!(htlc_signatures.len(), trusted_tx.htlcs().len());
8808
8802
for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(trusted_tx.htlcs()) {
8809
8803
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)),
8812
8806
log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
8813
8807
log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
8814
8808
}
@@ -9409,7 +9403,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9409
9403
Some(script) => script.clone().into_inner(),
9410
9404
None => Builder::new().into_script(),
9411
9405
}),
9412
- channel_type: Some(self.context.channel_type .clone()),
9406
+ channel_type: Some(self.funding.get_channel_type() .clone()),
9413
9407
},
9414
9408
push_msat: self.funding.get_value_satoshis() * 1000 - self.funding.value_to_self_msat,
9415
9409
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
@@ -9670,7 +9664,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9670
9664
Some(script) => script.clone().into_inner(),
9671
9665
None => Builder::new().into_script(),
9672
9666
}),
9673
- channel_type: Some(self.context.channel_type .clone()),
9667
+ channel_type: Some(self.funding.get_channel_type() .clone()),
9674
9668
},
9675
9669
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
9676
9670
#[cfg(taproot)]
@@ -9907,7 +9901,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9907
9901
Some(script) => script.clone().into_inner(),
9908
9902
None => Builder::new().into_script(),
9909
9903
}),
9910
- channel_type: Some(self.context.channel_type .clone()),
9904
+ channel_type: Some(self.funding.get_channel_type() .clone()),
9911
9905
},
9912
9906
funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
9913
9907
second_per_commitment_point,
@@ -10077,7 +10071,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
10077
10071
Some(script) => script.clone().into_inner(),
10078
10072
None => Builder::new().into_script(),
10079
10073
}),
10080
- channel_type: Some(self.context.channel_type .clone()),
10074
+ channel_type: Some(self.funding.get_channel_type() .clone()),
10081
10075
},
10082
10076
funding_satoshis: self.dual_funding_context.our_funding_satoshis,
10083
10077
second_per_commitment_point,
@@ -10450,8 +10444,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10450
10444
// older clients fail to deserialize this channel at all. If the type is
10451
10445
// only-static-remote-key, we simply consider it "default" and don't write the channel type
10452
10446
// 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 };
10455
10449
10456
10450
// The same logic applies for `holder_selected_channel_reserve_satoshis` values other than
10457
10451
// 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
10878
10872
}
10879
10873
}
10880
10874
10881
- let chan_features = channel_type.as_ref(). unwrap();
10875
+ let chan_features = channel_type.unwrap();
10882
10876
if chan_features.supports_any_optional_bits() || chan_features.requires_unknown_bits_from(&our_supported_features) {
10883
10877
// If the channel was written by a new version and negotiated with features we don't
10884
10878
// 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
10887
10881
10888
10882
// ChannelTransactionParameters may have had an empty features set upon deserialization.
10889
10883
// 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;
10891
10885
10892
10886
let mut secp_ctx = Secp256k1::new();
10893
10887
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
11099
11093
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
11100
11094
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
11101
11095
11102
- channel_type: channel_type.unwrap(),
11103
11096
channel_keys_id,
11104
11097
11105
11098
local_initiated_shutdown,
@@ -12638,7 +12631,7 @@ mod tests {
12638
12631
&channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
12639
12632
&config, 0, 42, None, &logger
12640
12633
).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());
12642
12635
12643
12636
let mut expected_channel_type = ChannelTypeFeatures::empty();
12644
12637
expected_channel_type.set_static_remote_key_required();
@@ -12657,8 +12650,8 @@ mod tests {
12657
12650
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
12658
12651
).unwrap();
12659
12652
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);
12662
12655
}
12663
12656
12664
12657
#[test]
0 commit comments