Skip to content

Commit 8281008

Browse files
committed
lightningd: annotate configuration settings which contain JSON literals.
We have hacky code to show some listconfigs values as literals; instead explicitly encode the types. Signed-off-by: Rusty Russell <[email protected]>
1 parent 86abb4c commit 8281008

File tree

4 files changed

+97
-69
lines changed

4 files changed

+97
-69
lines changed

common/configdir.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,11 @@ struct configvar **initial_config_opts(const tal_t *ctx,
347347
opt_register_version();
348348

349349
/* For convenience, we set deprecated_apis and rpc_filename now, too */
350-
opt_register_early_arg("--allow-deprecated-apis",
351-
opt_set_bool_arg, opt_show_bool,
352-
&deprecated_apis,
353-
"Enable deprecated options, JSONRPC commands, fields, etc.");
350+
clnopt_witharg("--allow-deprecated-apis",
351+
OPT_EARLY|OPT_SHOWBOOL,
352+
opt_set_bool_arg, opt_show_bool,
353+
&deprecated_apis,
354+
"Enable deprecated options, JSONRPC commands, fields, etc.");
354355

355356
/* Allow them to override rpc-file too. */
356357
*rpc_filename = default_rpcfile(ctx);

common/configvar.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ struct configvar {
5252
#define OPT_DEV (1 << (OPT_USER_START+1))
5353
/* Doesn't return, so don't show in listconfigs */
5454
#define OPT_EXITS (1 << (OPT_USER_START+2))
55+
/* listconfigs should treat as a literal number */
56+
#define OPT_SHOWINT (1 << (OPT_USER_START+3))
57+
/* listconfigs should treat as a literal msat number */
58+
#define OPT_SHOWMSATS (1 << (OPT_USER_START+4))
59+
/* listconfigs should treat as a literal boolean `true` or `false` */
60+
#define OPT_SHOWBOOL (1 << (OPT_USER_START+5))
5561

5662
/* Use this instead of opt_register_*_arg if you want OPT_* from above */
5763
#define clnopt_witharg(names, type, cb, show, arg, desc) \

lightningd/log.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,10 @@ void opt_register_logging(struct lightningd *ld)
736736
opt_register_early_arg("--log-level",
737737
opt_log_level, show_log_level, ld->log,
738738
"log level (io, debug, info, unusual, broken) [:prefix]");
739-
opt_register_early_arg("--log-timestamps",
740-
opt_set_bool_arg, opt_show_bool, &ld->log->lr->print_timestamps,
741-
"prefix log messages with timestamp");
739+
clnopt_witharg("--log-timestamps", OPT_EARLY|OPT_SHOWBOOL,
740+
opt_set_bool_arg, opt_show_bool,
741+
&ld->log->lr->print_timestamps,
742+
"prefix log messages with timestamp");
742743
opt_register_early_arg("--log-prefix", arg_log_prefix, show_log_prefix,
743744
ld->log_book,
744745
"log prefix");

lightningd/options.c

Lines changed: 82 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static void dev_register_opts(struct lightningd *ld)
792792
opt_set_bool,
793793
&ld->dev_allow_localhost,
794794
"Announce and allow announcments for localhost address");
795-
clnopt_witharg("--dev-bitcoind-poll", OPT_DEV,
795+
clnopt_witharg("--dev-bitcoind-poll", OPT_DEV|OPT_SHOWINT,
796796
opt_set_u32, opt_show_u32,
797797
&ld->topology->poll_seconds,
798798
"Time between polling for new transactions");
@@ -804,7 +804,7 @@ static void dev_register_opts(struct lightningd *ld)
804804
opt_set_bool,
805805
&ld->dev_fast_gossip_prune,
806806
"Make gossip pruning 30 seconds");
807-
clnopt_witharg("--dev-gossip-time", OPT_DEV,
807+
clnopt_witharg("--dev-gossip-time", OPT_DEV|OPT_SHOWINT,
808808
opt_set_u32, opt_show_u32,
809809
&ld->dev_gossip_time,
810810
"UNIX time to override gossipd to use.");
@@ -817,7 +817,8 @@ static void dev_register_opts(struct lightningd *ld)
817817
clnopt_witharg("--dev-force-channel-secrets", OPT_DEV,
818818
opt_force_channel_secrets, NULL, ld,
819819
"Force HSM to use these for all per-channel secrets");
820-
clnopt_witharg("--dev-max-funding-unconfirmed-blocks", OPT_DEV,
820+
clnopt_witharg("--dev-max-funding-unconfirmed-blocks",
821+
OPT_DEV|OPT_SHOWINT,
821822
opt_set_u32, opt_show_u32,
822823
&ld->dev_max_funding_unconfirmed,
823824
"Maximum number of blocks we wait for a channel "
@@ -841,28 +842,28 @@ static void dev_register_opts(struct lightningd *ld)
841842
clnopt_witharg("--dev-force-features", OPT_DEV,
842843
opt_force_featureset, NULL, ld,
843844
"Force the init/globalinit/node_announce/channel/bolt11/ features, each comma-separated bitnumbers OR a single +/-<bitnumber>");
844-
clnopt_witharg("--dev-timeout-secs", OPT_DEV,
845+
clnopt_witharg("--dev-timeout-secs", OPT_DEV|OPT_SHOWINT,
845846
opt_set_u32, opt_show_u32,
846847
&ld->config.connection_timeout_secs,
847848
"Seconds to timeout if we don't receive INIT from peer");
848849
clnopt_noarg("--dev-no-modern-onion", OPT_DEV,
849850
opt_set_bool,
850851
&ld->dev_ignore_modern_onion,
851852
"Ignore modern onion messages");
852-
clnopt_witharg("--dev-disable-commit-after", OPT_DEV,
853+
clnopt_witharg("--dev-disable-commit-after", OPT_DEV|OPT_SHOWINT,
853854
opt_set_intval, opt_show_intval,
854855
&ld->dev_disable_commit,
855856
"Disable commit timer after this many commits");
856857
clnopt_noarg("--dev-no-ping-timer", OPT_DEV,
857858
opt_set_bool,
858859
&ld->dev_no_ping_timer,
859860
"Don't hang up if we don't get a ping response");
860-
clnopt_witharg("--dev-onion-reply-length", OPT_DEV,
861+
clnopt_witharg("--dev-onion-reply-length", OPT_DEV|OPT_SHOWINT,
861862
opt_set_uintval,
862863
opt_show_uintval,
863864
&dev_onion_reply_length,
864865
"Send onion errors of custom length");
865-
clnopt_witharg("--dev-max-fee-multiplier", OPT_DEV,
866+
clnopt_witharg("--dev-max-fee-multiplier", OPT_DEV|OPT_SHOWINT,
866867
opt_set_uintval,
867868
opt_show_uintval,
868869
&ld->config.max_fee_multiplier,
@@ -871,7 +872,7 @@ static void dev_register_opts(struct lightningd *ld)
871872
"own. Small values will cause channels to be"
872873
" closed more often due to fee fluctuations,"
873874
" large values may result in large fees.");
874-
clnopt_witharg("--dev-allowdustreserve", OPT_DEV,
875+
clnopt_witharg("--dev-allowdustreserve", OPT_DEV|OPT_SHOWBOOL,
875876
opt_set_bool_arg, opt_show_bool,
876877
&ld->config.allowdustreserve,
877878
"If true, we allow the `fundchannel` RPC command and the `openchannel` plugin hook to set a reserve that is below the dust limit.");
@@ -1239,9 +1240,9 @@ static void register_opts(struct lightningd *ld)
12391240
"Add an important plugin to be run (can be used multiple times). Die if the plugin dies.");
12401241

12411242
/* Early, as it suppresses DNS lookups from cmdline too. */
1242-
opt_register_early_arg("--always-use-proxy",
1243-
opt_set_bool_arg, opt_show_bool,
1244-
&ld->always_use_proxy, "Use the proxy always");
1243+
clnopt_witharg("--always-use-proxy", OPT_EARLY|OPT_SHOWBOOL,
1244+
opt_set_bool_arg, opt_show_bool,
1245+
&ld->always_use_proxy, "Use the proxy always");
12451246

12461247
/* This immediately makes is a daemon. */
12471248
opt_register_early_noarg("--daemon", opt_start_daemon, ld,
@@ -1280,9 +1281,10 @@ static void register_opts(struct lightningd *ld)
12801281
opt_set_quiesce, ld,
12811282
"experimental: Advertise ability to quiesce"
12821283
" channels.");
1283-
opt_register_early_arg("--announce-addr-dns",
1284-
opt_set_announce_dns, NULL,
1285-
ld, opt_hidden);
1284+
clnopt_witharg("--announce-addr-dns", OPT_EARLY|OPT_SHOWBOOL,
1285+
opt_set_bool_arg, opt_show_bool,
1286+
&ld->announce_dns,
1287+
opt_hidden);
12861288

12871289
clnopt_noarg("--help|-h", OPT_EXITS,
12881290
opt_lightningd_usage, ld, "Print this message.");
@@ -1295,57 +1297,61 @@ static void register_opts(struct lightningd *ld)
12951297
&ld->pidfile,
12961298
"Specify pid file");
12971299

1298-
opt_register_arg("--ignore-fee-limits", opt_set_bool_arg, opt_show_bool,
1299-
&ld->config.ignore_fee_limits,
1300-
"(DANGEROUS) allow peer to set any feerate");
1301-
opt_register_arg("--watchtime-blocks", opt_set_u32, opt_show_u32,
1300+
clnopt_witharg("--ignore-fee-limits", OPT_SHOWBOOL,
1301+
opt_set_bool_arg, opt_show_bool,
1302+
&ld->config.ignore_fee_limits,
1303+
"(DANGEROUS) allow peer to set any feerate");
1304+
clnopt_witharg("--watchtime-blocks", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13021305
&ld->config.locktime_blocks,
13031306
"Blocks before peer can unilaterally spend funds");
1304-
opt_register_arg("--max-locktime-blocks", opt_set_u32, opt_show_u32,
1307+
clnopt_witharg("--max-locktime-blocks", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13051308
&ld->config.locktime_max,
13061309
"Maximum blocks funds may be locked for");
1307-
opt_register_arg("--funding-confirms", opt_set_u32, opt_show_u32,
1310+
clnopt_witharg("--funding-confirms", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13081311
&ld->config.anchor_confirms,
13091312
"Confirmations required for funding transaction");
1310-
opt_register_arg("--require-confirmed-inputs", opt_set_bool_arg, opt_show_bool,
1311-
&ld->config.require_confirmed_inputs,
1312-
"Confirmations required for inputs to funding transaction (v2 opens only)");
1313-
opt_register_arg("--cltv-delta", opt_set_u32, opt_show_u32,
1313+
clnopt_witharg("--require-confirmed-inputs", OPT_SHOWBOOL,
1314+
opt_set_bool_arg, opt_show_bool,
1315+
&ld->config.require_confirmed_inputs,
1316+
"Confirmations required for inputs to funding transaction (v2 opens only)");
1317+
clnopt_witharg("--cltv-delta", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13141318
&ld->config.cltv_expiry_delta,
13151319
"Number of blocks for cltv_expiry_delta");
1316-
opt_register_arg("--cltv-final", opt_set_u32, opt_show_u32,
1320+
clnopt_witharg("--cltv-final", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13171321
&ld->config.cltv_final,
13181322
"Number of blocks for final cltv_expiry");
1319-
opt_register_arg("--commit-time=<millseconds>",
1323+
clnopt_witharg("--commit-time=<millseconds>", OPT_SHOWINT,
13201324
opt_set_u32, opt_show_u32,
13211325
&ld->config.commit_time_ms,
13221326
"Time after changes before sending out COMMIT");
1323-
opt_register_arg("--fee-base", opt_set_u32, opt_show_u32,
1327+
clnopt_witharg("--fee-base", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13241328
&ld->config.fee_base,
13251329
"Millisatoshi minimum to charge for HTLC");
1326-
opt_register_arg("--rescan", opt_set_s32, opt_show_s32,
1330+
clnopt_witharg("--rescan", OPT_SHOWINT, opt_set_s32, opt_show_s32,
13271331
&ld->config.rescan,
13281332
"Number of blocks to rescan from the current head, or "
13291333
"absolute blockheight if negative");
1330-
opt_register_arg("--fee-per-satoshi", opt_set_u32, opt_show_u32,
1334+
clnopt_witharg("--fee-per-satoshi", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13311335
&ld->config.fee_per_satoshi,
13321336
"Microsatoshi fee for every satoshi in HTLC");
1333-
opt_register_arg("--htlc-minimum-msat", opt_set_msat, opt_show_msat,
1334-
&ld->config.htlc_minimum_msat,
1335-
"The default minimal value an HTLC must carry in order to be forwardable for new channels");
1336-
opt_register_arg("--htlc-maximum-msat", opt_set_msat, opt_show_msat,
1337-
&ld->config.htlc_maximum_msat,
1338-
"The default maximal value an HTLC must carry in order to be forwardable for new channel");
1339-
opt_register_arg("--max-concurrent-htlcs", opt_set_u32, opt_show_u32,
1337+
clnopt_witharg("--htlc-minimum-msat", OPT_SHOWMSATS,
1338+
opt_set_msat, opt_show_msat,
1339+
&ld->config.htlc_minimum_msat,
1340+
"The default minimal value an HTLC must carry in order to be forwardable for new channels");
1341+
clnopt_witharg("--htlc-maximum-msat", OPT_SHOWMSATS,
1342+
opt_set_msat, opt_show_msat,
1343+
&ld->config.htlc_maximum_msat,
1344+
"The default maximal value an HTLC must carry in order to be forwardable for new channel");
1345+
clnopt_witharg("--max-concurrent-htlcs", OPT_SHOWINT, opt_set_u32, opt_show_u32,
13401346
&ld->config.max_concurrent_htlcs,
13411347
"Number of HTLCs one channel can handle concurrently. Should be between 1 and 483");
1342-
opt_register_arg("--max-dust-htlc-exposure-msat", opt_set_msat,
1343-
opt_show_msat, &ld->config.max_dust_htlc_exposure_msat,
1344-
"Max HTLC amount that can be trimmed");
1345-
opt_register_arg("--min-capacity-sat", opt_set_u64, opt_show_u64,
1348+
clnopt_witharg("--max-dust-htlc-exposure-msat", OPT_SHOWMSATS,
1349+
opt_set_msat,
1350+
opt_show_msat, &ld->config.max_dust_htlc_exposure_msat,
1351+
"Max HTLC amount that can be trimmed");
1352+
clnopt_witharg("--min-capacity-sat", OPT_SHOWINT, opt_set_u64, opt_show_u64,
13461353
&ld->config.min_capacity_sat,
13471354
"Minimum capacity in satoshis for accepting channels");
1348-
13491355
clnopt_witharg("--addr", OPT_MULTI, opt_add_addr, NULL,
13501356
ld,
13511357
"Set an IP address (v4 or v6) to listen on and announce to the network for incoming connections");
@@ -1360,15 +1366,16 @@ static void register_opts(struct lightningd *ld)
13601366
opt_register_arg("--announce-addr-discovered", opt_set_autobool_arg, opt_show_autobool,
13611367
&ld->config.ip_discovery,
13621368
"Explicitly turns IP discovery 'on' or 'off'.");
1363-
opt_register_arg("--announce-addr-discovered-port", opt_set_uintval,
1364-
opt_show_uintval, &ld->config.ip_discovery_port,
1365-
"Sets the public TCP port to use for announcing discovered IPs.");
1366-
1369+
clnopt_witharg("--announce-addr-discovered-port", OPT_SHOWINT,
1370+
opt_set_uintval,
1371+
opt_show_uintval, &ld->config.ip_discovery_port,
1372+
"Sets the public TCP port to use for announcing discovered IPs.");
13671373
opt_register_noarg("--offline", opt_set_offline, ld,
13681374
"Start in offline-mode (do not automatically reconnect and do not accept incoming connections)");
1369-
opt_register_arg("--autolisten", opt_set_bool_arg, opt_show_bool,
1370-
&ld->autolisten,
1371-
"If true, listen on default port and announce if it seems to be a public interface");
1375+
clnopt_witharg("--autolisten", OPT_SHOWBOOL,
1376+
opt_set_bool_arg, opt_show_bool,
1377+
&ld->autolisten,
1378+
"If true, listen on default port and announce if it seems to be a public interface");
13721379
opt_register_arg("--proxy", opt_add_proxy_addr, NULL,
13731380
ld,"Set a socks v5 proxy IP address and port");
13741381
opt_register_arg("--tor-service-password", opt_set_talstr, NULL,
@@ -1395,9 +1402,9 @@ static void register_opts(struct lightningd *ld)
13951402
opt_force_feerates, NULL, ld,
13961403
"Set testnet/regtest feerates in sats perkw, opening/mutual_close/unlateral_close/delayed_to_us/htlc_resolution/penalty: if fewer specified, last number applies to remainder");
13971404

1398-
opt_register_arg("--commit-fee",
1399-
opt_set_u64, opt_show_u64, &ld->config.commit_fee_percent,
1400-
"Percentage of fee to request for their commitment");
1405+
clnopt_witharg("--commit-fee", OPT_SHOWINT,
1406+
opt_set_u64, opt_show_u64, &ld->config.commit_fee_percent,
1407+
"Percentage of fee to request for their commitment");
14011408
clnopt_witharg("--subdaemon",
14021409
OPT_MULTI,
14031410
opt_subdaemon, NULL,
@@ -1410,16 +1417,16 @@ static void register_opts(struct lightningd *ld)
14101417
"--subdaemon=hsmd:remote_signer "
14111418
"would use a hypothetical remote signing subdaemon.");
14121419

1413-
opt_register_arg("--experimental-websocket-port",
1414-
opt_set_websocket_port, NULL,
1415-
ld, opt_hidden);
1420+
clnopt_witharg("--experimental-websocket-port", OPT_SHOWINT,
1421+
opt_set_websocket_port, NULL,
1422+
ld, opt_hidden);
14161423
opt_register_noarg("--experimental-upgrade-protocol",
14171424
opt_set_bool, &ld->experimental_upgrade_protocol,
14181425
"experimental: allow channel types to be upgraded on reconnect");
1419-
opt_register_arg("--database-upgrade",
1420-
opt_set_db_upgrade, NULL,
1421-
ld,
1422-
"Set to true to allow database upgrades even on non-final releases (WARNING: you won't be able to downgrade!)");
1426+
clnopt_witharg("--database-upgrade", OPT_SHOWBOOL,
1427+
opt_set_db_upgrade, NULL,
1428+
ld,
1429+
"Set to true to allow database upgrades even on non-final releases (WARNING: you won't be able to downgrade!)");
14231430
opt_register_logging(ld);
14241431
opt_register_version();
14251432

@@ -1698,6 +1705,14 @@ static void json_add_opt_subdaemons(struct json_stream *response,
16981705
strmap_iterate(alt_subdaemons, json_add_opt_alt_subdaemon, &args);
16991706
}
17001707

1708+
/* Canonicalize value they've given */
1709+
static bool canon_bool(const char *val)
1710+
{
1711+
bool b;
1712+
opt_set_bool_arg(val, &b);
1713+
return b;
1714+
}
1715+
17011716
static void add_config(struct lightningd *ld,
17021717
struct json_stream *response,
17031718
const struct opt_table *opt,
@@ -1788,12 +1803,17 @@ static void add_config(struct lightningd *ld,
17881803
if (!opt->show(buf, sizeof(buf) - sizeof("..."), opt->u.carg))
17891804
buf[0] = '\0';
17901805

1791-
if (streq(buf, "true") || streq(buf, "false")
1792-
|| (!streq(buf, "") && strspn(buf, "0123456789.") == strlen(buf))) {
1793-
/* Let pure numbers and true/false through as
1794-
* literals. */
1806+
if ((opt->type & OPT_SHOWINT)
1807+
|| (opt->type & OPT_SHOWMSATS)) {
1808+
if (streq(buf, "")
1809+
|| strspn(buf, "-0123456789.") != strlen(buf))
1810+
errx(1, "Bad literal for %s: %s", name0, buf);
17951811
json_add_primitive(response, name0, buf);
17961812
return;
1813+
} else if (opt->type & OPT_SHOWBOOL) {
1814+
/* We allow variants here. Json-ize */
1815+
json_add_bool(response, name0, canon_bool(buf));
1816+
return;
17971817
}
17981818
answer = buf;
17991819
} else if (opt->cb_arg == (void *)opt_set_talstr

0 commit comments

Comments
 (0)