mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-23 06:55:13 +01:00
lightningd: metadata received support (log and decline).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
e01abf0b34
commit
4718ee076c
3 changed files with 37 additions and 2 deletions
|
@ -241,6 +241,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
|
||||||
p->amt_to_forward = fromwire_amount_msat(&cursor, &max);
|
p->amt_to_forward = fromwire_amount_msat(&cursor, &max);
|
||||||
p->outgoing_cltv = fromwire_u32(&cursor, &max);
|
p->outgoing_cltv = fromwire_u32(&cursor, &max);
|
||||||
p->payment_secret = NULL;
|
p->payment_secret = NULL;
|
||||||
|
p->payment_metadata = NULL;
|
||||||
p->blinding = NULL;
|
p->blinding = NULL;
|
||||||
/* We can't handle blinding with a legacy payload */
|
/* We can't handle blinding with a legacy payload */
|
||||||
if (blinding)
|
if (blinding)
|
||||||
|
@ -365,6 +366,12 @@ struct onion_payload *onion_decode(const tal_t *ctx,
|
||||||
*p->total_msat
|
*p->total_msat
|
||||||
= amount_msat(tlv->payment_data->total_msat);
|
= amount_msat(tlv->payment_data->total_msat);
|
||||||
}
|
}
|
||||||
|
if (tlv->payment_metadata)
|
||||||
|
p->payment_metadata
|
||||||
|
= tal_dup_talarr(p, u8, tlv->payment_metadata);
|
||||||
|
else
|
||||||
|
p->payment_metadata = NULL;
|
||||||
|
|
||||||
p->tlv = tal_steal(p, tlv);
|
p->tlv = tal_steal(p, tlv);
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct onion_payload {
|
||||||
struct amount_msat *total_msat;
|
struct amount_msat *total_msat;
|
||||||
struct short_channel_id *forward_channel;
|
struct short_channel_id *forward_channel;
|
||||||
struct secret *payment_secret;
|
struct secret *payment_secret;
|
||||||
|
u8 *payment_metadata;
|
||||||
|
|
||||||
/* If blinding is set, blinding_ss is the shared secret.*/
|
/* If blinding is set, blinding_ss is the shared secret.*/
|
||||||
struct pubkey *blinding;
|
struct pubkey *blinding;
|
||||||
|
|
|
@ -363,7 +363,8 @@ static void handle_localpay(struct htlc_in *hin,
|
||||||
struct amount_msat amt_to_forward,
|
struct amount_msat amt_to_forward,
|
||||||
u32 outgoing_cltv_value,
|
u32 outgoing_cltv_value,
|
||||||
struct amount_msat total_msat,
|
struct amount_msat total_msat,
|
||||||
const struct secret *payment_secret)
|
const struct secret *payment_secret,
|
||||||
|
const u8 *payment_metadata)
|
||||||
{
|
{
|
||||||
const u8 *failmsg;
|
const u8 *failmsg;
|
||||||
struct lightningd *ld = hin->key.channel->peer->ld;
|
struct lightningd *ld = hin->key.channel->peer->ld;
|
||||||
|
@ -424,6 +425,27 @@ static void handle_localpay(struct htlc_in *hin,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We don't expect payment_metadata; reject here */
|
||||||
|
if (payment_metadata) {
|
||||||
|
log_debug(hin->key.channel->log,
|
||||||
|
"Unexpected payment_metadata %s",
|
||||||
|
tal_hex(tmpctx, payment_metadata));
|
||||||
|
/* BOLT #4:
|
||||||
|
* 1. type: PERM|22 (`invalid_onion_payload`)
|
||||||
|
* 2. data:
|
||||||
|
* * [`bigsize`:`type`]
|
||||||
|
* * [`u16`:`offset`]
|
||||||
|
*
|
||||||
|
* The decrypted onion per-hop payload was not understood by the processing node
|
||||||
|
* or is incomplete. If the failure can be narrowed down to a specific tlv type in
|
||||||
|
* the payload, the erring node may include that `type` and its byte `offset` in
|
||||||
|
* the decrypted byte stream.
|
||||||
|
*/
|
||||||
|
failmsg = towire_invalid_onion_payload(NULL, TLV_TLV_PAYLOAD_PAYMENT_METADATA,
|
||||||
|
/* FIXME: offset? */ 0);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
htlc_set_add(ld, hin, total_msat, payment_secret);
|
htlc_set_add(ld, hin, total_msat, payment_secret);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1033,6 +1055,10 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
|
||||||
json_add_secret(s, "payment_secret",
|
json_add_secret(s, "payment_secret",
|
||||||
p->payload->payment_secret);
|
p->payload->payment_secret);
|
||||||
}
|
}
|
||||||
|
if (p->payload->payment_metadata) {
|
||||||
|
json_add_hex_talarr(s, "payment_metadata",
|
||||||
|
p->payload->payment_metadata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
json_add_hex_talarr(s, "next_onion", p->next_onion);
|
json_add_hex_talarr(s, "next_onion", p->next_onion);
|
||||||
json_add_secret(s, "shared_secret", hin->shared_secret);
|
json_add_secret(s, "shared_secret", hin->shared_secret);
|
||||||
|
@ -1082,7 +1108,8 @@ htlc_accepted_hook_final(struct htlc_accepted_hook_payload *request STEALS)
|
||||||
request->payload->amt_to_forward,
|
request->payload->amt_to_forward,
|
||||||
request->payload->outgoing_cltv,
|
request->payload->outgoing_cltv,
|
||||||
*request->payload->total_msat,
|
*request->payload->total_msat,
|
||||||
request->payload->payment_secret);
|
request->payload->payment_secret,
|
||||||
|
request->payload->payment_metadata);
|
||||||
|
|
||||||
tal_free(request);
|
tal_free(request);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue