diff --git a/common/onion_decode.c b/common/onion_decode.c index a17c8e87e..0f6419d3a 100644 --- a/common/onion_decode.c +++ b/common/onion_decode.c @@ -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; diff --git a/common/onion_encode.h b/common/onion_encode.h index ba4821191..ac2129325 100644 --- a/common/onion_encode.h +++ b/common/onion_encode.h @@ -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; diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index b83a021c0..69158a769 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -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);