@@ -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};
@@ -1371,10 +1371,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1371
1371
1372
1372
#[cfg(debug_assertions)]
1373
1373
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1374
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1374
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1375
1375
#[cfg(debug_assertions)]
1376
1376
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1377
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1377
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1378
1378
1379
1379
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1380
1380
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1486,9 +1486,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1486
1486
// be, by comparing the cached values to the fee of the tranaction generated by
1487
1487
// `build_commitment_transaction`.
1488
1488
#[cfg(any(test, fuzzing))]
1489
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1489
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1490
1490
#[cfg(any(test, fuzzing))]
1491
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1491
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1492
1492
1493
1493
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1494
1494
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2310,9 +2310,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2310
2310
2311
2311
2312
2312
#[cfg(debug_assertions)]
2313
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2313
+ 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) ))),
2314
2314
#[cfg(debug_assertions)]
2315
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2315
+ 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) ))),
2316
2316
2317
2317
last_sent_closing_fee: None,
2318
2318
last_received_closing_sig: None,
@@ -2370,9 +2370,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2370
2370
announcement_sigs: None,
2371
2371
2372
2372
#[cfg(any(test, fuzzing))]
2373
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2373
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2374
2374
#[cfg(any(test, fuzzing))]
2375
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2375
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2376
2376
2377
2377
workaround_lnd_bug_4006: None,
2378
2378
sent_message_awaiting_response: None,
@@ -2545,9 +2545,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2545
2545
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2546
2546
// when we receive `accept_channel2`.
2547
2547
#[cfg(debug_assertions)]
2548
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2548
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2549
2549
#[cfg(debug_assertions)]
2550
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2550
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2551
2551
2552
2552
last_sent_closing_fee: None,
2553
2553
last_received_closing_sig: None,
@@ -2603,9 +2603,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2603
2603
announcement_sigs: None,
2604
2604
2605
2605
#[cfg(any(test, fuzzing))]
2606
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2606
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2607
2607
#[cfg(any(test, fuzzing))]
2608
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2608
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2609
2609
2610
2610
workaround_lnd_bug_4006: None,
2611
2611
sent_message_awaiting_response: None,
@@ -4299,11 +4299,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4299
4299
self.get_initial_counterparty_commitment_signature(logger)
4300
4300
}
4301
4301
4302
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4303
- /// a few non-cloneable fields (such as Secp256k1 context)
4302
+ /// Clone, each field, with the exception of the channel signer.
4304
4303
#[allow(unused)]
4305
4304
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4306
4305
Self {
4306
+ // Use provided channel signer
4307
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4308
+
4307
4309
config: self.config,
4308
4310
prev_config: self.prev_config,
4309
4311
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4312,12 +4314,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4312
4314
temporary_channel_id: self.temporary_channel_id,
4313
4315
channel_state: self.channel_state,
4314
4316
announcement_sigs_state: self.announcement_sigs_state.clone(),
4315
- // Create new Secp256k context
4316
- secp_ctx: Secp256k1::new(),
4317
+ secp_ctx: self.secp_ctx.clone(),
4317
4318
channel_value_satoshis: self.channel_value_satoshis,
4318
4319
latest_monitor_update_id: self.latest_monitor_update_id,
4319
- // Use provided channel signer
4320
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4321
4320
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4322
4321
destination_script: self.destination_script.clone(),
4323
4322
holder_commitment_point: self.holder_commitment_point,
@@ -4347,9 +4346,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4347
4346
update_time_counter: self.update_time_counter,
4348
4347
// Create new mutex with copied values
4349
4348
#[cfg(debug_assertions)]
4350
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4349
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4351
4350
#[cfg(debug_assertions)]
4352
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4351
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4353
4352
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4354
4353
last_received_closing_sig: self.last_received_closing_sig,
4355
4354
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4386,9 +4385,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4386
4385
announcement_sigs: self.announcement_sigs,
4387
4386
// Create new mutex with copied values
4388
4387
#[cfg(any(test, fuzzing))]
4389
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4388
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4390
4389
#[cfg(any(test, fuzzing))]
4391
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4390
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4392
4391
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4393
4392
sent_message_awaiting_response: self.sent_message_awaiting_response,
4394
4393
#[cfg(any(test, fuzzing))]
@@ -10692,9 +10691,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10692
10691
feerate_per_kw,
10693
10692
10694
10693
#[cfg(debug_assertions)]
10695
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10694
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10696
10695
#[cfg(debug_assertions)]
10697
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10696
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10698
10697
10699
10698
last_sent_closing_fee: None,
10700
10699
last_received_closing_sig: None,
@@ -10739,9 +10738,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10739
10738
announcement_sigs,
10740
10739
10741
10740
#[cfg(any(test, fuzzing))]
10742
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10741
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10743
10742
#[cfg(any(test, fuzzing))]
10744
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10743
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10745
10744
10746
10745
workaround_lnd_bug_4006: None,
10747
10746
sent_message_awaiting_response: None,
0 commit comments