@@ -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};
@@ -1673,10 +1673,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1673
1673
1674
1674
#[cfg(debug_assertions)]
1675
1675
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1676
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1676
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1677
1677
#[cfg(debug_assertions)]
1678
1678
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1679
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1679
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1680
1680
1681
1681
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1682
1682
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1788,9 +1788,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1788
1788
// be, by comparing the cached values to the fee of the tranaction generated by
1789
1789
// `build_commitment_transaction`.
1790
1790
#[cfg(any(test, fuzzing))]
1791
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1791
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1792
1792
#[cfg(any(test, fuzzing))]
1793
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1793
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1794
1794
1795
1795
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1796
1796
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2461,9 +2461,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2461
2461
2462
2462
2463
2463
#[cfg(debug_assertions)]
2464
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2464
+ 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) ))),
2465
2465
#[cfg(debug_assertions)]
2466
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2466
+ 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) ))),
2467
2467
2468
2468
last_sent_closing_fee: None,
2469
2469
last_received_closing_sig: None,
@@ -2521,9 +2521,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2521
2521
announcement_sigs: None,
2522
2522
2523
2523
#[cfg(any(test, fuzzing))]
2524
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2524
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2525
2525
#[cfg(any(test, fuzzing))]
2526
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2526
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2527
2527
2528
2528
workaround_lnd_bug_4006: None,
2529
2529
sent_message_awaiting_response: None,
@@ -2693,9 +2693,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2693
2693
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2694
2694
// when we receive `accept_channel2`.
2695
2695
#[cfg(debug_assertions)]
2696
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2696
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2697
2697
#[cfg(debug_assertions)]
2698
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2698
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2699
2699
2700
2700
last_sent_closing_fee: None,
2701
2701
last_received_closing_sig: None,
@@ -2751,9 +2751,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2751
2751
announcement_sigs: None,
2752
2752
2753
2753
#[cfg(any(test, fuzzing))]
2754
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2754
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2755
2755
#[cfg(any(test, fuzzing))]
2756
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2756
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2757
2757
2758
2758
workaround_lnd_bug_4006: None,
2759
2759
sent_message_awaiting_response: None,
@@ -4421,11 +4421,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4421
4421
self.get_initial_counterparty_commitment_signature(logger)
4422
4422
}
4423
4423
4424
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4425
- /// a few non-cloneable fields (such as Secp256k1 context)
4424
+ /// Clone, each field, with the exception of the channel signer.
4426
4425
#[allow(unused)]
4427
4426
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4428
4427
Self {
4428
+ // Use provided channel signer
4429
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4430
+
4429
4431
config: self.config,
4430
4432
prev_config: self.prev_config,
4431
4433
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4434,12 +4436,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4434
4436
temporary_channel_id: self.temporary_channel_id,
4435
4437
channel_state: self.channel_state,
4436
4438
announcement_sigs_state: self.announcement_sigs_state.clone(),
4437
- // Create new Secp256k context
4438
- secp_ctx: Secp256k1::new(),
4439
+ secp_ctx: self.secp_ctx.clone(),
4439
4440
channel_value_satoshis: self.channel_value_satoshis,
4440
4441
latest_monitor_update_id: self.latest_monitor_update_id,
4441
- // Use provided channel signer
4442
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4443
4442
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4444
4443
destination_script: self.destination_script.clone(),
4445
4444
cur_counterparty_commitment_transaction_number: self.cur_counterparty_commitment_transaction_number,
@@ -4469,9 +4468,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4469
4468
update_time_counter: self.update_time_counter,
4470
4469
// Create new mutex with copied values
4471
4470
#[cfg(debug_assertions)]
4472
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4471
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4473
4472
#[cfg(debug_assertions)]
4474
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4473
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4475
4474
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4476
4475
last_received_closing_sig: self.last_received_closing_sig,
4477
4476
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4508,9 +4507,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4508
4507
announcement_sigs: self.announcement_sigs,
4509
4508
// Create new mutex with copied values
4510
4509
#[cfg(any(test, fuzzing))]
4511
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4510
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4512
4511
#[cfg(any(test, fuzzing))]
4513
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4512
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4514
4513
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4515
4514
sent_message_awaiting_response: self.sent_message_awaiting_response,
4516
4515
channel_type: self.channel_type.clone(),
@@ -10490,9 +10489,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10490
10489
feerate_per_kw,
10491
10490
10492
10491
#[cfg(debug_assertions)]
10493
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10492
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10494
10493
#[cfg(debug_assertions)]
10495
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10494
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10496
10495
10497
10496
last_sent_closing_fee: None,
10498
10497
last_received_closing_sig: None,
@@ -10537,9 +10536,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10537
10536
announcement_sigs,
10538
10537
10539
10538
#[cfg(any(test, fuzzing))]
10540
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10539
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10541
10540
#[cfg(any(test, fuzzing))]
10542
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10541
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10543
10542
10544
10543
workaround_lnd_bug_4006: None,
10545
10544
sent_message_awaiting_response: None,
0 commit comments