@@ -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};
@@ -1559,10 +1559,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
15591559
15601560 #[cfg(debug_assertions)]
15611561 /// Max to_local and to_remote outputs in a locally-generated commitment transaction
1562- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1562+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
15631563 #[cfg(debug_assertions)]
15641564 /// Max to_local and to_remote outputs in a remote-generated commitment transaction
1565- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1565+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
15661566
15671567 // (fee_sats, skip_remote_output, fee_range, holder_sig)
15681568 last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1674,9 +1674,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
16741674 // be, by comparing the cached values to the fee of the tranaction generated by
16751675 // `build_commitment_transaction`.
16761676 #[cfg(any(test, fuzzing))]
1677- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1677+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
16781678 #[cfg(any(test, fuzzing))]
1679- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1679+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
16801680
16811681 /// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
16821682 /// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2336,9 +2336,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23362336
23372337
23382338 #[cfg(debug_assertions)]
2339- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2339+ 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) ))),
23402340 #[cfg(debug_assertions)]
2341- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2341+ 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) ))),
23422342
23432343 last_sent_closing_fee: None,
23442344 last_received_closing_sig: None,
@@ -2396,9 +2396,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23962396 announcement_sigs: None,
23972397
23982398 #[cfg(any(test, fuzzing))]
2399- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2399+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
24002400 #[cfg(any(test, fuzzing))]
2401- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2401+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
24022402
24032403 workaround_lnd_bug_4006: None,
24042404 sent_message_awaiting_response: None,
@@ -2571,9 +2571,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
25712571 // We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
25722572 // when we receive `accept_channel2`.
25732573 #[cfg(debug_assertions)]
2574- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2574+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
25752575 #[cfg(debug_assertions)]
2576- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2576+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
25772577
25782578 last_sent_closing_fee: None,
25792579 last_received_closing_sig: None,
@@ -2629,9 +2629,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
26292629 announcement_sigs: None,
26302630
26312631 #[cfg(any(test, fuzzing))]
2632- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2632+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
26332633 #[cfg(any(test, fuzzing))]
2634- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2634+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
26352635
26362636 workaround_lnd_bug_4006: None,
26372637 sent_message_awaiting_response: None,
@@ -4298,11 +4298,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
42984298 self.get_initial_counterparty_commitment_signature(logger)
42994299 }
43004300
4301- /// Clone, each field, with a few exceptions, notably the channel signer, and
4302- /// a few non-cloneable fields (such as Secp256k1 context)
4301+ /// Clone, each field, with the exception of the channel signer.
43034302 #[allow(unused)]
43044303 fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
43054304 Self {
4305+ // Use provided channel signer
4306+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4307+
43064308 config: self.config,
43074309 prev_config: self.prev_config,
43084310 inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4311,12 +4313,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43114313 temporary_channel_id: self.temporary_channel_id,
43124314 channel_state: self.channel_state,
43134315 announcement_sigs_state: self.announcement_sigs_state.clone(),
4314- // Create new Secp256k context
4315- secp_ctx: Secp256k1::new(),
4316+ secp_ctx: self.secp_ctx.clone(),
43164317 channel_value_satoshis: self.channel_value_satoshis,
43174318 latest_monitor_update_id: self.latest_monitor_update_id,
4318- // Use provided channel signer
4319- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
43204319 shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
43214320 destination_script: self.destination_script.clone(),
43224321 cur_counterparty_commitment_transaction_number: self.cur_counterparty_commitment_transaction_number,
@@ -4346,9 +4345,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43464345 update_time_counter: self.update_time_counter,
43474346 // Create new mutex with copied values
43484347 #[cfg(debug_assertions)]
4349- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4348+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
43504349 #[cfg(debug_assertions)]
4351- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4350+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
43524351 last_sent_closing_fee: self.last_sent_closing_fee.clone(),
43534352 last_received_closing_sig: self.last_received_closing_sig,
43544353 target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4385,9 +4384,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43854384 announcement_sigs: self.announcement_sigs,
43864385 // Create new mutex with copied values
43874386 #[cfg(any(test, fuzzing))]
4388- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4387+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
43894388 #[cfg(any(test, fuzzing))]
4390- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4389+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
43914390 workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
43924391 sent_message_awaiting_response: self.sent_message_awaiting_response,
43934392 #[cfg(any(test, fuzzing))]
@@ -10461,9 +10460,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1046110460 feerate_per_kw,
1046210461
1046310462 #[cfg(debug_assertions)]
10464- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10463+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
1046510464 #[cfg(debug_assertions)]
10466- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10465+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
1046710466
1046810467 last_sent_closing_fee: None,
1046910468 last_received_closing_sig: None,
@@ -10508,9 +10507,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1050810507 announcement_sigs,
1050910508
1051010509 #[cfg(any(test, fuzzing))]
10511- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10510+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
1051210511 #[cfg(any(test, fuzzing))]
10513- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10512+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
1051410513
1051510514 workaround_lnd_bug_4006: None,
1051610515 sent_message_awaiting_response: None,
0 commit comments