mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
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:
parent
885506765e
commit
d5c19b23d8
@ -151,6 +151,8 @@ struct onion_payload *onion_decode(const tal_t *ctx,
|
|||||||
const u8 *cursor = rs->raw_payload;
|
const u8 *cursor = rs->raw_payload;
|
||||||
size_t max = tal_bytelen(cursor), len;
|
size_t max = tal_bytelen(cursor), len;
|
||||||
|
|
||||||
|
p->final = (rs->nextcase == ONION_END);
|
||||||
|
|
||||||
/* BOLT-remove-legacy-onion #4:
|
/* BOLT-remove-legacy-onion #4:
|
||||||
* 1. type: `hop_payloads`
|
* 1. type: `hop_payloads`
|
||||||
* 2. data:
|
* 2. data:
|
||||||
@ -276,7 +278,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
|
|||||||
goto field_bad;
|
goto field_bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rs->nextcase == ONION_FORWARD) {
|
if (!p->final) {
|
||||||
if (!handle_blinded_forward(p, amount_in, cltv_expiry,
|
if (!handle_blinded_forward(p, amount_in, cltv_expiry,
|
||||||
p->tlv, enc, failtlvtype))
|
p->tlv, enc, failtlvtype))
|
||||||
goto field_bad;
|
goto field_bad;
|
||||||
@ -333,7 +335,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
|
|||||||
* - For every non-final node:
|
* - For every non-final node:
|
||||||
* - MUST include `short_channel_id`
|
* - MUST include `short_channel_id`
|
||||||
*/
|
*/
|
||||||
if (rs->nextcase == ONION_FORWARD) {
|
if (!p->final) {
|
||||||
if (!p->tlv->short_channel_id) {
|
if (!p->tlv->short_channel_id) {
|
||||||
*failtlvtype = TLV_TLV_PAYLOAD_SHORT_CHANNEL_ID;
|
*failtlvtype = TLV_TLV_PAYLOAD_SHORT_CHANNEL_ID;
|
||||||
goto field_bad;
|
goto field_bad;
|
||||||
|
@ -14,6 +14,8 @@ enum onion_payload_type {
|
|||||||
|
|
||||||
struct onion_payload {
|
struct onion_payload {
|
||||||
enum onion_payload_type type;
|
enum onion_payload_type type;
|
||||||
|
/* Is this the final hop? */
|
||||||
|
bool final;
|
||||||
|
|
||||||
struct amount_msat amt_to_forward;
|
struct amount_msat amt_to_forward;
|
||||||
u32 outgoing_cltv;
|
u32 outgoing_cltv;
|
||||||
|
@ -1201,17 +1201,16 @@ REGISTER_PLUGIN_HOOK(htlc_accepted,
|
|||||||
|
|
||||||
/* Figures out how to fwd, allocating return off hp */
|
/* Figures out how to fwd, allocating return off hp */
|
||||||
static struct channel_id *calc_forwarding_channel(struct lightningd *ld,
|
static struct channel_id *calc_forwarding_channel(struct lightningd *ld,
|
||||||
struct htlc_accepted_hook_payload *hp,
|
struct htlc_accepted_hook_payload *hp)
|
||||||
const struct route_step *rs)
|
|
||||||
{
|
{
|
||||||
const struct onion_payload *p = hp->payload;
|
const struct onion_payload *p = hp->payload;
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
struct channel *c, *best;
|
struct channel *c, *best;
|
||||||
|
|
||||||
if (rs->nextcase != ONION_FORWARD)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!p)
|
if (p->final)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (p->forward_channel) {
|
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 don't store actual channel as it could vanish while
|
||||||
* we're in hook */
|
* we're in hook */
|
||||||
hook_payload->fwd_channel_id
|
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);
|
plugin_hook_call_htlc_accepted(ld, NULL, hook_payload);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user