Skip to content

Commit 7456483

Browse files
committed
Emit DiscardFunding event when no splice transaction confirms
When adding support for emitting these events in the channel monitor, we only covered the case where one of the splice transaction candidates confirmed. We also need to emit an event when none of them can confirm due to a commitment transaction confirming (and no longer under reorg risk) for the pre-splice funding.
1 parent 7d0760b commit 7456483

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5591,6 +5591,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
55915591
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
55925592
self.funding_spend_confirmed = Some(entry.txid);
55935593
self.confirmed_commitment_tx_counterparty_output = commitment_tx_to_counterparty_output;
5594+
if self.alternative_funding_confirmed.is_none() && !self.pending_funding.is_empty() {
5595+
for funding in self.pending_funding.drain(..) {
5596+
self.outputs_to_watch.remove(&funding.funding_txid());
5597+
self.pending_events.push(Event::DiscardFunding {
5598+
channel_id: self.channel_id,
5599+
funding_info: crate::events::FundingInfo::OutPoint {
5600+
outpoint: funding.funding_outpoint(),
5601+
},
5602+
});
5603+
}
5604+
}
55945605
},
55955606
OnchainEvent::AlternativeFundingConfirmation {} => {
55965607
// An alternative funding transaction has irrevocably confirmed and we're no

lightning/src/ln/splicing_tests.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;
1111
use crate::chain::channelmonitor::{ANTI_REORG_DELAY, LATENCY_GRACE_PERIOD_BLOCKS};
12+
use crate::chain::transaction::OutPoint;
1213
use crate::events::bump_transaction::sync::WalletSourceSync;
13-
use crate::events::{ClosureReason, Event, HTLCHandlingFailureType};
14+
use crate::events::{ClosureReason, Event, FundingInfo, HTLCHandlingFailureType};
1415
use crate::ln::chan_utils;
16+
use crate::ln::channelmanager::BREAKDOWN_TIMEOUT;
1517
use crate::ln::functional_test_utils::*;
1618
use crate::ln::funding::{FundingTxInput, SpliceContribution};
1719
use crate::ln::msgs::{self, BaseMessageHandler, ChannelMessageHandler, MessageSendEvent};
@@ -305,7 +307,8 @@ fn lock_splice_after_blocks<'a, 'b, 'c, 'd>(
305307
panic!();
306308
}
307309

308-
// Remove the corresponding outputs and transactions the chain source is watching.
310+
// Remove the corresponding outputs and transactions the chain source is watching for the
311+
// old funding as it is no longer being tracked.
309312
node_a
310313
.chain_source
311314
.remove_watched_txn_and_outputs(prev_funding_outpoint, prev_funding_script.clone());
@@ -559,4 +562,42 @@ fn do_test_splice_commitment_broadcast(splice_status: SpliceStatus, claim_htlcs:
559562
2
560563
);
561564
}
565+
566+
// When the splice never confirms and we see a commitment transaction broadcast and confirm for
567+
// the current funding instead, we should expect to see an `Event::DiscardFunding` for the
568+
// splice transaction.
569+
if splice_status == SpliceStatus::Unconfirmed {
570+
// Remove the corresponding outputs and transactions the chain source is watching for the
571+
// splice as it is no longer being tracked.
572+
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32);
573+
let (vout, txout) = splice_tx
574+
.output
575+
.iter()
576+
.enumerate()
577+
.find(|(_, output)| output.script_pubkey.is_p2wsh())
578+
.unwrap();
579+
let funding_outpoint = OutPoint { txid: splice_tx.compute_txid(), index: vout as u16 };
580+
nodes[0]
581+
.chain_source
582+
.remove_watched_txn_and_outputs(funding_outpoint, txout.script_pubkey.clone());
583+
nodes[1]
584+
.chain_source
585+
.remove_watched_txn_and_outputs(funding_outpoint, txout.script_pubkey.clone());
586+
587+
// `SpendableOutputs` events are also included here, but we don't care for them.
588+
let events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
589+
assert_eq!(events.len(), if claim_htlcs { 2 } else { 4 }, "{events:?}");
590+
if let Event::DiscardFunding { funding_info, .. } = &events[0] {
591+
assert_eq!(*funding_info, FundingInfo::OutPoint { outpoint: funding_outpoint });
592+
} else {
593+
panic!();
594+
}
595+
let events = nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events();
596+
assert_eq!(events.len(), if claim_htlcs { 2 } else { 1 }, "{events:?}");
597+
if let Event::DiscardFunding { funding_info, .. } = &events[0] {
598+
assert_eq!(*funding_info, FundingInfo::OutPoint { outpoint: funding_outpoint });
599+
} else {
600+
panic!();
601+
}
602+
}
562603
}

0 commit comments

Comments
 (0)