@@ -69,7 +69,7 @@ use crate::prelude::*;
6969use core::{cmp,mem,fmt};
7070use core::ops::Deref;
7171#[cfg(any(test, fuzzing, debug_assertions))]
72- use crate::sync::Mutex;
72+ use crate::sync::{Arc, Mutex} ;
7373use crate::sign::type_resolver::ChannelSignerType;
7474
7575use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
@@ -1312,10 +1312,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
13121312
13131313 #[cfg(debug_assertions)]
13141314 /// Max to_local and to_remote outputs in a locally-generated commitment transaction
1315- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1315+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
13161316 #[cfg(debug_assertions)]
13171317 /// Max to_local and to_remote outputs in a remote-generated commitment transaction
1318- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1318+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
13191319
13201320 // (fee_sats, skip_remote_output, fee_range, holder_sig)
13211321 last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1427,9 +1427,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14271427 // be, by comparing the cached values to the fee of the tranaction generated by
14281428 // `build_commitment_transaction`.
14291429 #[cfg(any(test, fuzzing))]
1430- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1430+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
14311431 #[cfg(any(test, fuzzing))]
1432- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1432+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
14331433
14341434 /// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
14351435 /// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2127,9 +2127,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21272127
21282128
21292129 #[cfg(debug_assertions)]
2130- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2130+ 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) ))),
21312131 #[cfg(debug_assertions)]
2132- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2132+ 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) ))),
21332133
21342134 last_sent_closing_fee: None,
21352135 last_received_closing_sig: None,
@@ -2187,9 +2187,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21872187 announcement_sigs: None,
21882188
21892189 #[cfg(any(test, fuzzing))]
2190- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2190+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
21912191 #[cfg(any(test, fuzzing))]
2192- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2192+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
21932193
21942194 workaround_lnd_bug_4006: None,
21952195 sent_message_awaiting_response: None,
@@ -2365,9 +2365,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23652365 // We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
23662366 // when we receive `accept_channel2`.
23672367 #[cfg(debug_assertions)]
2368- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2368+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
23692369 #[cfg(debug_assertions)]
2370- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2370+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
23712371
23722372 last_sent_closing_fee: None,
23732373 last_received_closing_sig: None,
@@ -2423,9 +2423,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
24232423 announcement_sigs: None,
24242424
24252425 #[cfg(any(test, fuzzing))]
2426- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2426+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
24272427 #[cfg(any(test, fuzzing))]
2428- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2428+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
24292429
24302430 workaround_lnd_bug_4006: None,
24312431 sent_message_awaiting_response: None,
@@ -4093,11 +4093,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40934093 self.get_initial_counterparty_commitment_signature(logger)
40944094 }
40954095
4096- /// Clone, each field, with a few exceptions, notably the channel signer, and
4097- /// a few non-cloneable fields (such as Secp256k1 context)
4096+ /// Clone, each field, with the exception of the channel signer.
40984097 #[allow(unused)]
40994098 fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
41004099 Self {
4100+ // Use provided channel signer
4101+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4102+
41014103 config: self.config,
41024104 prev_config: self.prev_config,
41034105 inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4106,12 +4108,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
41064108 temporary_channel_id: self.temporary_channel_id,
41074109 channel_state: self.channel_state,
41084110 announcement_sigs_state: self.announcement_sigs_state.clone(),
4109- // Create new Secp256k context
4110- secp_ctx: Secp256k1::new(),
4111+ secp_ctx: self.secp_ctx.clone(),
41114112 channel_value_satoshis: self.channel_value_satoshis,
41124113 latest_monitor_update_id: self.latest_monitor_update_id,
4113- // Use provided channel signer
4114- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
41154114 shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
41164115 destination_script: self.destination_script.clone(),
41174116 holder_commitment_point: self.holder_commitment_point,
@@ -4141,9 +4140,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
41414140 update_time_counter: self.update_time_counter,
41424141 // Create new mutex with copied values
41434142 #[cfg(debug_assertions)]
4144- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4143+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
41454144 #[cfg(debug_assertions)]
4146- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4145+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
41474146 last_sent_closing_fee: self.last_sent_closing_fee.clone(),
41484147 last_received_closing_sig: self.last_received_closing_sig,
41494148 target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4180,9 +4179,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
41804179 announcement_sigs: self.announcement_sigs,
41814180 // Create new mutex with copied values
41824181 #[cfg(any(test, fuzzing))]
4183- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4182+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
41844183 #[cfg(any(test, fuzzing))]
4185- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4184+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
41864185 workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
41874186 sent_message_awaiting_response: self.sent_message_awaiting_response,
41884187 #[cfg(any(test, fuzzing))]
@@ -10162,9 +10161,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1016210161 feerate_per_kw,
1016310162
1016410163 #[cfg(debug_assertions)]
10165- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10164+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
1016610165 #[cfg(debug_assertions)]
10167- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10166+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
1016810167
1016910168 last_sent_closing_fee: None,
1017010169 last_received_closing_sig: None,
@@ -10209,9 +10208,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1020910208 announcement_sigs,
1021010209
1021110210 #[cfg(any(test, fuzzing))]
10212- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10211+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
1021310212 #[cfg(any(test, fuzzing))]
10214- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10213+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
1021510214
1021610215 workaround_lnd_bug_4006: None,
1021710216 sent_message_awaiting_response: None,
0 commit comments