Skip to content

Commit 65a1cfa

Browse files
committed
f Avoid back-to-back locking
1 parent b7462fd commit 65a1cfa

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,20 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
12061206
self.inner.lock().unwrap().broadcast_latest_holder_commitment_txn(broadcaster, logger);
12071207
}
12081208

1209+
pub(crate) fn broadcast_latest_holder_commitment_txn_if_unspent<B: Deref, L: Deref>(
1210+
&self,
1211+
broadcaster: &B,
1212+
logger: &L,
1213+
) where
1214+
B::Target: BroadcasterInterface,
1215+
L::Target: Logger,
1216+
{
1217+
let mut locked_inner = self.inner.lock().unwrap();
1218+
if !locked_inner.detected_funding_spend() {
1219+
locked_inner.broadcast_latest_holder_commitment_txn(broadcaster, logger);
1220+
}
1221+
}
1222+
12091223
/// Updates a ChannelMonitor on the basis of some new information provided by the Channel
12101224
/// itself.
12111225
///
@@ -1236,11 +1250,6 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
12361250
self.inner.lock().unwrap().get_funding_txo().clone()
12371251
}
12381252

1239-
/// Gets whether we've seen a confirmed transaction spending the funding output.
1240-
pub(crate) fn detected_funding_spend(&self) -> bool {
1241-
self.inner.lock().unwrap().detected_funding_spend()
1242-
}
1243-
12441253
/// Gets a list of txids, with their output scripts (in the order they appear in the
12451254
/// transaction), which we must learn about spends of via block_connected().
12461255
pub fn get_outputs_to_watch(&self) -> Vec<(Txid, Vec<(u32, Script)>)> {

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7208,12 +7208,12 @@ where
72087208
}
72097209

72107210
for (funding_txo, monitor) in args.channel_monitors.iter_mut() {
7211-
// There's no need to broadcast our commitment transaction if we've seen one
7212-
// confirmed (even with 1 confirmation) as it'll be rejected as
7213-
// duplicate/conflicting.
7214-
if !funding_txo_set.contains(funding_txo) && !monitor.detected_funding_spend() {
7211+
if !funding_txo_set.contains(funding_txo) {
72157212
log_info!(args.logger, "Broadcasting latest holder commitment transaction for closed channel {}", log_bytes!(funding_txo.to_channel_id()));
7216-
monitor.broadcast_latest_holder_commitment_txn(&args.tx_broadcaster, &args.logger);
7213+
// There's no need to broadcast our commitment transaction if
7214+
// we've seen one confirmed (even with 1 confirmation) as it'll
7215+
// be rejected as duplicate/conflicting.
7216+
monitor.broadcast_latest_holder_commitment_txn_if_unspent(&args.tx_broadcaster, &args.logger);
72177217
}
72187218
}
72197219

0 commit comments

Comments
 (0)