Skip to content

Commit 379edfc

Browse files
committed
Avoid returning full HTLC info in get_pending_or_resolved_outbound_htlcs
We previously returned a `HTLCOutputInCommitment`, even though we only needed the HTLC's `payment_hash` and `amount_msat`. We make this change as we don't want callers to rely on the HTLC's `transaction_output_index`, as that can change across `FundingScope`s due to splices.
1 parent 4e03e45 commit 379edfc

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
29232923
/// HTLCs which were resolved on-chain (i.e. where the final HTLC resolution was done by an
29242924
/// event from this `ChannelMonitor`).
29252925
#[rustfmt::skip]
2926-
pub(crate) fn get_all_current_outbound_htlcs(&self) -> HashMap<HTLCSource, (HTLCOutputInCommitment, Option<PaymentPreimage>)> {
2926+
pub(crate) fn get_all_current_outbound_htlcs(&self) -> HashMap<HTLCSource, (PaymentHash, u64, Option<PaymentPreimage>)> {
29272927
let mut res = new_hash_map();
29282928
// Just examine the available counterparty commitment transactions. See docs on
29292929
// `fail_unbroadcast_htlcs`, below, for justification.
@@ -2933,7 +2933,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
29332933
if let Some(ref latest_outpoints) = us.funding.counterparty_claimable_outpoints.get($txid) {
29342934
for &(ref htlc, ref source_option) in latest_outpoints.iter() {
29352935
if let &Some(ref source) = source_option {
2936-
res.insert((**source).clone(), (htlc.clone(),
2936+
res.insert((**source).clone(), (htlc.payment_hash, htlc.amount_msat,
29372937
us.counterparty_fulfilled_htlcs.get(&SentHTLCId::from_source(source)).cloned()));
29382938
}
29392939
}
@@ -2957,7 +2957,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
29572957
/// Currently, the preimage is unused, however if it is present in the relevant internal state
29582958
/// an HTLC is always included even if it has been resolved.
29592959
#[rustfmt::skip]
2960-
pub(crate) fn get_pending_or_resolved_outbound_htlcs(&self) -> HashMap<HTLCSource, (HTLCOutputInCommitment, Option<PaymentPreimage>)> {
2960+
pub(crate) fn get_pending_or_resolved_outbound_htlcs(&self) -> HashMap<HTLCSource, (PaymentHash, u64, Option<PaymentPreimage>)> {
29612961
let us = self.inner.lock().unwrap();
29622962
// We're only concerned with the confirmation count of HTLC transactions, and don't
29632963
// actually care how many confirmations a commitment transaction may or may not have. Thus,
@@ -3009,7 +3009,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
30093009
let counterparty_resolved_preimage_opt =
30103010
us.counterparty_fulfilled_htlcs.get(&SentHTLCId::from_source(source)).cloned();
30113011
if !htlc_update_confd || counterparty_resolved_preimage_opt.is_some() {
3012-
res.insert(source.clone(), (htlc.clone(), counterparty_resolved_preimage_opt));
3012+
res.insert(source.clone(), (htlc.payment_hash, htlc.amount_msat, counterparty_resolved_preimage_opt));
30133013
}
30143014
} else {
30153015
panic!("Outbound HTLCs should have a source");

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,7 +4402,7 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
44024402
assert!(get_monitor!(nodes[1], chan_b.2)
44034403
.get_all_current_outbound_htlcs()
44044404
.iter()
4405-
.any(|(_, (_, preimage))| *preimage == Some(payment_preimage)));
4405+
.any(|(_, (_, _, preimage))| *preimage == Some(payment_preimage)));
44064406

44074407
// Once we complete the `ChannelMonitorUpdate` on channel A, and the `ChannelManager` processes
44084408
// background events (via `get_and_clear_pending_msg_events`), the final `ChannelMonitorUpdate`
@@ -4418,7 +4418,7 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
44184418
assert!(!get_monitor!(nodes[1], chan_b.2)
44194419
.get_all_current_outbound_htlcs()
44204420
.iter()
4421-
.any(|(_, (_, preimage))| *preimage == Some(payment_preimage)));
4421+
.any(|(_, (_, _, preimage))| *preimage == Some(payment_preimage)));
44224422
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], None, true, false);
44234423
}
44244424

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16273,13 +16273,11 @@ where
1627316273
}
1627416274

1627516275
if is_channel_closed {
16276-
for (htlc_source, (htlc, _)) in monitor.get_pending_or_resolved_outbound_htlcs()
16276+
for (htlc_source, (payment_hash, _, _)) in
16277+
monitor.get_pending_or_resolved_outbound_htlcs()
1627716278
{
16278-
let logger = WithChannelMonitor::from(
16279-
&args.logger,
16280-
monitor,
16281-
Some(htlc.payment_hash),
16282-
);
16279+
let logger =
16280+
WithChannelMonitor::from(&args.logger, monitor, Some(payment_hash));
1628316281
if let HTLCSource::OutboundRoute {
1628416282
payment_id, session_priv, path, ..
1628516283
} = htlc_source
@@ -16293,22 +16291,19 @@ where
1629316291
session_priv_bytes[..].copy_from_slice(&session_priv[..]);
1629416292
pending_outbounds.insert_from_monitor_on_startup(
1629516293
payment_id,
16296-
htlc.payment_hash,
16294+
payment_hash,
1629716295
session_priv_bytes,
1629816296
&path,
1629916297
best_block_height,
1630016298
logger,
1630116299
);
1630216300
}
1630316301
}
16304-
for (htlc_source, (htlc, preimage_opt)) in
16302+
for (htlc_source, (payment_hash, _, preimage_opt)) in
1630516303
monitor.get_all_current_outbound_htlcs()
1630616304
{
16307-
let logger = WithChannelMonitor::from(
16308-
&args.logger,
16309-
monitor,
16310-
Some(htlc.payment_hash),
16311-
);
16305+
let logger =
16306+
WithChannelMonitor::from(&args.logger, monitor, Some(payment_hash));
1631216307
match htlc_source {
1631316308
HTLCSource::PreviousHopData(prev_hop_data) => {
1631416309
let pending_forward_matches_htlc = |info: &PendingAddHTLCInfo| {
@@ -16326,7 +16321,7 @@ where
1632616321
update_add_htlc.htlc_id == prev_hop_data.htlc_id;
1632716322
if matches {
1632816323
log_info!(logger, "Removing pending to-decode HTLC with hash {} as it was forwarded to the closed channel {}",
16329-
&htlc.payment_hash, &monitor.channel_id());
16324+
&payment_hash, &monitor.channel_id());
1633016325
}
1633116326
!matches
1633216327
});
@@ -16337,7 +16332,7 @@ where
1633716332
if let HTLCForwardInfo::AddHTLC(htlc_info) = forward {
1633816333
if pending_forward_matches_htlc(&htlc_info) {
1633916334
log_info!(logger, "Removing pending to-forward HTLC with hash {} as it was forwarded to the closed channel {}",
16340-
&htlc.payment_hash, &monitor.channel_id());
16335+
&payment_hash, &monitor.channel_id());
1634116336
false
1634216337
} else { true }
1634316338
} else { true }
@@ -16347,7 +16342,7 @@ where
1634716342
pending_intercepted_htlcs.as_mut().unwrap().retain(|intercepted_id, htlc_info| {
1634816343
if pending_forward_matches_htlc(&htlc_info) {
1634916344
log_info!(logger, "Removing pending intercepted HTLC with hash {} as it was forwarded to the closed channel {}",
16350-
&htlc.payment_hash, &monitor.channel_id());
16345+
&payment_hash, &monitor.channel_id());
1635116346
pending_events_read.retain(|(event, _)| {
1635216347
if let Event::HTLCIntercepted { intercept_id: ev_id, .. } = event {
1635316348
intercepted_id != ev_id
@@ -16404,7 +16399,7 @@ where
1640416399
let mut fail_read = false;
1640516400
let outbound_claimed_htlcs_iter = monitor.get_all_current_outbound_htlcs()
1640616401
.into_iter()
16407-
.filter_map(|(htlc_source, (htlc, preimage_opt))| {
16402+
.filter_map(|(htlc_source, (_, amount_msat, preimage_opt))| {
1640816403
if let HTLCSource::PreviousHopData(prev_hop) = &htlc_source {
1640916404
if let Some(payment_preimage) = preimage_opt {
1641016405
let inbound_edge_monitor = args.channel_monitors.get(&prev_hop.channel_id);
@@ -16492,7 +16487,7 @@ where
1649216487
);
1649316488
}
1649416489

16495-
Some((htlc_source, payment_preimage, htlc.amount_msat,
16490+
Some((htlc_source, payment_preimage, amount_msat,
1649616491
is_channel_closed, monitor.get_counterparty_node_id(),
1649716492
monitor.get_funding_txo(), monitor.channel_id()))
1649816493
} else { None }

0 commit comments

Comments
 (0)