@@ -69,7 +69,7 @@ use crate::prelude::*;
69
69
use core::{cmp,mem,fmt};
70
70
use core::ops::Deref;
71
71
#[cfg(any(test, fuzzing, debug_assertions))]
72
- use crate::sync::Mutex;
72
+ use crate::sync::{Arc, Mutex} ;
73
73
use crate::sign::type_resolver::ChannelSignerType;
74
74
75
75
use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
@@ -1312,10 +1312,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1312
1312
1313
1313
#[cfg(debug_assertions)]
1314
1314
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1315
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1315
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1316
1316
#[cfg(debug_assertions)]
1317
1317
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1318
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1318
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1319
1319
1320
1320
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1321
1321
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1427,9 +1427,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1427
1427
// be, by comparing the cached values to the fee of the tranaction generated by
1428
1428
// `build_commitment_transaction`.
1429
1429
#[cfg(any(test, fuzzing))]
1430
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1430
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1431
1431
#[cfg(any(test, fuzzing))]
1432
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1432
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1433
1433
1434
1434
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1435
1435
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2127,9 +2127,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2127
2127
2128
2128
2129
2129
#[cfg(debug_assertions)]
2130
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2130
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat) ))),
2131
2131
#[cfg(debug_assertions)]
2132
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2132
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat) ))),
2133
2133
2134
2134
last_sent_closing_fee: None,
2135
2135
last_received_closing_sig: None,
@@ -2187,9 +2187,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2187
2187
announcement_sigs: None,
2188
2188
2189
2189
#[cfg(any(test, fuzzing))]
2190
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2190
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2191
2191
#[cfg(any(test, fuzzing))]
2192
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2192
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2193
2193
2194
2194
workaround_lnd_bug_4006: None,
2195
2195
sent_message_awaiting_response: None,
@@ -2365,9 +2365,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2365
2365
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2366
2366
// when we receive `accept_channel2`.
2367
2367
#[cfg(debug_assertions)]
2368
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2368
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2369
2369
#[cfg(debug_assertions)]
2370
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2370
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2371
2371
2372
2372
last_sent_closing_fee: None,
2373
2373
last_received_closing_sig: None,
@@ -2423,9 +2423,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2423
2423
announcement_sigs: None,
2424
2424
2425
2425
#[cfg(any(test, fuzzing))]
2426
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2426
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2427
2427
#[cfg(any(test, fuzzing))]
2428
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2428
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2429
2429
2430
2430
workaround_lnd_bug_4006: None,
2431
2431
sent_message_awaiting_response: None,
@@ -4093,11 +4093,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4093
4093
self.get_initial_counterparty_commitment_signature(logger)
4094
4094
}
4095
4095
4096
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4097
- /// a few non-cloneable fields (such as Secp256k1 context)
4096
+ /// Clone, each field, with the exception of the channel signer.
4098
4097
#[allow(unused)]
4099
4098
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4100
4099
Self {
4100
+ // Use provided channel signer
4101
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4102
+
4101
4103
config: self.config,
4102
4104
prev_config: self.prev_config,
4103
4105
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4106,12 +4108,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4106
4108
temporary_channel_id: self.temporary_channel_id,
4107
4109
channel_state: self.channel_state,
4108
4110
announcement_sigs_state: self.announcement_sigs_state.clone(),
4109
- // Create new Secp256k context
4110
- secp_ctx: Secp256k1::new(),
4111
+ secp_ctx: self.secp_ctx.clone(),
4111
4112
channel_value_satoshis: self.channel_value_satoshis,
4112
4113
latest_monitor_update_id: self.latest_monitor_update_id,
4113
- // Use provided channel signer
4114
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4115
4114
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4116
4115
destination_script: self.destination_script.clone(),
4117
4116
holder_commitment_point: self.holder_commitment_point,
@@ -4141,9 +4140,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4141
4140
update_time_counter: self.update_time_counter,
4142
4141
// Create new mutex with copied values
4143
4142
#[cfg(debug_assertions)]
4144
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4143
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4145
4144
#[cfg(debug_assertions)]
4146
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4145
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4147
4146
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4148
4147
last_received_closing_sig: self.last_received_closing_sig,
4149
4148
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4180,9 +4179,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4180
4179
announcement_sigs: self.announcement_sigs,
4181
4180
// Create new mutex with copied values
4182
4181
#[cfg(any(test, fuzzing))]
4183
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4182
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4184
4183
#[cfg(any(test, fuzzing))]
4185
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4184
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4186
4185
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4187
4186
sent_message_awaiting_response: self.sent_message_awaiting_response,
4188
4187
#[cfg(any(test, fuzzing))]
@@ -10162,9 +10161,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10162
10161
feerate_per_kw,
10163
10162
10164
10163
#[cfg(debug_assertions)]
10165
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10164
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10166
10165
#[cfg(debug_assertions)]
10167
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10166
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10168
10167
10169
10168
last_sent_closing_fee: None,
10170
10169
last_received_closing_sig: None,
@@ -10209,9 +10208,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10209
10208
announcement_sigs,
10210
10209
10211
10210
#[cfg(any(test, fuzzing))]
10212
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10211
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10213
10212
#[cfg(any(test, fuzzing))]
10214
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10213
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10215
10214
10216
10215
workaround_lnd_bug_4006: None,
10217
10216
sent_message_awaiting_response: None,
0 commit comments