Skip to content

Commit d356625

Browse files
committed
lightningd: metadata received support (log and decline).
Signed-off-by: Rusty Russell <[email protected]>
1 parent d2b604c commit d356625

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

common/onion.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ struct onion_payload *onion_decode(const tal_t *ctx,
310310
*p->total_msat
311311
= amount_msat(tlv->payment_data->total_msat);
312312
}
313+
if (tlv->payment_metadata)
314+
p->payment_metadata
315+
= tal_dup_talarr(p, u8, tlv->payment_metadata);
316+
else
317+
p->payment_metadata = NULL;
318+
313319
p->tlv = tal_steal(p, tlv);
314320
return p;
315321

common/onion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct onion_payload {
1212
struct amount_msat *total_msat;
1313
struct short_channel_id *forward_channel;
1414
struct secret *payment_secret;
15+
u8 *payment_metadata;
1516

1617
/* If blinding is set, blinding_ss is the shared secret.*/
1718
struct pubkey *blinding;

lightningd/peer_htlcs.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ static void handle_localpay(struct htlc_in *hin,
363363
struct amount_msat amt_to_forward,
364364
u32 outgoing_cltv_value,
365365
struct amount_msat total_msat,
366-
const struct secret *payment_secret)
366+
const struct secret *payment_secret,
367+
const u8 *payment_metadata)
367368
{
368369
const u8 *failmsg;
369370
struct lightningd *ld = hin->key.channel->peer->ld;
@@ -424,6 +425,27 @@ static void handle_localpay(struct htlc_in *hin,
424425
goto fail;
425426
}
426427

428+
/* We don't expect payment_metadata; reject here */
429+
if (payment_metadata) {
430+
log_debug(hin->key.channel->log,
431+
"Unexpected payment_metadata %s",
432+
tal_hex(tmpctx, payment_metadata));
433+
/* BOLT #4:
434+
* 1. type: PERM|22 (`invalid_onion_payload`)
435+
* 2. data:
436+
* * [`bigsize`:`type`]
437+
* * [`u16`:`offset`]
438+
*
439+
* The decrypted onion per-hop payload was not understood by the processing node
440+
* or is incomplete. If the failure can be narrowed down to a specific tlv type in
441+
* the payload, the erring node may include that `type` and its byte `offset` in
442+
* the decrypted byte stream.
443+
*/
444+
failmsg = towire_invalid_onion_payload(NULL, TLV_TLV_PAYLOAD_PAYMENT_METADATA,
445+
/* FIXME: offset? */ 0);
446+
goto fail;
447+
}
448+
427449
htlc_set_add(ld, hin, total_msat, payment_secret);
428450
return;
429451

@@ -1007,6 +1029,10 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
10071029
json_add_secret(s, "payment_secret",
10081030
p->payload->payment_secret);
10091031
}
1032+
if (p->payload->payment_metadata) {
1033+
json_add_hex_talarr(s, "payment_metadata",
1034+
p->payload->payment_metadata);
1035+
}
10101036
}
10111037
json_add_hex_talarr(s, "next_onion", p->next_onion);
10121038
json_add_secret(s, "shared_secret", hin->shared_secret);
@@ -1056,7 +1082,8 @@ htlc_accepted_hook_final(struct htlc_accepted_hook_payload *request STEALS)
10561082
request->payload->amt_to_forward,
10571083
request->payload->outgoing_cltv,
10581084
*request->payload->total_msat,
1059-
request->payload->payment_secret);
1085+
request->payload->payment_secret,
1086+
request->payload->payment_metadata);
10601087

10611088
tal_free(request);
10621089
}

0 commit comments

Comments
 (0)