Skip to content

Commit b68acb8

Browse files
cdeckerrustyrussell
authored andcommitted
opts: Add option to register extra TLV types to accept
Incoming HTLCs are rejected by the HTLC logic if the payload contains an even type that `lightningd` doesn't recognize. This is to prevent us from accidentally accepting a payment that has extra semantics attached (for example if we get a keysend payment and don't know what to do with the TLV field containing the message we should reject it, otherwise the overall semantics of the message delivery fail).
1 parent 84190af commit b68acb8

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

lightningd/lightningd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
233233
* so set it to NULL explicitly now. */
234234
ld->wallet = NULL;
235235

236+
/*~ Behavioral options */
237+
ld->accept_extra_tlv_types = tal_arr(ld, u64, 0);
238+
236239
/*~ In the next step we will initialize the plugins. This will
237240
* also populate the JSON-RPC with passthrough methods, hence
238241
* lightningd needs to have something to put those in. This

lightningd/lightningd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ struct lightningd {
278278

279279
/* Should we re-exec ourselves instead of just exiting? */
280280
bool try_reexec;
281+
282+
/* Array of (even) TLV types that we should allow. This is required
283+
* since we otherwise would outright reject them. */
284+
u64 *accept_extra_tlv_types;
281285
};
282286

283287
/* Turning this on allows a tal allocation to return NULL, rather than aborting.

lightningd/options.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ static char *opt_set_mode(const char *arg, mode_t *m)
131131
return NULL;
132132
}
133133

134+
#if EXPERIMENTAL_FEATURES
135+
static char *opt_set_accept_extra_tlv_types(const char *arg,
136+
struct lightningd *ld)
137+
{
138+
char *endp, **elements = tal_strsplit(NULL, arg, ",", STR_NO_EMPTY);;
139+
unsigned long long l;
140+
u64 u;
141+
for (int i = 0; elements[i] != NULL; i++) {
142+
/* This is how the manpage says to do it. Yech. */
143+
errno = 0;
144+
l = strtoull(elements[i], &endp, 0);
145+
if (*endp || !arg[0])
146+
return tal_fmt(NULL, "'%s' is not a number", arg);
147+
u = l;
148+
if (errno || u != l)
149+
return tal_fmt(NULL, "'%s' is out of range", arg);
150+
tal_arr_expand(&ld->accept_extra_tlv_types, u);
151+
}
152+
153+
tal_free(elements);
154+
return NULL;
155+
}
156+
#endif
157+
134158
static char *opt_add_addr_withtype(const char *arg,
135159
struct lightningd *ld,
136160
enum addr_listen_announce ala,
@@ -957,6 +981,12 @@ static void register_opts(struct lightningd *ld)
957981
&ld->tor_service_password,
958982
"Set a Tor hidden service password");
959983

984+
#if EXPERIMENTAL_FEATURES
985+
opt_register_arg("--experimental-accept-extra-tlv-types",
986+
opt_set_accept_extra_tlv_types, NULL, ld,
987+
"Comma separated list of extra TLV types to accept.");
988+
#endif
989+
960990
opt_register_noarg("--disable-dns", opt_set_invbool, &ld->config.use_dns,
961991
"Disable DNS lookups of peers");
962992

@@ -1401,6 +1431,10 @@ static void add_config(struct lightningd *ld,
14011431
|| opt->cb_arg == (void *)plugin_opt_flag_set) {
14021432
/* FIXME: We actually treat it as if they specified
14031433
* --plugin for each one, so ignore these */
1434+
#if EXPERIMENTAL_FEATURES
1435+
} else if (opt->cb_arg == (void *)opt_set_accept_extra_tlv_types) {
1436+
#endif
1437+
/* TODO Actually print the option */
14041438
} else {
14051439
/* Insert more decodes here! */
14061440
abort();

0 commit comments

Comments
 (0)