Skip to content

Commit 0d6dcc9

Browse files
Fix missing user_channel_id in PaymentForwarded
Previously, if a forwarding node reloaded mid-HTLC-forward with a preimage in the outbound edge monitor and the outbound edge channel still open, and subsequently reclaimed the inbound HTLC backwards, the PaymentForwarded event would be missing the next_user_channel_id field.
1 parent 48010cb commit 0d6dcc9

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3938,7 +3938,12 @@ fn do_test_durable_preimages_on_closed_channel(
39383938
let evs = nodes[1].node.get_and_clear_pending_events();
39393939
assert_eq!(evs.len(), if close_chans_before_reload { 2 } else { 1 });
39403940
for ev in evs {
3941-
if let Event::PaymentForwarded { .. } = ev {
3941+
if let Event::PaymentForwarded { claim_from_onchain_tx, next_user_channel_id, .. } = ev {
3942+
if !claim_from_onchain_tx {
3943+
// If the outbound channel is still open, the `next_user_channel_id` should be available.
3944+
// This was previously broken.
3945+
assert!(next_user_channel_id.is_some())
3946+
}
39423947
} else {
39433948
panic!();
39443949
}

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18707,14 +18707,16 @@ impl<
1870718707
}
1870818708
}
1870918709
for (channel_id, monitor) in args.channel_monitors.iter() {
18710-
let mut is_channel_closed = true;
18710+
let (mut is_channel_closed, mut user_channel_id_opt) = (true, None);
1871118711
let counterparty_node_id = monitor.get_counterparty_node_id();
1871218712
if let Some(peer_state_mtx) = per_peer_state.get(&counterparty_node_id) {
1871318713
let mut peer_state_lock = peer_state_mtx.lock().unwrap();
1871418714
let peer_state = &mut *peer_state_lock;
18715-
is_channel_closed = !peer_state.channel_by_id.contains_key(channel_id);
18716-
if reconstruct_manager_from_monitors && !is_channel_closed {
18717-
if let Some(chan) = peer_state.channel_by_id.get(channel_id) {
18715+
if let Some(chan) = peer_state.channel_by_id.get(channel_id) {
18716+
is_channel_closed = false;
18717+
user_channel_id_opt = Some(chan.context().get_user_id());
18718+
18719+
if reconstruct_manager_from_monitors {
1871818720
if let Some(funded_chan) = chan.as_funded() {
1871918721
for (payment_hash, prev_hop) in funded_chan.outbound_htlc_forwards()
1872018722
{
@@ -19014,7 +19016,7 @@ impl<
1901419016

1901519017
Some((htlc_source, payment_preimage, htlc.amount_msat,
1901619018
is_channel_closed, monitor.get_counterparty_node_id(),
19017-
monitor.get_funding_txo(), monitor.channel_id(), None))
19019+
monitor.get_funding_txo(), monitor.channel_id(), user_channel_id_opt))
1901819020
} else { None }
1901919021
} else {
1902019022
// If it was an outbound payment, we've handled it above - if a preimage

0 commit comments

Comments
 (0)