From 477f574569c5c316f50084dac1e4af51b193ee5f Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 17 Jun 2021 15:16:55 +0200 Subject: [PATCH] htlc: Keep the parsed TLV payload around with the htlc_in We want to show the fields in the invoice_payment hook. --- common/onion.c | 3 ++- common/onion.h | 3 +++ lightningd/htlc_end.h | 3 +++ lightningd/peer_htlcs.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/common/onion.c b/common/onion.c index 535f5fa57..6529d977d 100644 --- a/common/onion.c +++ b/common/onion.c @@ -306,6 +306,7 @@ struct onion_payload *onion_decode(const tal_t *ctx, /* If they somehow got an invalid onion this far, fail. */ if (!cursor) return tal_free(p); + p->tlv = NULL; return p; case ONION_TLV_PAYLOAD: @@ -404,7 +405,7 @@ struct onion_payload *onion_decode(const tal_t *ctx, *p->total_msat = amount_msat(tlv->payment_data->total_msat); } - tal_free(tlv); + p->tlv = tal_steal(p, tlv); return p; } diff --git a/common/onion.h b/common/onion.h index 157f4b0fa..a84301f21 100644 --- a/common/onion.h +++ b/common/onion.h @@ -24,6 +24,9 @@ struct onion_payload { /* If blinding is set, blinding_ss is the shared secret.*/ struct pubkey *blinding; struct secret blinding_ss; + + /* The raw TLVs contained in the payload. */ + struct tlv_tlv_payload *tlv; }; u8 *onion_nonfinal_hop(const tal_t *ctx, diff --git a/lightningd/htlc_end.h b/lightningd/htlc_end.h index 4c8e62d77..1220b5cb4 100644 --- a/lightningd/htlc_end.h +++ b/lightningd/htlc_end.h @@ -58,6 +58,9 @@ struct htlc_in { /* A simple text annotation shown in `listpeers` */ char *status; + + /* The decoded onion payload after hooks processed it. */ + struct onion_payload *payload; }; struct htlc_out { diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index f56565e1b..acbd3149e 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1077,6 +1077,10 @@ htlc_accepted_hook_final(struct htlc_accepted_hook_payload *request STEALS) request->hin->status = tal_free(request->hin->status); + /* Hand the payload to the htlc_in since we'll want to have that info + * handy for the hooks and notifications. */ + request->hin->payload = tal_steal(request->hin, request->payload); + /* *Now* we barf if it failed to decode */ if (!request->payload) { log_debug(channel->log,