@@ -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};
@@ -1603,10 +1603,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1603
1603
1604
1604
#[cfg(debug_assertions)]
1605
1605
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1606
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1606
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1607
1607
#[cfg(debug_assertions)]
1608
1608
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1609
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1609
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1610
1610
1611
1611
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1612
1612
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1718,9 +1718,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1718
1718
// be, by comparing the cached values to the fee of the tranaction generated by
1719
1719
// `build_commitment_transaction`.
1720
1720
#[cfg(any(test, fuzzing))]
1721
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1721
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1722
1722
#[cfg(any(test, fuzzing))]
1723
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1723
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1724
1724
1725
1725
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1726
1726
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2530,9 +2530,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2530
2530
2531
2531
2532
2532
#[cfg(debug_assertions)]
2533
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2533
+ 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) ))),
2534
2534
#[cfg(debug_assertions)]
2535
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2535
+ 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) ))),
2536
2536
2537
2537
last_sent_closing_fee: None,
2538
2538
last_received_closing_sig: None,
@@ -2590,9 +2590,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2590
2590
announcement_sigs: None,
2591
2591
2592
2592
#[cfg(any(test, fuzzing))]
2593
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2593
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2594
2594
#[cfg(any(test, fuzzing))]
2595
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2595
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2596
2596
2597
2597
workaround_lnd_bug_4006: None,
2598
2598
sent_message_awaiting_response: None,
@@ -2765,9 +2765,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2765
2765
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2766
2766
// when we receive `accept_channel2`.
2767
2767
#[cfg(debug_assertions)]
2768
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2768
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2769
2769
#[cfg(debug_assertions)]
2770
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2770
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2771
2771
2772
2772
last_sent_closing_fee: None,
2773
2773
last_received_closing_sig: None,
@@ -2823,9 +2823,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2823
2823
announcement_sigs: None,
2824
2824
2825
2825
#[cfg(any(test, fuzzing))]
2826
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2826
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2827
2827
#[cfg(any(test, fuzzing))]
2828
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2828
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2829
2829
2830
2830
workaround_lnd_bug_4006: None,
2831
2831
sent_message_awaiting_response: None,
@@ -4519,11 +4519,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4519
4519
self.get_initial_counterparty_commitment_signature(logger)
4520
4520
}
4521
4521
4522
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4523
- /// a few non-cloneable fields (such as Secp256k1 context)
4522
+ /// Clone, each field, with the exception of the channel signer.
4524
4523
#[allow(unused)]
4525
4524
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4526
4525
Self {
4526
+ // Use provided channel signer
4527
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4528
+
4527
4529
config: self.config,
4528
4530
prev_config: self.prev_config,
4529
4531
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4532,12 +4534,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4532
4534
temporary_channel_id: self.temporary_channel_id,
4533
4535
channel_state: self.channel_state,
4534
4536
announcement_sigs_state: self.announcement_sigs_state.clone(),
4535
- // Create new Secp256k context
4536
- secp_ctx: Secp256k1::new(),
4537
+ secp_ctx: self.secp_ctx.clone(),
4537
4538
channel_value_satoshis: self.channel_value_satoshis,
4538
4539
latest_monitor_update_id: self.latest_monitor_update_id,
4539
- // Use provided channel signer
4540
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4541
4540
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4542
4541
destination_script: self.destination_script.clone(),
4543
4542
// holder_commitment_point: self.holder_commitment_point,
@@ -4568,9 +4567,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4568
4567
update_time_counter: self.update_time_counter,
4569
4568
// Create new mutex with copied values
4570
4569
#[cfg(debug_assertions)]
4571
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4570
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4572
4571
#[cfg(debug_assertions)]
4573
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4572
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4574
4573
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4575
4574
last_received_closing_sig: self.last_received_closing_sig,
4576
4575
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4607,9 +4606,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4607
4606
announcement_sigs: self.announcement_sigs,
4608
4607
// Create new mutex with copied values
4609
4608
#[cfg(any(test, fuzzing))]
4610
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4609
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4611
4610
#[cfg(any(test, fuzzing))]
4612
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4611
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4613
4612
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4614
4613
sent_message_awaiting_response: self.sent_message_awaiting_response,
4615
4614
#[cfg(any(test, fuzzing))]
@@ -10896,9 +10895,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10896
10895
feerate_per_kw,
10897
10896
10898
10897
#[cfg(debug_assertions)]
10899
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10898
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10900
10899
#[cfg(debug_assertions)]
10901
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10900
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10902
10901
10903
10902
last_sent_closing_fee: None,
10904
10903
last_received_closing_sig: None,
@@ -10943,9 +10942,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10943
10942
announcement_sigs,
10944
10943
10945
10944
#[cfg(any(test, fuzzing))]
10946
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10945
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10947
10946
#[cfg(any(test, fuzzing))]
10948
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10947
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10949
10948
10950
10949
workaround_lnd_bug_4006: None,
10951
10950
sent_message_awaiting_response: None,
0 commit comments