Abandon claims of irrevocably spent HTLC outputs
What changed, and why it matters
This commit fixes a bug in the Lightning Dev Kit where the wallet could keep trying to claim bitcoin that was already spent by someone else. After a channel closes on-chain, the code normally tries to grab any HTLC outputs it can. A bug caused it to recreate already-impossible claims every time it learned a new payment secret or restarted, because it only avoided duplicate claims for outputs it was still actively tracking. Once an output's spend was buried under enough confirmations, it was dropped from tracking, so the old claim was added again. These impossible claims could never confirm, but they stayed in the monitor forever and were re-broadcast repeatedly. In rare cases they could also trigger a panic if a previously-split claim later saw its output spent again. The fix detects outputs that are already irreversibly spent and tells the on-chain transaction handler to abandon those claims, splitting or dropping them as needed.
Review and merge the patch, then backport to supported release branches. Operators should upgrade nodes that may have persisted stale claims from older versions, as the fix also cleans up already-persisted invalid claims on block connection. No immediate on-chain funds are at risk, but upgrade avoids rebroadcast noise and possible monitor panics.
Security signals we found
Denial-of-service via persistent invalid on-chain claims that bloat the monitor and are rebroadcast forever
Potential panic when a claim split out earlier sees its spent output again because claimable_outpoints still maps to the old claim
State inconsistency after restart because ChannelManager::read replays preimages, recreating abandoned claims
Fix removes impossible HTLC-Timeout broadcasts for outputs already claimed by counterparty with preimage
New defensive cleanup of claimable_outpoints entries for removed claims
Evidence from the diff
ChannelMonitor rebuilds all HTLC-output claims for a confirmed commitment tx whenever it learns a new preimage. It previously deduplicated only against outpoints still in claimable_outpoints. Once an HTLC spend reached ANTI_REORG_DELAY confirmations, the outpoint was removed from tracking, so a later preimage (or a ChannelManager::read replay of stored preimages after restart) would recreate a claim for an already-irrevocably-spent output. The claim could never confirm and was yielded again on every rebroadcast. The patch adds abandon_spent_outpoints in OnchainTxHandler and calls it from ChannelMonitor::block_connected with two sources of irrevocably-spent outputs: htlcs_resolved_on_chain, and HTLCSpendConfirmation events that have reached ANTI_REORG_DELAY. Single-outpoint claims are removed and any split-out claimable_outpoints entries mapping to them are cleaned up; multi-outpoint claims have the spent outpoint split out and their timer reset so the remaining outputs are reclaimed in the same block. It also removes stale HTLC-Timeout claims in locktimed_packages for non-anchor channels where the counterparty already claimed the output with the preimage. Tests cover both anchor and zero-fee commitment variants, upgrade from 0.2, and split-claim behavior.
Changed components
lightning/src/chain/channelmonitor.rslightning/src/chain/onchaintx.rslightning/src/ln/functional_tests.rslightning/src/ln/monitor_tests.rslightning/src/ln/payment_tests.rslightning-tests/src/upgrade_downgrade_tests.rsInspect captured patch +338 / −22
### lightning-tests/src/upgrade_downgrade_tests.rs
@@ -22,8 +22,11 @@ use lightning_0_3::util::ser::Writeable as _;
use lightning_0_2::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW as FEERATE_FLOOR_0_2;
use lightning_0_2::commitment_signed_dance as commitment_signed_dance_0_2;
use lightning_0_2::events::bump_transaction::sync::WalletSourceSync as WalletSourceSync_0_2;
+use lightning_0_2::events::ClosureReason as ClosureReason_0_2;
use lightning_0_2::events::Event as Event_0_2;
+use lightning_0_2::expect_payment_claimed as expect_payment_claimed_0_2;
use lightning_0_2::get_event_msg as get_event_msg_0_2;
+use lightning_0_2::get_local_commitment_txn as get_local_commitment_txn_0_2;
use lightning_0_2::get_monitor as get_monitor_0_2;
use lightning_0_2::ln::channelmanager::PaymentId as PaymentId_0_2;
use lightning_0_2::ln::channelmanager::RecipientOnionFields as RecipientOnionFields_0_2;
@@ -1691,3 +1694,101 @@ fn upgrade_zero_fee_commitments_from_0_2() {
claim_payment(&nodes[0], &[&nodes[1]], preimage);
send_payment(&nodes[0], &[&nodes[1]], 1_000_000);
}
+
+#[test]
+fn upgrade_with_claim_of_spent_htlc_output() {
+ // LDK 0.2 rebuilds the claims of all HTLC outputs on our confirmed commitment transaction when
+ // it learns a preimage, including outputs our counterparty has already irrevocably spent. Test
+ // that such a claim never fires after an upgrade.
+ let (node_a_ser, mon_a_ser, node_a_blocks, outbound_htlc_expiry, inbound_hash);
+ {
+ let chanmon_cfgs = lightning_0_2_utils::create_chanmon_cfgs(2);
+ let node_cfgs = lightning_0_2_utils::create_node_cfgs(2, &chanmon_cfgs);
+ let mut config = lightning_0_2_utils::test_default_channel_config();
+ config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
+ config.manually_accept_inbound_channels = true;
+ let configs = [Some(config.clone()), Some(config)];
+ let node_chanmgrs = lightning_0_2_utils::create_node_chanmgrs(2, &node_cfgs, &configs);
+ let nodes = lightning_0_2_utils::create_network(2, &node_cfgs, &node_chanmgrs);
+ let node_a_id = nodes[0].node.get_our_node_id();
+ let node_b_id = nodes[1].node.get_our_node_id();
+
+ lightning_0_2_utils::provide_anchor_reserves(&nodes);
+ let chan_id = lightning_0_2_utils::create_chan_between_nodes_with_value(
+ &nodes[0],
+ &nodes[1],
+ 1_000_000,
+ 500_000_000,
+ )
+ .3;
+
+ // B claims the HTLC we offer, but we never learn its preimage off-chain.
+ let (outbound_preimage, outbound_hash, ..) =
+ lightning_0_2_utils::route_payment(&nodes[0], &[&nodes[1]], 10_000_000);
+ outbound_htlc_expiry = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1;
+ let (inbound_preimage, inbound_hash_0_2, ..) =
+ lightning_0_2_utils::route_payment(&nodes[1], &[&nodes[0]], 20_000_000);
+ inbound_hash = PaymentHash(inbound_hash_0_2.0);
+ nodes[1].node.claim_funds(outbound_preimage);
+ lightning_0_2_utils::check_added_monitors(&nodes[1], 1);
+ expect_payment_claimed_0_2!(nodes[1], outbound_hash, 10_000_000);
+ lightning_0_2_utils::get_htlc_update_msgs(&nodes[1], &node_a_id);
+
+ let commitment_tx = get_local_commitment_txn_0_2!(&nodes[0], chan_id).pop().unwrap();
+ for (node, counterparty_id) in [(&nodes[0], node_b_id), (&nodes[1], node_a_id)] {
+ lightning_0_2_utils::mine_transaction(node, &commitment_tx);
+ let reason = ClosureReason_0_2::CommitmentTxConfirmed;
+ lightning_0_2_utils::check_closed_event(
+ node,
+ 1,
+ reason,
+ false,
+ &[counterparty_id],
+ 1_000_000,
+ );
+ lightning_0_2_utils::check_closed_broadcast(node, 1, true);
+ lightning_0_2_utils::check_added_monitors(node, 1);
+ }
+
+ let mut bs_txn = nodes[1].tx_broadcaster.txn_broadcast();
+ bs_txn.retain(|tx| tx.input[0].previous_output.txid == commitment_tx.compute_txid());
+ assert_eq!(bs_txn.len(), 1);
+ lightning_0_2_utils::mine_transaction(&nodes[0], &bs_txn[0]);
+ lightning_0_2_utils::expect_payment_sent(&nodes[0], outbound_preimage, None, true, true);
+ lightning_0_2_utils::connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
+
+ nodes[0].node.claim_funds(inbound_preimage);
+ lightning_0_2_utils::check_added_monitors(&nodes[0], 1);
+ expect_payment_claimed_0_2!(nodes[0], inbound_hash_0_2, 20_000_000);
+ let mut events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ assert_eq!(events.len(), 1);
+ match events.pop().unwrap() {
+ Event_0_2::BumpTransaction(event) => nodes[0].bump_tx_handler.handle_event(&event),
+ _ => panic!("Unexpected event"),
+ }
+ let htlc_success_tx = nodes[0].tx_broadcaster.txn_broadcast().pop().unwrap();
+ lightning_0_2_utils::mine_transaction(&nodes[0], &htlc_success_tx);
+ lightning_0_2_utils::connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
+
+ node_a_ser = nodes[0].node.encode();
+ mon_a_ser = get_monitor_0_2!(nodes[0], chan_id).encode();
+ node_a_blocks = Arc::clone(&nodes[0].blocks);
+ }
+
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let (persister, chain_mon, node_a);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let config = test_default_channel_config();
+ reload_node!(nodes[0], config, &node_a_ser, &[&mon_a_ser[..]], persister, chain_mon, node_a);
+ nodes[0].blocks = node_a_blocks;
+ expect_payment_claimed!(nodes[0], inbound_hash, 20_000_000);
+ check_added_monitors(&nodes[0], 1);
+
+ connect_blocks(&nodes[0], outbound_htlc_expiry - nodes[0].best_block_info().1);
+ nodes[0].chain_monitor.chain_monitor.rebroadcast_pending_claims();
+ let events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ assert!(events.is_empty(), "{events:?}");
+ assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
+}
### lightning/src/chain/channelmonitor.rs
@@ -6317,6 +6317,27 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
}
}
+ // Claims of irrevocably spent HTLC outputs can never confirm.
+ if let Some((txid, _)) = self.confirmed_funding_spend() {
+ let best_height = self.best_block.height;
+ let resolved_outputs = self.htlcs_resolved_on_chain.iter()
+ .filter_map(|htlc| htlc.commitment_tx_output_idx);
+ // An HTLC spend which waits for a CSV delay is irrevocable after `ANTI_REORG_DELAY`
+ // confirmations, before it reaches `htlcs_resolved_on_chain`.
+ let irrevocably_spent_outputs = self.onchain_events_awaiting_threshold_conf.iter()
+ .filter_map(|entry| match entry.event {
+ OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, .. }
+ if entry.height + ANTI_REORG_DELAY - 1 <= best_height =>
+ {
+ Some(commitment_tx_output_idx)
+ },
+ _ => None,
+ });
+ let spent_outpoints = resolved_outputs.chain(irrevocably_spent_outputs)
+ .map(|vout| BitcoinOutPoint { txid, vout });
+ self.onchain_tx_handler.abandon_spent_outpoints(spent_outpoints, best_height, logger);
+ }
+
let conf_target = self.closure_conf_target();
self.onchain_tx_handler.update_claims_view_from_requests(
claimable_outpoints, conf_height, self.best_block.height, broadcaster, conf_target,
### lightning/src/chain/onchaintx.rs
@@ -780,6 +780,57 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
found_claim
}
+ /// Stops claiming `spent_outpoints`, which must be spent by transactions with at least
+ /// [`ANTI_REORG_DELAY`] confirmations. A pending claim which also spends other outpoints is
+ /// rebuilt without the spent ones once `cur_height` is passed to
+ /// [`Self::update_claims_view_from_matched_txn`].
+ pub(super) fn abandon_spent_outpoints<I: IntoIterator<Item = BitcoinOutPoint>, L: Logger>(
+ &mut self, spent_outpoints: I, cur_height: u32, logger: &L,
+ ) {
+ for outpoint in spent_outpoints {
+ if let Some((claim_id, _)) = self.claimable_outpoints.get(&outpoint).copied() {
+ // An outpoint which was split out of a claim maps to it until its spend has
+ // `ANTI_REORG_DELAY` confirmations, so check that the claim still spends it.
+ let claim = self.pending_claim_requests.get_mut(&claim_id);
+ if let Some(claim) = claim.filter(|claim| claim.outpoints().contains(&&outpoint)) {
+ log_info!(
+ logger,
+ "Abandoning claim of irrevocably spent outpoint {}",
+ outpoint
+ );
+ self.pending_claim_events.retain(|(id, _)| *id != claim_id);
+ if claim.outpoints().len() == 1 {
+ self.pending_claim_requests.remove(&claim_id);
+ // Outpoints which were split out of the claim can still map to it.
+ self.claimable_outpoints.retain(|_, (id, _)| *id != claim_id);
+ } else {
+ claim.split_package(&outpoint);
+ claim.set_timer(cur_height);
+ self.claimable_outpoints.remove(&outpoint);
+ }
+ }
+ }
+ self.locktimed_packages.retain(|_, claims| {
+ claims.retain_mut(|claim| {
+ if !claim.outpoints().contains(&&outpoint) {
+ return true;
+ }
+ log_info!(
+ logger,
+ "Abandoning claim of irrevocably spent outpoint {}",
+ outpoint
+ );
+ if claim.outpoints().len() == 1 {
+ return false;
+ }
+ claim.split_package(&outpoint);
+ true
+ });
+ !claims.is_empty()
+ });
+ }
+ }
+
/// Upon channelmonitor.block_connected(..) or upon provision of a preimage on the forward link
/// for this channel, provide new relevant on-chain transactions and/or new claim requests.
/// Together with `update_claims_view_from_matched_txn` this used to be named
### lightning/src/ln/functional_tests.rs
@@ -1757,17 +1757,8 @@ pub fn test_htlc_on_chain_success() {
_ => panic!("Unexpected event"),
}
}
- // HTLC timeout claims for non-anchor channels are only aggregated when claimed from the
- // remote commitment transaction.
- let mut node_txn = nodes[0].tx_broadcaster.txn_broadcast();
- assert_eq!(node_txn.len(), 2);
- for tx in node_txn.iter() {
- check_spends!(tx, node_a_commitment_tx[0]);
- assert_ne!(tx.lock_time, LockTime::ZERO);
- assert_eq!(tx.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
- assert!(tx.output[0].script_pubkey.is_p2wsh()); // revokeable output
- }
- assert_ne!(node_txn[0].input[0].previous_output, node_txn[1].input[0].previous_output);
+ // nodes[0] doesn't try to time out the HTLCs which nodes[1] claimed on chain.
+ assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
}
fn do_test_htlc_on_chain_timeout(connect_style: ConnectStyle) {
### lightning/src/ln/monitor_tests.rs
@@ -3990,3 +3990,157 @@ fn test_onchain_claim_of_offchain_claimed_htlc_balance() {
// Processing the events acks the claim's `MonitorEvent`s.
assert!(get_monitor!(nodes[0], chan_id).list_unacked_monitor_events().is_empty());
}
+
+fn do_test_no_claim_for_resolved_holder_htlc_output(p2a_anchor: bool) {
+ // Test that once our counterparty's claim of an HTLC output on our confirmed commitment
+ // transaction is irrevocably confirmed, we never try to claim that output again, even after a
+ // preimage for another HTLC makes us rebuild the claims for the commitment transaction.
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let mut config = test_default_channel_config();
+ config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = !p2a_anchor;
+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor;
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let node_a_id = nodes[0].node.get_our_node_id();
+ let node_b_id = nodes[1].node.get_our_node_id();
+
+ let coinbase_tx = provide_anchor_reserves(&nodes);
+ let (_, _, _, chan_id, funding_tx) =
+ create_chan_between_nodes_with_value(&nodes[0], &nodes[1], 1_000_000, 500_000_000);
+
+ // B claims the HTLC we offer, but we never learn its preimage off-chain.
+ let (outbound_preimage, outbound_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 10_000_000);
+ let outbound_htlc_expiry = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1;
+ let (inbound_preimage, inbound_hash, ..) = route_payment(&nodes[1], &[&nodes[0]], 20_000_000);
+ nodes[1].node.claim_funds(outbound_preimage, Default::default());
+ check_added_monitors(&nodes[1], 1);
+ expect_payment_claimed!(nodes[1], outbound_hash, 10_000_000);
+ get_htlc_update_msgs(&nodes[1], &node_a_id);
+
+ let commitment_tx = get_local_commitment_txn!(&nodes[0], chan_id).pop().unwrap();
+ check_spends!(commitment_tx, funding_tx);
+ mine_transaction(&nodes[0], &commitment_tx);
+ check_closed_event(&nodes[0], 1, ClosureReason::CommitmentTxConfirmed, &[node_b_id], 1_000_000);
+ check_closed_broadcast(&nodes[0], 1, true);
+ check_added_monitors(&nodes[0], 1);
+ mine_transaction(&nodes[1], &commitment_tx);
+ check_closed_event(&nodes[1], 1, ClosureReason::CommitmentTxConfirmed, &[node_a_id], 1_000_000);
+ check_closed_broadcast(&nodes[1], 1, true);
+ check_added_monitors(&nodes[1], 1);
+
+ let mut bs_txn = nodes[1].tx_broadcaster.txn_broadcast();
+ bs_txn.retain(|tx| tx.input[0].previous_output.txid == commitment_tx.compute_txid());
+ assert_eq!(bs_txn.len(), 1);
+ let bs_preimage_claim = bs_txn.pop().unwrap();
+ check_spends!(bs_preimage_claim, commitment_tx);
+ mine_transaction(&nodes[0], &bs_preimage_claim);
+ expect_payment_sent(&nodes[0], outbound_preimage, None, true, true);
+ connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
+ assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+
+ // Claiming the HTLC we received rebuilds the claims for the HTLC outputs of our commitment
+ // transaction. Only the received HTLC gets a claim.
+ nodes[0].node.claim_funds(inbound_preimage, Default::default());
+ check_added_monitors(&nodes[0], 1);
+ expect_payment_claimed!(nodes[0], inbound_hash, 20_000_000);
+ let mut events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ assert_eq!(events.len(), 1, "{events:?}");
+ match events.pop().unwrap() {
+ Event::BumpTransaction(event) => nodes[0].bump_tx_handler.handle_event(&event),
+ event => panic!("Unexpected event {event:?}"),
+ }
+ let htlc_success_tx = nodes[0].tx_broadcaster.txn_broadcast().pop().unwrap();
+ check_spends!(htlc_success_tx, commitment_tx, coinbase_tx);
+ mine_transaction(&nodes[0], &htlc_success_tx);
+ connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
+
+ // When the HTLC we offered expires, we must not try to claim its output, which B spent.
+ connect_blocks(&nodes[0], outbound_htlc_expiry - nodes[0].best_block_info().1);
+ let events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ assert!(events.is_empty(), "{events:?}");
+ nodes[0].chain_monitor.chain_monitor.rebroadcast_pending_claims();
+ let events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ assert!(events.is_empty(), "{events:?}");
+ assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
+}
+
+#[test]
+fn test_no_claim_for_resolved_holder_htlc_output() {
+ do_test_no_claim_for_resolved_holder_htlc_output(false);
+ do_test_no_claim_for_resolved_holder_htlc_output(true);
+}
+
+fn do_test_claim_split_from_resolved_holder_htlc_output(p2a_anchor: bool) {
+ // Test that once our HTLC-Success transaction for an HTLC output on our confirmed commitment
+ // transaction is irrevocably confirmed, a later preimage for another HTLC only makes us claim
+ // that other HTLC's output.
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let mut config = test_default_channel_config();
+ config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = !p2a_anchor;
+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor;
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let node_b_id = nodes[1].node.get_our_node_id();
+
+ let coinbase_tx = provide_anchor_reserves(&nodes);
+ let (_, _, _, chan_id, _) =
+ create_chan_between_nodes_with_value(&nodes[0], &nodes[1], 1_000_000, 500_000_000);
+ let (first_preimage, first_hash, ..) = route_payment(&nodes[1], &[&nodes[0]], 10_000_000);
+ let (second_preimage, second_hash, ..) = route_payment(&nodes[1], &[&nodes[0]], 20_000_000);
+
+ let commitment_tx = get_local_commitment_txn!(&nodes[0], chan_id).pop().unwrap();
+ mine_transaction(&nodes[0], &commitment_tx);
+ check_closed_event(&nodes[0], 1, ClosureReason::CommitmentTxConfirmed, &[node_b_id], 1_000_000);
+ check_closed_broadcast(&nodes[0], 1, true);
+ check_added_monitors(&nodes[0], 1);
+
+ nodes[0].node.claim_funds(first_preimage, Default::default());
+ check_added_monitors(&nodes[0], 1);
+ expect_payment_claimed!(nodes[0], first_hash, 10_000_000);
+ let mut events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ assert_eq!(events.len(), 1, "{events:?}");
+ match events.pop().unwrap() {
+ Event::BumpTransaction(event) => nodes[0].bump_tx_handler.handle_event(&event),
+ event => panic!("Unexpected event {event:?}"),
+ }
+ let first_htlc_success_tx = nodes[0].tx_broadcaster.txn_broadcast().pop().unwrap();
+ check_spends!(first_htlc_success_tx, commitment_tx, coinbase_tx);
+ mine_transaction(&nodes[0], &first_htlc_success_tx);
+ connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
+ assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+
+ // After the next block, the claim must only spend the second HTLC's output.
+ nodes[0].node.claim_funds(second_preimage, Default::default());
+ check_added_monitors(&nodes[0], 1);
+ expect_payment_claimed!(nodes[0], second_hash, 20_000_000);
+ nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ nodes[0].tx_broadcaster.clear();
+ connect_blocks(&nodes[0], 1);
+ nodes[0].chain_monitor.chain_monitor.rebroadcast_pending_claims();
+ let mut events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+ assert_eq!(events.len(), 1, "{events:?}");
+ match events.pop().unwrap() {
+ Event::BumpTransaction(event) => {
+ if let BumpTransactionEvent::HTLCResolution { htlc_descriptors, .. } = &event {
+ assert_eq!(htlc_descriptors.len(), 1, "{htlc_descriptors:?}");
+ assert_eq!(htlc_descriptors[0].htlc.payment_hash, second_hash);
+ } else {
+ panic!("Unexpected event {event:?}");
+ }
+ nodes[0].bump_tx_handler.handle_event(&event);
+ },
+ event => panic!("Unexpected event {event:?}"),
+ }
+ let second_htlc_success_tx = nodes[0].tx_broadcaster.txn_broadcast().pop().unwrap();
+ check_spends!(second_htlc_success_tx, commitment_tx, coinbase_tx, first_htlc_success_tx);
+ let first_htlc_outpoint = first_htlc_success_tx.input[0].previous_output;
+ assert!(second_htlc_success_tx.input.iter().all(|i| i.previous_output != first_htlc_outpoint));
+}
+
+#[test]
+fn test_claim_split_from_resolved_holder_htlc_output() {
+ do_test_claim_split_from_resolved_holder_htlc_output(false);
+ do_test_claim_split_from_resolved_holder_htlc_output(true);
+}
### lightning/src/ln/payment_tests.rs
@@ -1002,19 +1002,17 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
mine_transaction(&nodes[0], &bs_htlc_claim_txn);
expect_payment_sent(&nodes[0], payment_preimage_1, None, true, true);
connect_blocks(&nodes[0], TEST_FINAL_CLTV * 4 + 20);
- let (first_htlc_timeout_tx, second_htlc_timeout_tx) = {
+ let htlc_timeout_tx = {
let mut txn = nodes[0].tx_broadcaster.unique_txn_broadcast();
- assert_eq!(txn.len(), 2);
- (txn.remove(0), txn.remove(0))
+ assert_eq!(txn.len(), 1);
+ txn.pop().unwrap()
};
- check_spends!(first_htlc_timeout_tx, as_commitment_tx);
- check_spends!(second_htlc_timeout_tx, as_commitment_tx);
- if first_htlc_timeout_tx.input[0].previous_output == bs_htlc_claim_txn.input[0].previous_output
- {
- confirm_transaction(&nodes[0], &second_htlc_timeout_tx);
- } else {
- confirm_transaction(&nodes[0], &first_htlc_timeout_tx);
- }
+ check_spends!(htlc_timeout_tx, as_commitment_tx);
+ assert_ne!(
+ htlc_timeout_tx.input[0].previous_output,
+ bs_htlc_claim_txn.input[0].previous_output
+ );
+ confirm_transaction(&nodes[0], &htlc_timeout_tx);
nodes[0].tx_broadcaster.clear();
let conditions = PaymentFailedConditions::new().from_mon_update();
expect_payment_failed_conditions(&nodes[0], payment_hash, false, conditions);Why this scored 57/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.