Skip to content

Commit f98ffba

Browse files
Defer claimable tracking until funding tx confirms
For manually-broadcast funding, we can't track claimable outputs until the funding tx is actually onchain. Otherwise we'd try to claim outputs that don't exist yet.
1 parent 038d216 commit f98ffba

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5581,8 +5581,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
55815581
if should_broadcast_commitment {
55825582
let (mut claimables, mut outputs) =
55835583
self.generate_claimable_outpoints_and_watch_outputs(None);
5584-
claimable_outpoints.append(&mut claimables);
5585-
watch_outputs.append(&mut outputs);
5584+
if !self.is_manual_broadcast || self.funding_seen_onchain {
5585+
claimable_outpoints.append(&mut claimables);
5586+
watch_outputs.append(&mut outputs);
5587+
}
55865588
}
55875589

55885590
self.block_confirmed(height, block_hash, txn_matched, watch_outputs, claimable_outpoints, &broadcaster, &fee_estimator, logger)
@@ -5616,13 +5618,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
56165618
log_trace!(logger, "Processing {} matched transactions for block at height {}.", txn_matched.len(), conf_height);
56175619
debug_assert!(self.best_block.height >= conf_height);
56185620

5619-
let should_broadcast = self.should_broadcast_holder_commitment_txn(logger);
5620-
if let Some(payment_hash) = should_broadcast {
5621-
let reason = ClosureReason::HTLCsTimedOut { payment_hash: Some(payment_hash) };
5622-
let (mut new_outpoints, mut new_outputs) =
5623-
self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
5624-
claimable_outpoints.append(&mut new_outpoints);
5625-
watch_outputs.append(&mut new_outputs);
5621+
// Only generate claims if we haven't already done so (e.g., in transactions_confirmed).
5622+
if claimable_outpoints.is_empty() {
5623+
let should_broadcast = self.should_broadcast_holder_commitment_txn(logger);
5624+
if let Some(payment_hash) = should_broadcast {
5625+
let reason = ClosureReason::HTLCsTimedOut { payment_hash: Some(payment_hash) };
5626+
let (mut new_outpoints, mut new_outputs) =
5627+
self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
5628+
if !self.is_manual_broadcast || self.funding_seen_onchain {
5629+
claimable_outpoints.append(&mut new_outpoints);
5630+
watch_outputs.append(&mut new_outputs);
5631+
}
5632+
}
56265633
}
56275634

56285635
// Find which on-chain events have reached their confirmation threshold.

0 commit comments

Comments
 (0)