Skip to content

Commit f26b140

Browse files
rustyrussellendothermicdev
authored andcommitted
common: re-add legacy v0 hop generation to Sphinx for testing.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 1d4783a commit f26b140

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

common/sphinx.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "config.h"
22
#include <assert.h>
33

4+
#include <ccan/array_size/array_size.h>
45
#include <ccan/mem/mem.h>
56
#include <common/onion_decode.h>
67
#include <common/onionreply.h>
@@ -122,6 +123,33 @@ bool sphinx_add_hop_has_length(struct sphinx_path *path, const struct pubkey *pu
122123
return true;
123124
}
124125

126+
static u8 *make_v0_hop(const tal_t *ctx,
127+
const struct short_channel_id *scid,
128+
struct amount_msat forward, u32 outgoing_cltv)
129+
{
130+
const u8 padding[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
132+
/* Prepend 0 byte for realm */
133+
u8 *buf = tal_arrz(ctx, u8, 1);
134+
towire_short_channel_id(&buf, *scid);
135+
towire_amount_msat(&buf, forward);
136+
towire_u32(&buf, outgoing_cltv);
137+
towire(&buf, padding, ARRAY_SIZE(padding));
138+
assert(tal_bytelen(buf) == 1 + 32);
139+
return buf;
140+
}
141+
142+
void sphinx_add_v0_hop(struct sphinx_path *path, const struct pubkey *pubkey,
143+
const struct short_channel_id *scid,
144+
struct amount_msat forward, u32 outgoing_cltv)
145+
{
146+
struct sphinx_hop sp;
147+
148+
sp.raw_payload = make_v0_hop(path, scid, forward, outgoing_cltv);
149+
sp.pubkey = *pubkey;
150+
tal_arr_expand(&path->hops, sp);
151+
}
152+
125153
void sphinx_add_hop(struct sphinx_path *path, const struct pubkey *pubkey,
126154
const u8 *payload TAKES)
127155
{

common/sphinx.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ bool sphinx_add_hop_has_length(struct sphinx_path *path, const struct pubkey *pu
216216
void sphinx_add_hop(struct sphinx_path *path, const struct pubkey *pubkey,
217217
const u8 *payload TAKES);
218218

219+
/**
220+
* Do not use, function is cursed.
221+
*/
222+
void sphinx_add_v0_hop(struct sphinx_path *path, const struct pubkey *pubkey,
223+
const struct short_channel_id *scid,
224+
struct amount_msat forward, u32 outgoing_cltv);
225+
219226
/**
220227
* Compute the size of the serialized payloads.
221228
*/

common/test/run-sphinx-xor_cipher_stream.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ void subkey_from_hmac(const char *prefix UNNEEDED,
111111
/* Generated stub for towire */
112112
void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
113113
{ fprintf(stderr, "towire called!\n"); abort(); }
114+
/* Generated stub for towire_amount_msat */
115+
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
116+
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }
114117
/* Generated stub for towire_bigsize */
115118
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
116119
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }

wallet/test/run-wallet.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,11 @@ u8 *serialize_onionpacket(
932932
bool sphinx_add_hop_has_length(struct sphinx_path *path UNNEEDED, const struct pubkey *pubkey UNNEEDED,
933933
const u8 *payload TAKES UNNEEDED)
934934
{ fprintf(stderr, "sphinx_add_hop_has_length called!\n"); abort(); }
935+
/* Generated stub for sphinx_add_v0_hop */
936+
void sphinx_add_v0_hop(struct sphinx_path *path UNNEEDED, const struct pubkey *pubkey UNNEEDED,
937+
const struct short_channel_id *scid UNNEEDED,
938+
struct amount_msat forward UNNEEDED, u32 outgoing_cltv UNNEEDED)
939+
{ fprintf(stderr, "sphinx_add_v0_hop called!\n"); abort(); }
935940
/* Generated stub for sphinx_path_new */
936941
struct sphinx_path *sphinx_path_new(const tal_t *ctx UNNEEDED,
937942
const u8 *associated_data UNNEEDED)

0 commit comments

Comments
 (0)