@@ -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};
@@ -1365,10 +1365,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1365
1365
1366
1366
#[cfg(debug_assertions)]
1367
1367
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1368
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1368
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1369
1369
#[cfg(debug_assertions)]
1370
1370
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1371
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1371
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1372
1372
1373
1373
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1374
1374
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1480,9 +1480,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1480
1480
// be, by comparing the cached values to the fee of the tranaction generated by
1481
1481
// `build_commitment_transaction`.
1482
1482
#[cfg(any(test, fuzzing))]
1483
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1483
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1484
1484
#[cfg(any(test, fuzzing))]
1485
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1485
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1486
1486
1487
1487
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1488
1488
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2295,9 +2295,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2295
2295
2296
2296
2297
2297
#[cfg(debug_assertions)]
2298
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2298
+ 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) ))),
2299
2299
#[cfg(debug_assertions)]
2300
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2300
+ 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) ))),
2301
2301
2302
2302
last_sent_closing_fee: None,
2303
2303
last_received_closing_sig: None,
@@ -2355,9 +2355,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2355
2355
announcement_sigs: None,
2356
2356
2357
2357
#[cfg(any(test, fuzzing))]
2358
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2358
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2359
2359
#[cfg(any(test, fuzzing))]
2360
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2360
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2361
2361
2362
2362
workaround_lnd_bug_4006: None,
2363
2363
sent_message_awaiting_response: None,
@@ -2533,9 +2533,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2533
2533
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2534
2534
// when we receive `accept_channel2`.
2535
2535
#[cfg(debug_assertions)]
2536
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2536
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2537
2537
#[cfg(debug_assertions)]
2538
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2538
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2539
2539
2540
2540
last_sent_closing_fee: None,
2541
2541
last_received_closing_sig: None,
@@ -2591,9 +2591,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2591
2591
announcement_sigs: None,
2592
2592
2593
2593
#[cfg(any(test, fuzzing))]
2594
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2594
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2595
2595
#[cfg(any(test, fuzzing))]
2596
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2596
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2597
2597
2598
2598
workaround_lnd_bug_4006: None,
2599
2599
sent_message_awaiting_response: None,
@@ -4296,11 +4296,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4296
4296
self.get_initial_counterparty_commitment_signature(logger)
4297
4297
}
4298
4298
4299
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4300
- /// a few non-cloneable fields (such as Secp256k1 context)
4299
+ /// Clone, each field, with the exception of the channel signer.
4301
4300
#[allow(unused)]
4302
4301
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4303
4302
Self {
4303
+ // Use provided channel signer
4304
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4305
+
4304
4306
config: self.config,
4305
4307
prev_config: self.prev_config,
4306
4308
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4309,12 +4311,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4309
4311
temporary_channel_id: self.temporary_channel_id,
4310
4312
channel_state: self.channel_state,
4311
4313
announcement_sigs_state: self.announcement_sigs_state.clone(),
4312
- // Create new Secp256k context
4313
- secp_ctx: Secp256k1::new(),
4314
+ secp_ctx: self.secp_ctx.clone(),
4314
4315
channel_value_satoshis: self.channel_value_satoshis,
4315
4316
latest_monitor_update_id: self.latest_monitor_update_id,
4316
- // Use provided channel signer
4317
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4318
4317
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4319
4318
destination_script: self.destination_script.clone(),
4320
4319
holder_commitment_point: self.holder_commitment_point,
@@ -4344,9 +4343,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4344
4343
update_time_counter: self.update_time_counter,
4345
4344
// Create new mutex with copied values
4346
4345
#[cfg(debug_assertions)]
4347
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4346
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4348
4347
#[cfg(debug_assertions)]
4349
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4348
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4350
4349
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4351
4350
last_received_closing_sig: self.last_received_closing_sig,
4352
4351
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4383,9 +4382,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4383
4382
announcement_sigs: self.announcement_sigs,
4384
4383
// Create new mutex with copied values
4385
4384
#[cfg(any(test, fuzzing))]
4386
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4385
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4387
4386
#[cfg(any(test, fuzzing))]
4388
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4387
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4389
4388
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4390
4389
sent_message_awaiting_response: self.sent_message_awaiting_response,
4391
4390
#[cfg(any(test, fuzzing))]
@@ -10578,9 +10577,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10578
10577
feerate_per_kw,
10579
10578
10580
10579
#[cfg(debug_assertions)]
10581
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10580
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10582
10581
#[cfg(debug_assertions)]
10583
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10582
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10584
10583
10585
10584
last_sent_closing_fee: None,
10586
10585
last_received_closing_sig: None,
@@ -10625,9 +10624,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10625
10624
announcement_sigs,
10626
10625
10627
10626
#[cfg(any(test, fuzzing))]
10628
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10627
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10629
10628
#[cfg(any(test, fuzzing))]
10630
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10629
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10631
10630
10632
10631
workaround_lnd_bug_4006: None,
10633
10632
sent_message_awaiting_response: None,
0 commit comments