@@ -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};
@@ -1319,10 +1319,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1319
1319
1320
1320
#[cfg(debug_assertions)]
1321
1321
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1322
- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1322
+ holder_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1323
1323
#[cfg(debug_assertions)]
1324
1324
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1325
- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1325
+ counterparty_max_commitment_tx_output: Arc< Mutex<(u64, u64)> >,
1326
1326
1327
1327
// (fee_sats, skip_remote_output, fee_range, holder_sig)
1328
1328
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
@@ -1434,9 +1434,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1434
1434
// be, by comparing the cached values to the fee of the tranaction generated by
1435
1435
// `build_commitment_transaction`.
1436
1436
#[cfg(any(test, fuzzing))]
1437
- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1437
+ next_local_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1438
1438
#[cfg(any(test, fuzzing))]
1439
- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1439
+ next_remote_commitment_tx_fee_info_cached: Arc< Mutex<Option<CommitmentTxInfoCached> >>,
1440
1440
1441
1441
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
1442
1442
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
@@ -2143,9 +2143,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2143
2143
2144
2144
2145
2145
#[cfg(debug_assertions)]
2146
- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2146
+ 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) ))),
2147
2147
#[cfg(debug_assertions)]
2148
- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2148
+ 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) ))),
2149
2149
2150
2150
last_sent_closing_fee: None,
2151
2151
last_received_closing_sig: None,
@@ -2203,9 +2203,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2203
2203
announcement_sigs: None,
2204
2204
2205
2205
#[cfg(any(test, fuzzing))]
2206
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2206
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2207
2207
#[cfg(any(test, fuzzing))]
2208
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2208
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2209
2209
2210
2210
workaround_lnd_bug_4006: None,
2211
2211
sent_message_awaiting_response: None,
@@ -2378,9 +2378,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2378
2378
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2379
2379
// when we receive `accept_channel2`.
2380
2380
#[cfg(debug_assertions)]
2381
- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2381
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2382
2382
#[cfg(debug_assertions)]
2383
- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2383
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat) )),
2384
2384
2385
2385
last_sent_closing_fee: None,
2386
2386
last_received_closing_sig: None,
@@ -2436,9 +2436,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2436
2436
announcement_sigs: None,
2437
2437
2438
2438
#[cfg(any(test, fuzzing))]
2439
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2439
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2440
2440
#[cfg(any(test, fuzzing))]
2441
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2441
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
2442
2442
2443
2443
workaround_lnd_bug_4006: None,
2444
2444
sent_message_awaiting_response: None,
@@ -4105,11 +4105,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4105
4105
self.get_initial_counterparty_commitment_signature(logger)
4106
4106
}
4107
4107
4108
- /// Clone, each field, with a few exceptions, notably the channel signer, and
4109
- /// a few non-cloneable fields (such as Secp256k1 context)
4108
+ /// Clone, each field, with the exception of the channel signer.
4110
4109
#[allow(unused)]
4111
4110
fn clone(&self, holder_signer: <SP::Target as SignerProvider>::EcdsaSigner) -> Self {
4112
4111
Self {
4112
+ // Use provided channel signer
4113
+ holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4114
+
4113
4115
config: self.config,
4114
4116
prev_config: self.prev_config,
4115
4117
inbound_handshake_limits_override: self.inbound_handshake_limits_override,
@@ -4118,12 +4120,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4118
4120
temporary_channel_id: self.temporary_channel_id,
4119
4121
channel_state: self.channel_state,
4120
4122
announcement_sigs_state: self.announcement_sigs_state.clone(),
4121
- // Create new Secp256k context
4122
- secp_ctx: Secp256k1::new(),
4123
+ secp_ctx: self.secp_ctx.clone(),
4123
4124
channel_value_satoshis: self.channel_value_satoshis,
4124
4125
latest_monitor_update_id: self.latest_monitor_update_id,
4125
- // Use provided channel signer
4126
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
4127
4126
shutdown_scriptpubkey: self.shutdown_scriptpubkey.clone(),
4128
4127
destination_script: self.destination_script.clone(),
4129
4128
cur_counterparty_commitment_transaction_number: self.cur_counterparty_commitment_transaction_number,
@@ -4153,9 +4152,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4153
4152
update_time_counter: self.update_time_counter,
4154
4153
// Create new mutex with copied values
4155
4154
#[cfg(debug_assertions)]
4156
- holder_max_commitment_tx_output: Mutex::new(* self.holder_max_commitment_tx_output.lock().unwrap() ),
4155
+ holder_max_commitment_tx_output: self.holder_max_commitment_tx_output.clone( ),
4157
4156
#[cfg(debug_assertions)]
4158
- counterparty_max_commitment_tx_output: Mutex::new(* self.counterparty_max_commitment_tx_output.lock().unwrap() ),
4157
+ counterparty_max_commitment_tx_output: self.counterparty_max_commitment_tx_output.clone( ),
4159
4158
last_sent_closing_fee: self.last_sent_closing_fee.clone(),
4160
4159
last_received_closing_sig: self.last_received_closing_sig,
4161
4160
target_closing_feerate_sats_per_kw: self.target_closing_feerate_sats_per_kw,
@@ -4192,9 +4191,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4192
4191
announcement_sigs: self.announcement_sigs,
4193
4192
// Create new mutex with copied values
4194
4193
#[cfg(any(test, fuzzing))]
4195
- next_local_commitment_tx_fee_info_cached: Mutex::new( self.next_local_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4194
+ next_local_commitment_tx_fee_info_cached: self.next_local_commitment_tx_fee_info_cached.clone(),
4196
4195
#[cfg(any(test, fuzzing))]
4197
- next_remote_commitment_tx_fee_info_cached: Mutex::new( self.next_remote_commitment_tx_fee_info_cached.lock().unwrap(). clone() ),
4196
+ next_remote_commitment_tx_fee_info_cached: self.next_remote_commitment_tx_fee_info_cached.clone(),
4198
4197
workaround_lnd_bug_4006: self.workaround_lnd_bug_4006.clone(),
4199
4198
sent_message_awaiting_response: self.sent_message_awaiting_response,
4200
4199
#[cfg(any(test, fuzzing))]
@@ -10283,9 +10282,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10283
10282
feerate_per_kw,
10284
10283
10285
10284
#[cfg(debug_assertions)]
10286
- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10285
+ holder_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10287
10286
#[cfg(debug_assertions)]
10288
- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10287
+ counterparty_max_commitment_tx_output: Arc::new( Mutex::new((0, 0) )),
10289
10288
10290
10289
last_sent_closing_fee: None,
10291
10290
last_received_closing_sig: None,
@@ -10330,9 +10329,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10330
10329
announcement_sigs,
10331
10330
10332
10331
#[cfg(any(test, fuzzing))]
10333
- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
10332
+ next_local_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10334
10333
#[cfg(any(test, fuzzing))]
10335
- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
10334
+ next_remote_commitment_tx_fee_info_cached: Arc::new( Mutex::new(None) ),
10336
10335
10337
10336
workaround_lnd_bug_4006: None,
10338
10337
sent_message_awaiting_response: None,
0 commit comments