From 75c382fe163df8f8b7feb7245922b1b83835cf30 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 8 Nov 2022 11:41:44 +1030 Subject: [PATCH] lightningd: --dev-onion-reply-length option. Signed-off-by: Rusty Russell --- common/sphinx.c | 11 +++++++++-- common/sphinx.h | 3 +++ lightningd/options.c | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/common/sphinx.c b/common/sphinx.c index fff2a2d29..2fef1451f 100644 --- a/common/sphinx.c +++ b/common/sphinx.c @@ -679,12 +679,19 @@ struct route_step *process_onionpacket( return step; } +#if DEVELOPER +unsigned dev_onion_reply_length = ONION_REPLY_SIZE; +#define OUR_ONION_REPLY_SIZE dev_onion_reply_length +#else +#define OUR_ONION_REPLY_SIZE ONION_REPLY_SIZE +#endif + struct onionreply *create_onionreply(const tal_t *ctx, const struct secret *shared_secret, const u8 *failure_msg) { size_t msglen = tal_count(failure_msg); - size_t padlen = ONION_REPLY_SIZE - msglen; + size_t padlen = OUR_ONION_REPLY_SIZE - msglen; struct onionreply *reply = tal(ctx, struct onionreply); u8 *payload = tal_arr(ctx, u8, 0); struct secret key; @@ -716,7 +723,7 @@ struct onionreply *create_onionreply(const tal_t *ctx, * - Note: this value is 118 bytes longer than the longest * currently-defined message. */ - assert(tal_count(payload) == ONION_REPLY_SIZE + 4); + assert(tal_count(payload) == OUR_ONION_REPLY_SIZE + 4); /* BOLT #4: * diff --git a/common/sphinx.h b/common/sphinx.h index 6ba537cf3..9b80c29b3 100644 --- a/common/sphinx.h +++ b/common/sphinx.h @@ -267,6 +267,9 @@ sphinx_compressed_onion_deserialize(const tal_t *ctx, const u8 *src); #if DEVELOPER /* Override to force us to reject valid onion packets */ extern bool dev_fail_process_onionpacket; + +/* Override to set custom onion error lengths. */ +extern unsigned dev_onion_reply_length; #endif #endif /* LIGHTNING_COMMON_SPHINX_H */ diff --git a/lightningd/options.c b/lightningd/options.c index 91f443643..07504bda9 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -752,6 +752,11 @@ static void dev_register_opts(struct lightningd *ld) opt_register_noarg("--dev-no-ping-timer", opt_set_bool, &ld->dev_no_ping_timer, "Don't hang up if we don't get a ping response"); + opt_register_arg("--dev-onion-reply-length", + opt_set_uintval, + opt_show_uintval, + &dev_onion_reply_length, + "Send onion errors of custom length"); } #endif /* DEVELOPER */