Skip to content

Report the sending peer in Event::OnionMessageIntercepted#4682

Open
jkczyz wants to merge 2 commits into
lightningdevkit:mainfrom
jkczyz:2026-06-onion-message-origin
Open

Report the sending peer in Event::OnionMessageIntercepted#4682
jkczyz wants to merge 2 commits into
lightningdevkit:mainfrom
jkczyz:2026-06-onion-message-origin

Conversation

@jkczyz

@jkczyz jkczyz commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

When the OnionMessenger intercepts a message bound for an offline peer, it now reports which peer sent us the message to forward via a new prev_node_id field, so handlers can apply source-based policy when deciding whether to forward. The existing destination field is renamed peer_node_id -> next_node_id so the two node ids are unambiguous.

prev_node_id is None when the forward is enqueued by a message handler (the BOLT 12 static-invoice-server flow), which isn't given the sending node; otherwise it is the node we received the message from.

@ldk-reviews-bot

ldk-reviews-bot commented Jun 11, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@jkczyz jkczyz requested a review from TheBlueMatt June 11, 2026 14:28
@ldk-claude-review-bot

ldk-claude-review-bot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

The previously flagged blocking issue at messenger.rs:1744 is now resolved — the offline-peer interception path correctly reports NextMessageHop::NodeId(next_node_id) instead of reusing next_hop verbatim. This is confirmed in the current commit.

I re-reviewed the full diff for new issues: the TLV serialization/compat logic (legacy field 0 peer_node_id, field 1 next_hop, field 3 prev_hop, read-side .or() fallback), the impl_ser_tlv_based_enum! macro on NextMessageHop, the new intercept_for_unknown_scids constructor arg threading, and the call sites (None on originate, Some(peer_node_id) on forward) are all correct.

No new issues found. The stale-comment minor issues at functional_tests.rs:1240-1242 and :1264 were already flagged in a prior pass and are not repeated here.

Cross-cutting note (previously raised, not re-flagged): enabling intercept_for_unknown_scids allows any unresolvable SCID to enqueue an event into the unbounded pending_intercepted_msgs_events, which lowers the bar for event-flooding versus the offline-peer path. This remains a design tradeoff the user explicitly opts into.

@TheBlueMatt TheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. hate changing the api at this point but backporting to 0.3 probably should happen cause its trivial

Comment thread lightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@jkczyz jkczyz force-pushed the 2026-06-onion-message-origin branch from e0c7e55 to 41ef2e6 Compare June 11, 2026 15:01
@jkczyz jkczyz requested a review from TheBlueMatt June 11, 2026 15:01

@tnull tnull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this seems to conflict with the first commit on #4463. Do you maybe want to pull that commit here to do it in one go?

@jkczyz jkczyz self-assigned this Jun 11, 2026
@jkczyz jkczyz force-pushed the 2026-06-onion-message-origin branch from 41ef2e6 to 316a0ce Compare June 11, 2026 19:12
@jkczyz

jkczyz commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, this seems to conflict with the first commit on #4463. Do you maybe want to pull that commit here to do it in one go?

Good idea! Done, but needed to rebase.

@jkczyz jkczyz requested a review from tnull June 11, 2026 19:13
Comment thread lightning/src/onion_message/messenger.rs
TheBlueMatt
TheBlueMatt previously approved these changes Jun 12, 2026

@TheBlueMatt TheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two doc nits otherwise LGTM

Comment thread lightning/src/events/mod.rs Outdated
Comment thread lightning/src/events/mod.rs Outdated
/// The node id of the peer that sent the message, if known.
///
/// This is `None` when the forward is enqueued by a message handler (e.g. the BOLT 12
/// static-invoice-server flow), which isn't given the sending node. Otherwise it is the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to just document it as "message is sent with a MessageSendInstructions::ForwardedMessage rather than forwarded internally in the OnionMessenger"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, though gave an example of which method does that since it might not be apparent to users.

@jkczyz jkczyz force-pushed the 2026-06-onion-message-origin branch from 316a0ce to 58e11d0 Compare June 12, 2026 15:08
@jkczyz jkczyz requested a review from TheBlueMatt June 12, 2026 15:09
Comment thread lightning/src/onion_message/functional_tests.rs Outdated
tnull and others added 2 commits June 12, 2026 10:44
Allow integrations to intercept blinded onion-message hops that identify
the next node by short channel id, so LSPS-style protocols can resolve
those hops out of band instead of dropping the message.

Co-Authored-By: HAL 9000
When the OnionMessenger intercepts an onion message to forward, it now reports
which peer sent us the message via a new `prev_hop` field, so handlers can
apply source-based policy when deciding whether to forward.

`prev_hop` is `None` when the forward is enqueued by a message handler (the
BOLT 12 static-invoice-server flow), which isn't given the sending node;
otherwise it is the node we received the message from.

Co-Authored-By: Claude <noreply@anthropic.com>
@jkczyz jkczyz force-pushed the 2026-06-onion-message-origin branch from 58e11d0 to 1a0e530 Compare June 12, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants