@@ -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};
@@ -1718,10 +1718,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1718
1718
1719
1719
#[cfg(debug_assertions)]
1720
1720
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1721
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1721
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1722
1722
#[cfg(debug_assertions)]
1723
1723
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1724
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1724
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1725
1725
1726
1726
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1727
1727
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1833,9 +1833,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1833
1833
// be, by comparing the cached values to the fee of the tranaction generated by
1834
1834
// `build_commitment_transaction`.
1835
1835
#[cfg(any(test, fuzzing))]
1836
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1836
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1837
1837
#[cfg(any(test, fuzzing))]
1838
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1838
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1839
1839
1840
1840
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1841
1841
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2658,9 +2658,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2658
2658
2659
2659
2660
2660
#[cfg(debug_assertions)]
2661
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2661
+ 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) ))),
2662
2662
#[cfg(debug_assertions)]
2663
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2663
+ 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) ))),
2664
2664
2665
2665
last_sent_closing_fee: None,
2666
2666
last_received_closing_sig: None,
@@ -2718,9 +2718,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2718
2718
announcement_sigs: None,
2719
2719
2720
2720
#[cfg(any(test, fuzzing))]
2721
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2721
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2722
2722
#[cfg(any(test, fuzzing))]
2723
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2723
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2724
2724
2725
2725
workaround_lnd_bug_4006: None,
2726
2726
sent_message_awaiting_response: None,
@@ -2890,9 +2890,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2890
2890
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2891
2891
// when we receive `accept_channel2`.
2892
2892
#[cfg(debug_assertions)]
2893
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2893
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2894
2894
#[cfg(debug_assertions)]
2895
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2895
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2896
2896
2897
2897
last_sent_closing_fee: None,
2898
2898
last_received_closing_sig: None,
@@ -2948,9 +2948,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2948
2948
announcement_sigs: None,
2949
2949
2950
2950
#[cfg(any(test, fuzzing))]
2951
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2951
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2952
2952
#[cfg(any(test, fuzzing))]
2953
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2953
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2954
2954
2955
2955
workaround_lnd_bug_4006: None,
2956
2956
sent_message_awaiting_response: None,
@@ -4645,11 +4645,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4645
4645
self.get_initial_counterparty_commitment_signature(logger)
4646
4646
}
4647
4647
4648
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4649
- /// a few non-cloneable fields (such as Secp256k1 context)
4648
+ /// Clone, each field, with the exception of the channel signer.
4650
4649
#[allow(unused)]
4651
4650
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4652
4651
Self {
4652
+ // Use provided channel signer
4653
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4654
+
4653
4655
config: self.config,
4654
4656
prev_config: self.prev_config,
4655
4657
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4658,12 +4660,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4658
4660
temporary_channel_id: self.temporary_channel_id,
4659
4661
channel_state: self.channel_state,
4660
4662
announcement_sigs_state: self.announcement_sigs_state.clone(),
4661
- // Create new Secp256k context
4662
- secp_ctx: Secp256k1::new(),
4663
+ secp_ctx: self.secp_ctx.clone(),
4663
4664
channel_value_satoshis: self.channel_value_satoshis,
4664
4665
latest_monitor_update_id: self.latest_monitor_update_id,
4665
- // Use provided channel signer
4666
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4667
4666
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4668
4667
destination_script: self.destination_script.clone(),
4669
4668
// holder_commitment_point: self.holder_commitment_point,
@@ -4694,9 +4693,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4694
4693
update_time_counter: self.update_time_counter,
4695
4694
// Create new mutex with copied values
4696
4695
#[cfg(debug_assertions)]
4697
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4696
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4698
4697
#[cfg(debug_assertions)]
4699
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4698
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4700
4699
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4701
4700
last_received_closing_sig: self.last_received_closing_sig,
4702
4701
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4733,9 +4732,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4733
4732
announcement_sigs: self.announcement_sigs,
4734
4733
// Create new mutex with copied values
4735
4734
#[cfg(any(test, fuzzing))]
4736
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4735
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4737
4736
#[cfg(any(test, fuzzing))]
4738
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4737
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4739
4738
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4740
4739
sent_message_awaiting_response: self.sent_message_awaiting_response,
4741
4740
#[cfg(any(test, fuzzing))]
@@ -10928,9 +10927,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10928
10927
feerate_per_kw,
10929
10928
10930
10929
#[cfg(debug_assertions)]
10931
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10930
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10932
10931
#[cfg(debug_assertions)]
10933
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10932
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10934
10933
10935
10934
last_sent_closing_fee: None,
10936
10935
last_received_closing_sig: None,
@@ -10975,9 +10974,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10975
10974
announcement_sigs,
10976
10975
10977
10976
#[cfg(any(test, fuzzing))]
10978
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10977
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10979
10978
#[cfg(any(test, fuzzing))]
10980
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10979
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10981
10980
10982
10981
workaround_lnd_bug_4006: None,
10983
10982
sent_message_awaiting_response: None,
0 commit comments