Skip to content

Commit

Permalink
hooks: Add the raw payload to the htlc_accepted call
Browse files Browse the repository at this point in the history
Since we might soon be changing the payload it is a good idea to not just
expose the v0 payload, but also the raw payload for the plugin to
interpret. This might also include payloads that `lightningd` itself cannot
understand, but the plugin might.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Suggested-by: Corné Plooy <@bitonic-cjp>
  • Loading branch information
cdecker committed Apr 8, 2019
1 parent 5d6d70c commit e8a468b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/sphinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ struct route_step *process_onionpacket(
deserialize_hop_data(&step->hop_data, paddedheader);

memcpy(&step->next->mac, step->hop_data.hmac, SECURITY_PARAMETER);
step->raw_payload = tal_dup_arr(step, u8, paddedheader + 1,
HOP_DATA_SIZE - 1 - HMAC_SIZE, 0);

memcpy(&step->next->routinginfo, paddedheader + HOP_DATA_SIZE, ROUTING_INFO_SIZE);

Expand Down
1 change: 1 addition & 0 deletions common/sphinx.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct route_step {
enum route_next_case nextcase;
struct onionpacket *next;
struct hop_data hop_data;
u8 *raw_payload;
};

/**
Expand Down
1 change: 1 addition & 0 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
const struct htlc_in *hin = p->hin;
json_object_start(s, "onion");

json_add_hex_talarr (s, "payload", rs->raw_payload);
json_object_start(s, "hop_data");
json_add_hex(s, "realm", &rs->hop_data.realm, 1);
json_add_short_channel_id(s, "short_channel_id", &rs->hop_data.channel_id);
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/fail_htlcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@plugin.hook("htlc_accepted")
def on_htlc_accepted(htlc, onion, plugin):
plugin.log("Failing htlc on purpose")
plugin.log("onion: %r" % (onion))
return {"result": "fail"}


Expand Down

0 comments on commit e8a468b

Please sign in to comment.