common/onion_decode: put final flag in onion_payload.

You can use rs->nextcase, but we don't always keep that around, so
keep a flag in onion_payload.

We'll use this in the "do we need to return a blinded error code"
patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-01-12 14:22:38 +10:30
parent 885506765e
commit d5c19b23d8
3 changed files with 10 additions and 7 deletions

View File

@ -151,6 +151,8 @@ struct onion_payload *onion_decode(const tal_t *ctx,
const u8 *cursor = rs->raw_payload;
size_t max = tal_bytelen(cursor), len;
p->final = (rs->nextcase == ONION_END);
/* BOLT-remove-legacy-onion #4:
* 1. type: `hop_payloads`
* 2. data:
@ -276,7 +278,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
goto field_bad;
}
if (rs->nextcase == ONION_FORWARD) {
if (!p->final) {
if (!handle_blinded_forward(p, amount_in, cltv_expiry,
p->tlv, enc, failtlvtype))
goto field_bad;
@ -333,7 +335,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
* - For every non-final node:
* - MUST include `short_channel_id`
*/
if (rs->nextcase == ONION_FORWARD) {
if (!p->final) {
if (!p->tlv->short_channel_id) {
*failtlvtype = TLV_TLV_PAYLOAD_SHORT_CHANNEL_ID;
goto field_bad;

View File

@ -14,6 +14,8 @@ enum onion_payload_type {
struct onion_payload {
enum onion_payload_type type;
/* Is this the final hop? */
bool final;
struct amount_msat amt_to_forward;
u32 outgoing_cltv;

View File

@ -1201,17 +1201,16 @@ REGISTER_PLUGIN_HOOK(htlc_accepted,
/* Figures out how to fwd, allocating return off hp */
static struct channel_id *calc_forwarding_channel(struct lightningd *ld,
struct htlc_accepted_hook_payload *hp,
const struct route_step *rs)
struct htlc_accepted_hook_payload *hp)
{
const struct onion_payload *p = hp->payload;
struct peer *peer;
struct channel *c, *best;
if (rs->nextcase != ONION_FORWARD)
if (!p)
return NULL;
if (!p)
if (p->final)
return NULL;
if (p->forward_channel) {
@ -1402,7 +1401,7 @@ static bool peer_accepted_htlc(const tal_t *ctx,
/* We don't store actual channel as it could vanish while
* we're in hook */
hook_payload->fwd_channel_id
= calc_forwarding_channel(ld, hook_payload, rs);
= calc_forwarding_channel(ld, hook_payload);
plugin_hook_call_htlc_accepted(ld, NULL, hook_payload);