Skip to content

Commit aa912ce

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 022d3a0 commit aa912ce

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
@@ -5571,6 +5571,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
55715571
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
55725572
self.funding_spend_confirmed = Some(entry.txid);
55735573
self.confirmed_commitment_tx_counterparty_output = commitment_tx_to_counterparty_output;
5574+
if self.alternative_funding_confirmed.is_none() {
5575+
for funding in self.pending_funding.drain(..) {
5576+
self.outputs_to_watch.remove(&funding.funding_txid());
5577+
self.pending_events.push(Event::DiscardFunding {
5578+
channel_id: self.channel_id,
5579+
funding_info: crate::events::FundingInfo::OutPoint {
5580+
outpoint: funding.funding_outpoint(),
5581+
},
5582+
});
5583+
}
5584+
}
55745585
},
55755586
OnchainEvent::AlternativeFundingConfirmation {} => {
55765587
// 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());
@@ -560,4 +563,42 @@ fn do_test_splice_commitment_broadcast(splice_status: SpliceStatus, claim_htlcs:
560563
);
561564
}
562565
check_added_monitors(&nodes[0], 2); // Two `ReleasePaymentComplete` monitor updates
566+
567+
// When the splice never confirms and we see a commitment transaction broadcast and confirm for
568+
// the current funding instead, we should expect to see an `Event::DiscardFunding` for the
569+
// splice transaction.
570+
if splice_status == SpliceStatus::Unconfirmed {
571+
// Remove the corresponding outputs and transactions the chain source is watching for the
572+
// splice as it is no longer being tracked.
573+
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32);
574+
let (vout, txout) = splice_tx
575+
.output
576+
.iter()
577+
.enumerate()
578+
.find(|(_, output)| output.script_pubkey.is_p2wsh())
579+
.unwrap();
580+
let funding_outpoint = OutPoint { txid: splice_tx.compute_txid(), index: vout as u16 };
581+
nodes[0]
582+
.chain_source
583+
.remove_watched_txn_and_outputs(funding_outpoint, txout.script_pubkey.clone());
584+
nodes[1]
585+
.chain_source
586+
.remove_watched_txn_and_outputs(funding_outpoint, txout.script_pubkey.clone());
587+
588+
// `SpendableOutputs` events are also included here, but we don't care for them.
589+
let events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
590+
assert_eq!(events.len(), if claim_htlcs { 2 } else { 4 }, "{events:?}");
591+
if let Event::DiscardFunding { funding_info, .. } = &events[0] {
592+
assert_eq!(*funding_info, FundingInfo::OutPoint { outpoint: funding_outpoint });
593+
} else {
594+
panic!();
595+
}
596+
let events = nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events();
597+
assert_eq!(events.len(), if claim_htlcs { 2 } else { 1 }, "{events:?}");
598+
if let Event::DiscardFunding { funding_info, .. } = &events[0] {
599+
assert_eq!(*funding_info, FundingInfo::OutPoint { outpoint: funding_outpoint });
600+
} else {
601+
panic!();
602+
}
603+
}
563604
}

0 commit comments

Comments
 (0)