Skip to content

Commit 4131680

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 6c5ef04 commit 4131680

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,7 +3985,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39853985
}
39863986
claimable_outpoints.append(&mut new_outpoints);
39873987
}
3988-
(claimable_outpoints, watch_outputs)
3988+
// In manual-broadcast mode, if we have not yet observed the funding transaction on-chain,
3989+
// return empty vectors.
3990+
if self.is_manual_broadcast && !self.funding_seen_onchain {
3991+
return (Vec::new(), Vec::new());
3992+
} else {
3993+
(claimable_outpoints, watch_outputs)
3994+
}
39893995
}
39903996

39913997
#[rustfmt::skip]
@@ -5642,13 +5648,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
56425648
log_trace!(logger, "Processing {} matched transactions for block at height {}.", txn_matched.len(), conf_height);
56435649
debug_assert!(self.best_block.height >= conf_height);
56445650

5645-
let should_broadcast = self.should_broadcast_holder_commitment_txn(logger);
5646-
if let Some(payment_hash) = should_broadcast {
5647-
let reason = ClosureReason::HTLCsTimedOut { payment_hash: Some(payment_hash) };
5648-
let (mut new_outpoints, mut new_outputs) =
5649-
self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
5650-
claimable_outpoints.append(&mut new_outpoints);
5651-
watch_outputs.append(&mut new_outputs);
5651+
// Only generate claims if we haven't already done so (e.g., in transactions_confirmed).
5652+
if claimable_outpoints.is_empty() {
5653+
let should_broadcast = self.should_broadcast_holder_commitment_txn(logger);
5654+
if let Some(payment_hash) = should_broadcast {
5655+
let reason = ClosureReason::HTLCsTimedOut { payment_hash: Some(payment_hash) };
5656+
let (mut new_outpoints, mut new_outputs) =
5657+
self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
5658+
claimable_outpoints.append(&mut new_outpoints);
5659+
watch_outputs.append(&mut new_outputs);
5660+
}
56525661
}
56535662

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

0 commit comments

Comments
 (0)