Skip to content

Commit ea7a032

Browse files
committed
onion: add payload type tracking to route_step and onion_payload
Add `onion_payload_type` enum and `type` field to track whether payloads are legacy v0 or modern TLV format. Move the `onion_payload_type` enum from `onion_encode.h` to `sphinx.h` and add a `type` field to both `route_step` and `onion_payload` structures. Previously, `onion_payload` had the `type` field declared but it was never set or used. The type is now set during onion processing in `process_onionpacket()` based on the payload format detected, then propagated to `onion_payload` in `onion_decode()`. This allows code to easily determine the payload format without re-parsing the raw payload. Changelog-None
1 parent 73147da commit ea7a032

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

common/onion_decode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
200200
size_t max = tal_bytelen(cursor), len;
201201

202202
p->final = (rs->nextcase == ONION_END);
203+
p->type = rs->type;
203204

204205
/* BOLT #4:
205206
* 1. type: `hop_payloads`

common/onion_encode.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <assert.h>
33
#include <ccan/cast/cast.h>
44
#include <common/onion_encode.h>
5-
#include <common/sphinx.h>
65
#include <common/utils.h>
76

87
/* BOLT #4:

common/onion_encode.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
#include "config.h"
44
#include <bitcoin/privkey.h>
55
#include <common/amount.h>
6+
#include <common/sphinx.h>
67

78
struct route_step;
89
struct tlv_encrypted_data_tlv_payment_relay;
910

10-
enum onion_payload_type {
11-
ONION_V0_PAYLOAD = 0,
12-
ONION_TLV_PAYLOAD = 1,
13-
};
14-
1511
struct onion_payload {
1612
enum onion_payload_type type;
1713
/* Is this the final hop? */

common/sphinx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ struct route_step *process_onionpacket(
684684
size_t legacy_max = 32;
685685
u8 *onwire_tlv;
686686

687+
step->type = ONION_V0_PAYLOAD;
687688
legacy->amt_to_forward = tal(legacy, u64);
688689
legacy->outgoing_cltv_value = tal(legacy, u32);
689690
legacy->short_channel_id = tal(legacy, struct short_channel_id);
@@ -718,6 +719,7 @@ struct route_step *process_onionpacket(
718719
payload_size = 32;
719720
fromwire_pad(&cursor, &max, payload_size);
720721
} else {
722+
step->type = ONION_TLV_PAYLOAD;
721723
/* FIXME: raw_payload *includes* the length, which is redundant and
722724
* means we can't just ust fromwire_tal_arrn. */
723725
fromwire_pad(&cursor, &max, payload_size);

common/sphinx.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ struct sphinx_hop {
5959
const u8 *raw_payload;
6060
};
6161

62+
enum onion_payload_type {
63+
ONION_V0_PAYLOAD = 0,
64+
ONION_TLV_PAYLOAD = 1,
65+
};
66+
6267
struct route_step {
68+
enum onion_payload_type type;
6369
enum route_next_case nextcase;
6470
struct onionpacket *next;
6571
u8 *raw_payload;

0 commit comments

Comments
 (0)