@@ -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};
@@ -1559,10 +1559,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1559
1559
1560
1560
#[cfg(debug_assertions)]
1561
1561
/// 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)> >,
1563
1563
#[cfg(debug_assertions)]
1564
1564
/// 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)> >,
1566
1566
1567
1567
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1568
1568
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1674,9 +1674,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1674
1674
// be, by comparing the cached values to the fee of the tranaction generated by
1675
1675
// `build_commitment_transaction`.
1676
1676
#[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> >>,
1678
1678
#[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> >>,
1680
1680
1681
1681
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1682
1682
/// 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 {
2336
2336
2337
2337
2338
2338
#[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) ))),
2340
2340
#[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) ))),
2342
2342
2343
2343
last_sent_closing_fee: None,
2344
2344
last_received_closing_sig: None,
@@ -2396,9 +2396,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2396
2396
announcement_sigs: None,
2397
2397
2398
2398
#[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) ),
2400
2400
#[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) ),
2402
2402
2403
2403
workaround_lnd_bug_4006: None,
2404
2404
sent_message_awaiting_response: None,
@@ -2571,9 +2571,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2571
2571
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2572
2572
// when we receive `accept_channel2`.
2573
2573
#[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) )),
2575
2575
#[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) )),
2577
2577
2578
2578
last_sent_closing_fee: None,
2579
2579
last_received_closing_sig: None,
@@ -2629,9 +2629,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2629
2629
announcement_sigs: None,
2630
2630
2631
2631
#[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) ),
2633
2633
#[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) ),
2635
2635
2636
2636
workaround_lnd_bug_4006: None,
2637
2637
sent_message_awaiting_response: None,
@@ -4298,11 +4298,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4298
4298
self.get_initial_counterparty_commitment_signature(logger)
4299
4299
}
4300
4300
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.
4303
4302
#[allow(unused)]
4304
4303
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4305
4304
Self {
4305
+ // Use provided channel signer
4306
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4307
+
4306
4308
config: self.config,
4307
4309
prev_config: self.prev_config,
4308
4310
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4311,12 +4313,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4311
4313
temporary_channel_id: self.temporary_channel_id,
4312
4314
channel_state: self.channel_state,
4313
4315
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(),
4316
4317
channel_value_satoshis: self.channel_value_satoshis,
4317
4318
latest_monitor_update_id: self.latest_monitor_update_id,
4318
- // Use provided channel signer
4319
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4320
4319
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4321
4320
destination_script: self.destination_script.clone(),
4322
4321
cur_counterparty_commitment_transaction_number: self.cur_counterparty_commitment_transaction_number,
@@ -4346,9 +4345,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4346
4345
update_time_counter: self.update_time_counter,
4347
4346
// Create new mutex with copied values
4348
4347
#[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( ),
4350
4349
#[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( ),
4352
4351
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4353
4352
last_received_closing_sig: self.last_received_closing_sig,
4354
4353
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 {
4385
4384
announcement_sigs: self.announcement_sigs,
4386
4385
// Create new mutex with copied values
4387
4386
#[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(),
4389
4388
#[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(),
4391
4390
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4392
4391
sent_message_awaiting_response: self.sent_message_awaiting_response,
4393
4392
#[cfg(any(test, fuzzing))]
@@ -10461,9 +10460,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10461
10460
feerate_per_kw,
10462
10461
10463
10462
#[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) )),
10465
10464
#[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) )),
10467
10466
10468
10467
last_sent_closing_fee: None,
10469
10468
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
10508
10507
announcement_sigs,
10509
10508
10510
10509
#[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) ),
10512
10511
#[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) ),
10514
10513
10515
10514
workaround_lnd_bug_4006: None,
10516
10515
sent_message_awaiting_response: None,
0 commit comments