@@ -68,7 +68,7 @@ use crate::prelude::*;
68
68
use core::{cmp,mem,fmt};
69
69
use core::ops::Deref;
70
70
#[cfg(any(test, fuzzing, debug_assertions))]
71
- use crate::sync::Mutex;
71
+ use crate::sync::{Arc, Mutex} ;
72
72
use crate::sign::type_resolver::ChannelSignerType;
73
73
74
74
use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
@@ -1364,10 +1364,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1364
1364
1365
1365
#[cfg(debug_assertions)]
1366
1366
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1367
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1367
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1368
1368
#[cfg(debug_assertions)]
1369
1369
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1370
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1370
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1371
1371
1372
1372
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1373
1373
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1479,9 +1479,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1479
1479
// be, by comparing the cached values to the fee of the tranaction generated by
1480
1480
// `build_commitment_transaction`.
1481
1481
#[cfg(any(test, fuzzing))]
1482
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1482
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1483
1483
#[cfg(any(test, fuzzing))]
1484
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1484
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1485
1485
1486
1486
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1487
1487
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2243,9 +2243,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2243
2243
2244
2244
2245
2245
#[cfg(debug_assertions)]
2246
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2246
+ 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) ))),
2247
2247
#[cfg(debug_assertions)]
2248
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2248
+ 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) ))),
2249
2249
2250
2250
last_sent_closing_fee: None,
2251
2251
last_received_closing_sig: None,
@@ -2303,9 +2303,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2303
2303
announcement_sigs: None,
2304
2304
2305
2305
#[cfg(any(test, fuzzing))]
2306
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2306
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2307
2307
#[cfg(any(test, fuzzing))]
2308
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2308
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2309
2309
2310
2310
workaround_lnd_bug_4006: None,
2311
2311
sent_message_awaiting_response: None,
@@ -2481,9 +2481,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2481
2481
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2482
2482
// when we receive `accept_channel2`.
2483
2483
#[cfg(debug_assertions)]
2484
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2484
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2485
2485
#[cfg(debug_assertions)]
2486
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2486
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2487
2487
2488
2488
last_sent_closing_fee: None,
2489
2489
last_received_closing_sig: None,
@@ -2539,9 +2539,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2539
2539
announcement_sigs: None,
2540
2540
2541
2541
#[cfg(any(test, fuzzing))]
2542
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2542
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2543
2543
#[cfg(any(test, fuzzing))]
2544
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2544
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2545
2545
2546
2546
workaround_lnd_bug_4006: None,
2547
2547
sent_message_awaiting_response: None,
@@ -4244,11 +4244,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4244
4244
self.get_initial_counterparty_commitment_signature(logger)
4245
4245
}
4246
4246
4247
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4248
- /// a few non-cloneable fields (such as Secp256k1 context)
4247
+ /// Clone, each field, with the exception of the channel signer.
4249
4248
#[allow(unused)]
4250
4249
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4251
4250
Self {
4251
+ // Use provided channel signer
4252
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4253
+
4252
4254
config: self.config,
4253
4255
prev_config: self.prev_config,
4254
4256
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4257,12 +4259,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4257
4259
temporary_channel_id: self.temporary_channel_id,
4258
4260
channel_state: self.channel_state,
4259
4261
announcement_sigs_state: self.announcement_sigs_state.clone(),
4260
- // Create new Secp256k context
4261
- secp_ctx: Secp256k1::new(),
4262
+ secp_ctx: self.secp_ctx.clone(),
4262
4263
channel_value_satoshis: self.channel_value_satoshis,
4263
4264
latest_monitor_update_id: self.latest_monitor_update_id,
4264
- // Use provided channel signer
4265
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4266
4265
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4267
4266
destination_script: self.destination_script.clone(),
4268
4267
holder_commitment_point: self.holder_commitment_point,
@@ -4292,9 +4291,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4292
4291
update_time_counter: self.update_time_counter,
4293
4292
// Create new mutex with copied values
4294
4293
#[cfg(debug_assertions)]
4295
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4294
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4296
4295
#[cfg(debug_assertions)]
4297
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4296
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4298
4297
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4299
4298
last_received_closing_sig: self.last_received_closing_sig,
4300
4299
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4331,9 +4330,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4331
4330
announcement_sigs: self.announcement_sigs,
4332
4331
// Create new mutex with copied values
4333
4332
#[cfg(any(test, fuzzing))]
4334
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4333
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4335
4334
#[cfg(any(test, fuzzing))]
4336
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4335
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4337
4336
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4338
4337
sent_message_awaiting_response: self.sent_message_awaiting_response,
4339
4338
#[cfg(any(test, fuzzing))]
@@ -10524,9 +10523,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10524
10523
feerate_per_kw,
10525
10524
10526
10525
#[cfg(debug_assertions)]
10527
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10526
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10528
10527
#[cfg(debug_assertions)]
10529
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10528
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10530
10529
10531
10530
last_sent_closing_fee: None,
10532
10531
last_received_closing_sig: None,
@@ -10571,9 +10570,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10571
10570
announcement_sigs,
10572
10571
10573
10572
#[cfg(any(test, fuzzing))]
10574
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10573
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10575
10574
#[cfg(any(test, fuzzing))]
10576
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10575
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10577
10576
10578
10577
workaround_lnd_bug_4006: None,
10579
10578
sent_message_awaiting_response: None,
0 commit comments