lightningd: add peer_id to htlc_accepted_hook
What changed, and why it matters
This commit adds extra information — the identity of the peer that sent an HTLC — to a plugin hook called htlc_accepted. It is a straightforward feature enhancement for plugin developers and does not change how payments are validated, accepted, or rejected. There is no security issue visible in the change itself.
No security action required. Review as a normal feature/documentation change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch extends the htlc_accepted_hook payload by serializing p->channel->peer->id as peer_id when the channel and peer objects are available. It also updates the developer documentation to describe the new field. The change is additive only and does not alter HTLC validation logic, authorization decisions, or memory handling.
Changed components
lightningd/peer_htlcs.cdoc/developers-guide/plugin-development/hooks.mdInspect captured patch +5 / −0
diff --git a/doc/developers-guide/plugin-development/hooks.md b/doc/developers-guide/plugin-development/hooks.md
index 9b3bacd9..d78abe77 100644
--- a/doc/developers-guide/plugin-development/hooks.md
+++ b/doc/developers-guide/plugin-development/hooks.md
@@ -400,6 +400,7 @@ The payload of the hook call has the following format:
```json
{
+ "peer_id": "02df5ffe895c778e10f7742a6c5b8a0cefbe9465df58b92fadeb883752c8107c8f",
"onion": {
"payload": "",
"short_channel_id": "1x2x3",
@@ -425,6 +426,7 @@ The payload of the hook call has the following format:
For detailed information about each field please refer to [BOLT 04 of the specification](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), the following is just a brief summary:
+- `peer_id`: is the id of the peer that offered us this htlc.
- `onion`:
- `payload` contains the unparsed payload that was sent to us from the sender of the payment.
- `short_channel_id` determines the channel that the sender is hinting should be used next. Not present if we're the final destination.
diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c
index 99c287f9..7c818782 100644
--- a/lightningd/peer_htlcs.c
+++ b/lightningd/peer_htlcs.c
@@ -1193,6 +1193,9 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
tal_fmt(hin, "Waiting for the htlc_accepted hook of plugin %s",
plugin->shortname);
+ if (p->channel && p->channel->peer)
+ json_add_node_id(s, "peer_id", &p->channel->peer->id);
+
json_object_start(s, "onion");
json_add_hex_talarr(s, "payload", rs->raw_payload);
Why this scored 15/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.