@@ -2041,9 +2041,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
2041
2041
/// <https://github.com/lightningnetwork/lnd/issues/7682>.
2042
2042
sent_message_awaiting_response: Option<usize>,
2043
2043
2044
- /// This channel's type, as negotiated during channel open
2045
- channel_type: ChannelTypeFeatures,
2046
-
2047
2044
// Our counterparty can offer us SCID aliases which they will map to this channel when routing
2048
2045
// outbound payments. These can be used in invoice route hints to avoid explicitly revealing
2049
2046
// the channel's funding UTXO.
@@ -2790,7 +2787,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2790
2787
funding_tx_broadcast_safe_event_emitted: false,
2791
2788
channel_ready_event_emitted: false,
2792
2789
2793
- channel_type,
2794
2790
channel_keys_id,
2795
2791
2796
2792
local_initiated_shutdown: None,
@@ -3027,7 +3023,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3027
3023
funding_tx_broadcast_safe_event_emitted: false,
3028
3024
channel_ready_event_emitted: false,
3029
3025
3030
- channel_type,
3031
3026
channel_keys_id,
3032
3027
3033
3028
blocked_monitor_updates: Vec::new(),
@@ -3254,7 +3249,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3254
3249
}
3255
3250
3256
3251
if let Some(ty) = &common_fields.channel_type {
3257
- if * ty != self.channel_type {
3252
+ if ty != funding.get_channel_type() {
3258
3253
return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
3259
3254
}
3260
3255
} else if their_features.supports_channel_type() {
@@ -3264,7 +3259,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3264
3259
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
3265
3260
return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
3266
3261
}
3267
- self.channel_type = channel_type.clone();
3268
3262
funding.channel_transaction_parameters.channel_type_features = channel_type;
3269
3263
}
3270
3264
@@ -3633,11 +3627,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3633
3627
for (idx, (htlc, mut source_opt)) in htlcs_cloned.into_iter().enumerate() {
3634
3628
if let Some(_) = htlc.transaction_output_index {
3635
3629
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() ,
3637
3631
&holder_keys.broadcaster_delayed_payment_key, &holder_keys.revocation_key);
3638
3632
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 };
3641
3635
let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
3642
3636
log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
3643
3637
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 {
4035
4029
.checked_sub(dust_exposure_limiting_feerate);
4036
4030
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
4037
4031
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;
4039
4033
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;
4041
4035
extra_htlc_dust_exposure
4042
4036
});
4043
4037
@@ -4396,12 +4390,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4396
4390
}
4397
4391
4398
4392
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;
4400
4394
#[cfg(any(test, fuzzing))]
4401
4395
{
4402
4396
let mut fee = res;
4403
4397
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;
4405
4399
}
4406
4400
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
4407
4401
+ context.holding_cell_htlc_updates.len();
@@ -4493,12 +4487,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4493
4487
}
4494
4488
4495
4489
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;
4497
4491
#[cfg(any(test, fuzzing))]
4498
4492
if let Some(htlc) = &htlc {
4499
4493
let mut fee = res;
4500
4494
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;
4502
4496
}
4503
4497
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
4504
4498
let commitment_tx_info = CommitmentTxInfoCached {
@@ -4678,7 +4672,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4678
4672
{
4679
4673
return Err(());
4680
4674
}
4681
- if self.channel_type == ChannelTypeFeatures::only_static_remote_key() {
4675
+ if funding.get_channel_type() == & ChannelTypeFeatures::only_static_remote_key() {
4682
4676
// We've exhausted our options
4683
4677
return Err(());
4684
4678
}
@@ -4691,16 +4685,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4691
4685
// checks whether the counterparty supports every feature, this would only happen if the
4692
4686
// counterparty is advertising the feature, but rejecting channels proposing the feature for
4693
4687
// 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();
4696
4691
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();
4700
4695
} else {
4701
- self. channel_type = ChannelTypeFeatures::only_static_remote_key();
4696
+ * channel_type = ChannelTypeFeatures::only_static_remote_key();
4702
4697
}
4703
- funding.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
4704
4698
Ok(())
4705
4699
}
4706
4700
@@ -6796,7 +6790,7 @@ impl<SP: Deref> FundedChannel<SP> where
6796
6790
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
6797
6791
return Err(ChannelError::WarnAndDisconnect("Got fee update message while quiescent".to_owned()));
6798
6792
}
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)?;
6800
6794
6801
6795
self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
6802
6796
self.context.update_time_counter += 1;
@@ -9003,8 +8997,8 @@ impl<SP: Deref> FundedChannel<SP> where
9003
8997
debug_assert_eq!(htlc_signatures.len(), trusted_tx.htlcs().len());
9004
8998
for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(trusted_tx.htlcs()) {
9005
8999
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)),
9008
9002
log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
9009
9003
log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
9010
9004
}
@@ -9611,7 +9605,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9611
9605
Some(script) => script.clone().into_inner(),
9612
9606
None => Builder::new().into_script(),
9613
9607
}),
9614
- channel_type: Some(self.context.channel_type .clone()),
9608
+ channel_type: Some(self.funding.get_channel_type() .clone()),
9615
9609
},
9616
9610
push_msat: self.funding.get_value_satoshis() * 1000 - self.funding.value_to_self_msat,
9617
9611
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
@@ -9874,7 +9868,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9874
9868
Some(script) => script.clone().into_inner(),
9875
9869
None => Builder::new().into_script(),
9876
9870
}),
9877
- channel_type: Some(self.context.channel_type .clone()),
9871
+ channel_type: Some(self.funding.get_channel_type() .clone()),
9878
9872
},
9879
9873
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
9880
9874
#[cfg(taproot)]
@@ -10113,7 +10107,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
10113
10107
Some(script) => script.clone().into_inner(),
10114
10108
None => Builder::new().into_script(),
10115
10109
}),
10116
- channel_type: Some(self.context.channel_type .clone()),
10110
+ channel_type: Some(self.funding.get_channel_type() .clone()),
10117
10111
},
10118
10112
funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
10119
10113
second_per_commitment_point,
@@ -10283,7 +10277,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
10283
10277
Some(script) => script.clone().into_inner(),
10284
10278
None => Builder::new().into_script(),
10285
10279
}),
10286
- channel_type: Some(self.context.channel_type .clone()),
10280
+ channel_type: Some(self.funding.get_channel_type() .clone()),
10287
10281
},
10288
10282
funding_satoshis: self.dual_funding_context.our_funding_satoshis,
10289
10283
second_per_commitment_point,
@@ -10656,8 +10650,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10656
10650
// older clients fail to deserialize this channel at all. If the type is
10657
10651
// only-static-remote-key, we simply consider it "default" and don't write the channel type
10658
10652
// 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 };
10661
10655
10662
10656
// The same logic applies for `holder_selected_channel_reserve_satoshis` values other than
10663
10657
// 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
11088
11082
}
11089
11083
}
11090
11084
11091
- let chan_features = channel_type.as_ref(). unwrap();
11085
+ let chan_features = channel_type.unwrap();
11092
11086
if chan_features.supports_any_optional_bits() || chan_features.requires_unknown_bits_from(&our_supported_features) {
11093
11087
// If the channel was written by a new version and negotiated with features we don't
11094
11088
// 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
11097
11091
11098
11092
// ChannelTransactionParameters may have had an empty features set upon deserialization.
11099
11093
// 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;
11101
11095
11102
11096
let mut secp_ctx = Secp256k1::new();
11103
11097
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
11311
11305
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
11312
11306
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
11313
11307
11314
- channel_type: channel_type.unwrap(),
11315
11308
channel_keys_id,
11316
11309
11317
11310
local_initiated_shutdown,
@@ -12850,7 +12843,7 @@ mod tests {
12850
12843
&channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
12851
12844
&config, 0, 42, None, &logger
12852
12845
).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());
12854
12847
12855
12848
let mut expected_channel_type = ChannelTypeFeatures::empty();
12856
12849
expected_channel_type.set_static_remote_key_required();
@@ -12869,8 +12862,8 @@ mod tests {
12869
12862
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
12870
12863
).unwrap();
12871
12864
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);
12874
12867
}
12875
12868
12876
12869
#[test]
0 commit comments