Skip to content

Commit 1b252f3

Browse files
committed
config: replace accept-htlc-tlv-types with accept-htlc-tlv-type
We use multi-specifiable options elsewhere, this is just another. Otherwise you can't add, you can only set them all. Changelog-Added: Config: `accept-htlc-tlv-type` (replaces awkward-to-use `accept-htlc-tlv-types`) Changelog-Deprecated: Config: `accept-htlc-tlv-types` (use `accept-htlc-tlv-type` multiple times) Signed-off-by: Rusty Russell <[email protected]>
1 parent 0df9754 commit 1b252f3

File tree

7 files changed

+83
-59
lines changed

7 files changed

+83
-59
lines changed

common/json_parse.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -709,27 +709,6 @@ json_to_blinded_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
709709
return rpath;
710710
}
711711

712-
bool json_to_uintarr(const char *buffer, const jsmntok_t *tok, u64 **dest)
713-
{
714-
char *str = json_strdup(NULL, buffer, tok);
715-
char *endp, **elements = tal_strsplit(str, str, ",", STR_NO_EMPTY);
716-
unsigned long long l;
717-
u64 u;
718-
for (int i = 0; elements[i] != NULL; i++) {
719-
/* This is how the manpage says to do it. Yech. */
720-
errno = 0;
721-
l = strtoull(elements[i], &endp, 0);
722-
if (*endp || !str[0])
723-
return tal_fmt(NULL, "'%s' is not a number", elements[i]);
724-
u = l;
725-
if (errno || u != l)
726-
return tal_fmt(NULL, "'%s' is out of range", elements[i]);
727-
tal_arr_expand(dest, u);
728-
}
729-
tal_free(str);
730-
return NULL;
731-
}
732-
733712
bool
734713
json_tok_channel_id(const char *buffer, const jsmntok_t *tok,
735714
struct channel_id *cid)

common/json_parse.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
114114
bool json_to_coin_mvt_tag(const char *buffer, const jsmntok_t *tok,
115115
enum mvt_tag *tag);
116116

117-
/* Read a JSON value into an array of u64 */
118-
bool json_to_uintarr(const char *buffer, const jsmntok_t *tok, u64 **dest);
119-
120117
/* Extract reply path from this JSON */
121118
struct blinded_path *
122119
json_to_blinded_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);

doc/lightning-listconfigs.7.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ On success, an object is returned, containing:
323323
- **force-feerates** (string, optional): force-feerate configuration setting, if any
324324
- **subdaemon** (string, optional): `subdaemon` fields from config or cmdline if any (can be more than one)
325325
- **fetchinvoice-noconnect** (boolean, optional): `fetchinvoice-noconnect` fields from config or cmdline, or default
326-
- **accept-htlc-tlv-types** (string, optional): `accept-htlc-tlv-types` fields from config or cmdline, or not present
326+
- **accept-htlc-tlv-types** (string, optional): `accept-htlc-tlv-types` field from config or cmdline, or not present **deprecated, removal in v24.05**
327327
- **tor-service-password** (string, optional): `tor-service-password` field from config or cmdline, if any
328328
- **dev-allowdustreserve** (boolean, optional): Whether we allow setting dust reserves
329329
- **announce-addr-dns** (boolean, optional): Whether we put DNS entries into node\_announcement **deprecated, removal in v24.05** *(added v22.11.1)*
@@ -446,4 +446,4 @@ RESOURCES
446446

447447
Main web site: <https://github.com/ElementsProject/lightning>
448448

449-
[comment]: # ( SHA256STAMP:c847cb106f78f616b3adfe506ef499c9228f3966a44e6164b9cf49e1cf67d417)
449+
[comment]: # ( SHA256STAMP:a3d32b74eb78b014e39ea85c19b3366e0468087ae44da633e9d5a194d2fe11b6)

doc/schemas/listconfigs.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,9 @@
15921592
"description": "`fetchinvoice-noconnect` fields from config or cmdline, or default"
15931593
},
15941594
"accept-htlc-tlv-types": {
1595+
"deprecated": "v23.08",
15951596
"type": "string",
1596-
"description": "`accept-htlc-tlv-types` fields from config or cmdline, or not present"
1597+
"description": "`accept-htlc-tlv-types` field from config or cmdline, or not present"
15971598
},
15981599
"tor-service-password": {
15991600
"type": "string",

lightningd/options.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,28 @@ static char *fmt_force_feerates(const tal_t *ctx, const u32 *force_feerates)
190190
return ret;
191191
}
192192

193+
static char *opt_add_accept_htlc_tlv(const char *arg,
194+
u64 **accept_extra_tlv_types)
195+
{
196+
size_t n = tal_count(*accept_extra_tlv_types);
197+
198+
tal_resize(accept_extra_tlv_types, n+1);
199+
return opt_set_u64(arg, &(*accept_extra_tlv_types)[n]);
200+
}
201+
193202
static char *opt_set_accept_extra_tlv_types(const char *arg,
194203
struct lightningd *ld)
195204
{
196-
char *endp, **elements = tal_strsplit(NULL, arg, ",", STR_NO_EMPTY);
197-
unsigned long long l;
198-
u64 u;
205+
char *ret, **elements = tal_strsplit(tmpctx, arg, ",", STR_NO_EMPTY);
206+
207+
if (!deprecated_apis)
208+
return "Please use --accept-htlc-tlv-type multiple times";
199209
for (int i = 0; elements[i] != NULL; i++) {
200-
/* This is how the manpage says to do it. Yech. */
201-
errno = 0;
202-
l = strtoull(elements[i], &endp, 0);
203-
if (*endp || !arg[0])
204-
return tal_fmt(NULL, "'%s' is not a number", arg);
205-
u = l;
206-
if (errno || u != l)
207-
return tal_fmt(NULL, "'%s' is out of range", arg);
208-
tal_arr_expand(&ld->accept_extra_tlv_types, u);
210+
ret = opt_add_accept_htlc_tlv(elements[i],
211+
&ld->accept_extra_tlv_types);
212+
if (ret)
213+
return ret;
209214
}
210-
211-
tal_free(elements);
212215
return NULL;
213216
}
214217

@@ -1385,6 +1388,10 @@ static void register_opts(struct lightningd *ld)
13851388
opt_register_arg("--accept-htlc-tlv-types",
13861389
opt_set_accept_extra_tlv_types, NULL, ld,
13871390
"Comma separated list of extra HTLC TLV types to accept.");
1391+
clnopt_witharg("--accept-htlc-tlv-type", OPT_MULTI|OPT_SHOWINT,
1392+
opt_add_accept_htlc_tlv, NULL,
1393+
&ld->accept_extra_tlv_types,
1394+
"HTLC TLV type to accept (can be used multiple times)");
13881395

13891396
opt_register_early_noarg("--disable-dns", opt_set_invbool, &ld->config.use_dns,
13901397
"Disable DNS lookups of peers");
@@ -1887,6 +1894,8 @@ static void add_config_deprecated(struct lightningd *ld,
18871894
|| opt->cb_arg == (void *)plugin_opt_flag_set) {
18881895
/* FIXME: We actually treat it as if they specified
18891896
* --plugin for each one, so ignore these */
1897+
} else if (opt->cb_arg == (void *)opt_add_accept_htlc_tlv) {
1898+
/* We ignore this: it's printed below: */
18901899
} else if (opt->cb_arg == (void *)opt_set_accept_extra_tlv_types) {
18911900
for (size_t i = 0;
18921901
i < tal_count(ld->accept_extra_tlv_types);
@@ -1989,6 +1998,7 @@ static const char *get_opt_val(const struct opt_table *ot,
19891998
|| ot->cb_arg == (void *)opt_subdaemon
19901999
|| ot->cb_arg == (void *)opt_set_db_upgrade
19912000
|| ot->cb_arg == (void *)arg_log_to_file
2001+
|| ot->cb_arg == (void *)opt_add_accept_htlc_tlv
19922002
#if DEVELOPER
19932003
|| ot->cb_arg == (void *)opt_subd_dev_disconnect
19942004
|| ot->cb_arg == (void *)opt_force_featureset

plugins/keysend.c

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <common/json_stream.h>
99
#include <common/memleak.h>
1010
#include <common/type_to_string.h>
11+
#include <errno.h>
1112
#include <plugins/libplugin-pay.h>
1213
#include <sodium.h>
1314

@@ -161,29 +162,65 @@ REGISTER_PAYMENT_MODIFIER(check_preapprovekeysend, void *, NULL,
161162
* End of check_preapprovekeysend modifier
162163
*****************************************************************************/
163164

165+
/* Deprecated: comma-separated string containing integers */
166+
static bool json_accumulate_uintarr(const char *buffer,
167+
const jsmntok_t *tok,
168+
u64 **dest)
169+
{
170+
char *str = json_strdup(NULL, buffer, tok);
171+
char *endp, **elements = tal_strsplit(str, str, ",", STR_NO_EMPTY);
172+
unsigned long long l;
173+
u64 u;
174+
for (int i = 0; elements[i] != NULL; i++) {
175+
/* This is how the manpage says to do it. Yech. */
176+
errno = 0;
177+
l = strtoull(elements[i], &endp, 0);
178+
if (*endp || !str[0])
179+
return false;
180+
u = l;
181+
if (errno || u != l)
182+
return false;
183+
tal_arr_expand(dest, u);
184+
}
185+
tal_free(str);
186+
return NULL;
187+
}
188+
189+
/* values_int is a JSON array of u64s */
190+
static bool jsonarr_accumulate_u64(const char *buffer,
191+
const jsmntok_t *tok,
192+
u64 **dest)
193+
{
194+
const jsmntok_t *t;
195+
size_t i, n;
196+
197+
if (tok->type != JSMN_ARRAY)
198+
return false;
199+
n = tal_count(*dest);
200+
tal_resize(dest, n + tok->size);
201+
json_for_each_arr(i, t, tok) {
202+
if (!json_to_u64(buffer, t, &(*dest)[n + i]))
203+
return false;
204+
}
205+
return true;
206+
}
207+
164208
static const char *init(struct plugin *p, const char *buf UNUSED,
165209
const jsmntok_t *config UNUSED)
166210
{
167-
const jsmntok_t *maxdelay, *extratlvs, *ctok;
168-
const char *cbuf;
169-
170211
rpc_scan(p, "getinfo", take(json_out_obj(NULL, NULL, NULL)), "{id:%}",
171212
JSON_SCAN(json_to_node_id, &my_id));
172213

173-
ctok =
174-
jsonrpc_request_sync(tmpctx, p, "listconfigs",
175-
take(json_out_obj(NULL, NULL, NULL)), &cbuf);
176-
/* `accept-htlc-tlv-types` may be missing if not set in the
177-
* config */
178-
maxdelay = json_get_member(cbuf, ctok, "max-locktime-blocks");
179-
extratlvs = json_get_member(cbuf, ctok, "accept-htlc-tlv-types");
180214
accepted_extra_tlvs = notleak(tal_arr(NULL, u64, 0));
181-
182-
assert(maxdelay != NULL);
183-
json_to_number(cbuf, maxdelay, &maxdelay_default);
184-
185-
if (extratlvs != NULL)
186-
json_to_uintarr(cbuf, extratlvs, &accepted_extra_tlvs);
215+
/* accept-htlc-tlv-types deprecated in v23.08, but still grab it! */
216+
rpc_scan(p, "listconfigs", take(json_out_obj(NULL, NULL, NULL)),
217+
"{configs:{"
218+
"max-locktime-blocks:{value_int:%},"
219+
"accept-htlc-tlv-types?:{value_str:%},"
220+
"accept-htlc-tlv-type:{values_int:%}}}",
221+
JSON_SCAN(json_to_u32, &maxdelay_default),
222+
JSON_SCAN(json_accumulate_uintarr, &accepted_extra_tlvs),
223+
JSON_SCAN(jsonarr_accumulate_u64, &accepted_extra_tlvs));
187224

188225
return NULL;
189226
}

tests/test_pay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,7 +3546,7 @@ def test_keysend_strip_tlvs(node_factory):
35463546
opts=[
35473547
{
35483548
# Not needed, just for listconfigs test.
3549-
'accept-htlc-tlv-types': '133773310,99990',
3549+
'accept-htlc-tlv-type': [133773310, 99990],
35503550
"plugin": os.path.join(os.path.dirname(__file__), "plugins/sphinx-receiver.py"),
35513551
},
35523552
{
@@ -3556,7 +3556,7 @@ def test_keysend_strip_tlvs(node_factory):
35563556
)
35573557

35583558
# Make sure listconfigs works here
3559-
assert l1.rpc.listconfigs()['accept-htlc-tlv-types'] == '133773310,99990'
3559+
assert l1.rpc.listconfigs('accept-htlc-tlv-type')['configs']['accept-htlc-tlv-type']['values_int'] == [133773310, 99990]
35603560

35613561
# l1 is configured to accept, so l2 should still filter them out
35623562
l1.rpc.keysend(l2.info['id'], amt, extratlvs={133773310: 'FEEDC0DE'})

0 commit comments

Comments
 (0)