sphinx: Return the error in parse_onionpacket

As suggested by @niftynei here: https://github.com/ElementsProject/lightning/pull/3260#discussion_r347543999

Suggested-by: Lisa Neigut <@niftynei>
Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
Christian Decker
2019-11-29 21:20:18 +01:00
parent e1b1f47c53
commit ff5f7b194f
7 changed files with 38 additions and 48 deletions

View File

@@ -103,21 +103,21 @@ static struct route_step *decode_with_privkey(const tal_t *ctx, const u8 *onion,
{
struct privkey seckey;
struct route_step *step;
struct onionpacket *packet;
struct onionpacket packet;
enum onion_type why_bad;
u8 shared_secret[32];
if (!hex_decode(hexprivkey, strlen(hexprivkey), &seckey, sizeof(seckey)))
errx(1, "Invalid private key hex '%s'", hexprivkey);
packet = parse_onionpacket(ctx, onion, TOTAL_PACKET_SIZE, &why_bad);
why_bad = parse_onionpacket(onion, TOTAL_PACKET_SIZE, &packet);
if (!packet)
if (why_bad != 0)
errx(1, "Error parsing message: %s", onion_type_name(why_bad));
if (!onion_shared_secret(shared_secret, packet, &seckey))
if (!onion_shared_secret(shared_secret, &packet, &seckey))
errx(1, "Error creating shared secret.");
step = process_onionpacket(ctx, packet, shared_secret, assocdata,
step = process_onionpacket(ctx, &packet, shared_secret, assocdata,
tal_bytelen(assocdata));
return step;