From 01411d70be0ffc9645caf85ba01aef51315ff8fa Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2022 19:52:09 +0930 Subject: [PATCH] common: enforce that msat fields are called "xxx_msat". Now we've fixed them all, make sure no new ones slip in! Signed-off-by: Rusty Russell --- common/json_helpers.c | 4 ++++ lightningd/options.c | 8 +++++++- plugins/libplugin-pay.c | 4 +++- plugins/test/run-route-overlong.c | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/common/json_helpers.c b/common/json_helpers.c index baa7d3918..3b1e210ce 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -402,6 +402,8 @@ void json_add_amount_msat_compat(struct json_stream *result, const char *msatfieldname) { json_add_u64(result, rawfieldname, msat.millisatoshis); /* Raw: low-level helper */ + if (!deprecated_apis) + assert(strends(msatfieldname, "_msat")); json_add_amount_msat_only(result, msatfieldname, msat); } @@ -409,6 +411,8 @@ void json_add_amount_msat_only(struct json_stream *result, const char *msatfieldname, struct amount_msat msat) { + if (!deprecated_apis) + assert(strends(msatfieldname, "_msat")); json_add_string(result, msatfieldname, type_to_string(tmpctx, struct amount_msat, &msat)); } diff --git a/lightningd/options.c b/lightningd/options.c index 6c22c4c5f..43be6bccc 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -1616,7 +1616,13 @@ static void add_config(struct lightningd *ld, /* FIXME: We actually treat it as if they specified * --plugin for each one, so ignore these */ } else if (opt->cb_arg == (void *)opt_set_msat) { - json_add_amount_msat_only(response, name0, ld->config.max_dust_htlc_exposure_msat); + /* We allow -msat not _msat here, unlike + * json_add_amount_msat_only */ + assert(strends(name0, "-msat")); + json_add_string(response, name0, + fmt_amount_msat(tmpctx, + *(struct amount_msat *) + opt->u.carg)); #if EXPERIMENTAL_FEATURES } else if (opt->cb_arg == (void *)opt_set_accept_extra_tlv_types) { /* TODO Actually print the option */ diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 24bb3fbb0..bd5faa2c0 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -1825,7 +1825,9 @@ static void payment_add_attempt(struct json_stream *s, const char *fieldname, st json_add_string(s, "failreason", p->failreason); json_add_u64(s, "partid", p->partid); - json_add_amount_msat_only(s, "amount", p->amount); + if (deprecated_apis) + json_add_amount_msat_only(s, "amount", p->amount); + json_add_amount_msat_only(s, "amount_msat", p->amount); if (p->parent != NULL) json_add_u64(s, "parent_partid", p->parent->partid); diff --git a/plugins/test/run-route-overlong.c b/plugins/test/run-route-overlong.c index 42271efcd..dd59da1cd 100644 --- a/plugins/test/run-route-overlong.c +++ b/plugins/test/run-route-overlong.c @@ -14,6 +14,8 @@ struct command_result *command_finished(struct command *cmd UNNEEDED, struct jso /* Generated stub for command_still_pending */ struct command_result *command_still_pending(struct command *cmd UNNEEDED) { fprintf(stderr, "command_still_pending called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for feature_offered */ bool feature_offered(const u8 *features UNNEEDED, size_t f UNNEEDED) { fprintf(stderr, "feature_offered called!\n"); abort(); }