Skip to content

Commit 70aee52

Browse files
rustyrussellendothermicdev
authored andcommitted
libplugin: don't spew datastore errors to LOG_DEBUG.
People get upset, especially as our "not found" error can be a bit hard to read! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> See-also: ElementsProject#5990
1 parent dd9400d commit 70aee52

File tree

6 files changed

+56
-47
lines changed

6 files changed

+56
-47
lines changed

plugins/autoclean.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,11 @@ static const char *init(struct plugin *p,
574574

575575
cleantimer = plugin_timer(p, time_from_sec(cycle_seconds), do_clean_timer, NULL);
576576

577+
/* We don't care if this fails (it usually does, since entries
578+
* don't exist! */
577579
for (enum subsystem i = 0; i < NUM_SUBSYSTEM; i++) {
578-
rpc_scan_datastore_str(plugin, datastore_path(tmpctx, i, "num"),
580+
rpc_scan_datastore_str(tmpctx, plugin,
581+
datastore_path(tmpctx, i, "num"),
579582
JSON_SCAN(json_to_u64, &total_cleaned[i]));
580583
}
581584

plugins/commando.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ static const char *init(struct plugin *p,
989989
const char *buf UNUSED, const jsmntok_t *config UNUSED)
990990
{
991991
struct secret rune_secret;
992+
const char *err;
992993

993994
outgoing_commands = tal_arr(p, struct commando *, 0);
994995
incoming_commands = tal_arr(p, struct commando *, 0);
@@ -1000,13 +1001,16 @@ static const char *init(struct plugin *p,
10001001
#endif
10011002

10021003
rune_counter = tal(p, u64);
1003-
if (!rpc_scan_datastore_str(plugin, "commando/rune_counter",
1004-
JSON_SCAN(json_to_u64, rune_counter)))
1004+
/* If this fails, it probably doesn't exist */
1005+
err = rpc_scan_datastore_str(tmpctx, plugin, "commando/rune_counter",
1006+
JSON_SCAN(json_to_u64, rune_counter));
1007+
if (err)
10051008
rune_counter = tal_free(rune_counter);
10061009

10071010
/* Old python commando used to store secret */
1008-
if (!rpc_scan_datastore_hex(plugin, "commando/secret",
1009-
JSON_SCAN(json_to_secret, &rune_secret))) {
1011+
err = rpc_scan_datastore_hex(tmpctx, plugin, "commando/secret",
1012+
JSON_SCAN(json_to_secret, &rune_secret));
1013+
if (err) {
10101014
rpc_scan(plugin, "makesecret",
10111015
/* $ i commando
10121016
* 99 0x63 0143 0b1100011 'c'

plugins/libplugin.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,14 @@ static void json_add_keypath(struct json_out *jout, const char *fieldname, const
627627
json_out_end(jout, ']');
628628
}
629629

630-
static bool rpc_scan_datastore(struct plugin *plugin,
631-
const char *path,
632-
const char *hex_or_string,
633-
va_list ap)
630+
static const char *rpc_scan_datastore(const tal_t *ctx,
631+
struct plugin *plugin,
632+
const char *path,
633+
const char *hex_or_string,
634+
va_list ap)
634635
{
635636
const char *guide;
636637
struct json_out *params;
637-
const char *err;
638638

639639
params = json_out_new(NULL);
640640
json_out_start(params, NULL, '{');
@@ -643,37 +643,35 @@ static bool rpc_scan_datastore(struct plugin *plugin,
643643
json_out_finished(params);
644644

645645
guide = tal_fmt(tmpctx, "{datastore:[0:{%s:%%}]}", hex_or_string);
646-
/* FIXME: Could be some other error, but that's probably a caller bug! */
647-
err = rpc_scan_core(tmpctx, plugin, "listdatastore", take(params), guide, ap);
648-
if (!err)
649-
return true;
650-
plugin_log(plugin, LOG_DBG, "listdatastore error %s: %s", path, err);
651-
return false;
646+
return rpc_scan_core(ctx, plugin, "listdatastore", take(params),
647+
guide, ap);
652648
}
653649

654-
bool rpc_scan_datastore_str(struct plugin *plugin,
655-
const char *path,
656-
...)
650+
const char *rpc_scan_datastore_str(const tal_t *ctx,
651+
struct plugin *plugin,
652+
const char *path,
653+
...)
657654
{
658-
bool ret;
655+
const char *ret;
659656
va_list ap;
660657

661658
va_start(ap, path);
662-
ret = rpc_scan_datastore(plugin, path, "string", ap);
659+
ret = rpc_scan_datastore(ctx, plugin, path, "string", ap);
663660
va_end(ap);
664661
return ret;
665662
}
666663

667664
/* This variant scans the hex encoding, not the string */
668-
bool rpc_scan_datastore_hex(struct plugin *plugin,
669-
const char *path,
670-
...)
665+
const char *rpc_scan_datastore_hex(const tal_t *ctx,
666+
struct plugin *plugin,
667+
const char *path,
668+
...)
671669
{
672-
bool ret;
670+
const char *ret;
673671
va_list ap;
674672

675673
va_start(ap, path);
676-
ret = rpc_scan_datastore(plugin, path, "hex", ap);
674+
ret = rpc_scan_datastore(ctx, plugin, path, "hex", ap);
677675
va_end(ap);
678676
return ret;
679677
}

plugins/libplugin.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,19 @@ void rpc_scan(struct plugin *plugin,
310310
const char *guide,
311311
...);
312312

313-
/* Helper to scan datastore: can only be used in init callback. *
314-
Returns false if field does not exist. * path is /-separated. Final
315-
arg is JSON_SCAN or JSON_SCAN_TAL.
313+
/* Helper to scan datastore: can only be used in init callback. Returns error
314+
* msg (usually meaning field does not exist), or NULL on success. path is
315+
* /-separated. Final arg is JSON_SCAN or JSON_SCAN_TAL.
316316
*/
317-
bool rpc_scan_datastore_str(struct plugin *plugin,
318-
const char *path,
319-
...);
317+
const char *rpc_scan_datastore_str(const tal_t *ctx,
318+
struct plugin *plugin,
319+
const char *path,
320+
...);
320321
/* This variant scans the hex encoding, not the string */
321-
bool rpc_scan_datastore_hex(struct plugin *plugin,
322-
const char *path,
323-
...);
322+
const char *rpc_scan_datastore_hex(const tal_t *ctx,
323+
struct plugin *plugin,
324+
const char *path,
325+
...);
324326

325327
/* This sets batching of database commitments */
326328
void rpc_enable_batching(struct plugin *plugin);

tests/plugins/test_libplugin.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static const char *init(struct plugin *p,
131131
const char *buf UNUSED,
132132
const jsmntok_t *config UNUSED)
133133
{
134-
const char *name;
134+
const char *name, *err_str, *err_hex;
135135
const u8 *binname;
136136

137137
plugin_log(p, LOG_DBG, "test_libplugin initialised!");
@@ -143,19 +143,21 @@ static const char *init(struct plugin *p,
143143
return "Disabled via selfdisable option";
144144

145145
/* Test rpc_scan_datastore funcs */
146-
if (!rpc_scan_datastore_str(p, "test_libplugin/name",
147-
JSON_SCAN_TAL(tmpctx, json_strdup,
148-
&name)))
146+
err_str = rpc_scan_datastore_str(tmpctx, p, "test_libplugin/name",
147+
JSON_SCAN_TAL(tmpctx, json_strdup,
148+
&name));
149+
if (err_str)
149150
name = NULL;
150-
if (!rpc_scan_datastore_hex(p, "test_libplugin/name",
151-
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex,
152-
&binname)))
151+
err_hex = rpc_scan_datastore_hex(tmpctx, p, "test_libplugin/name",
152+
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex,
153+
&binname));
154+
if (err_hex)
153155
binname = NULL;
154156

155157
plugin_log(p, LOG_INFORM, "String name from datastore: %s",
156-
name ? name : "NOT FOUND");
158+
name ? name : err_str);
157159
plugin_log(p, LOG_INFORM, "Hex name from datastore: %s",
158-
binname ? tal_hex(tmpctx, binname) : "NOT FOUND");
160+
binname ? tal_hex(tmpctx, binname) : err_hex);
159161

160162
return NULL;
161163
}

tests/test_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,8 @@ def test_libplugin(node_factory):
14991499

15001500
# Test startup
15011501
assert l1.daemon.is_in_log("test_libplugin initialised!")
1502-
assert l1.daemon.is_in_log("String name from datastore: NOT FOUND")
1503-
assert l1.daemon.is_in_log("Hex name from datastore: NOT FOUND")
1502+
assert l1.daemon.is_in_log("String name from datastore:.*token has no index 0")
1503+
assert l1.daemon.is_in_log("Hex name from datastore:.*token has no index 0")
15041504

15051505
# This will look on datastore for default, won't find it.
15061506
assert l1.rpc.call("helloworld") == {"hello": "NOT FOUND"}
@@ -1519,7 +1519,7 @@ def test_libplugin(node_factory):
15191519
# yet whether strings are allowed:
15201520
l1.daemon.wait_for_log(r"test_libplugin: [0-9]*\[OUT\]")
15211521

1522-
l1.daemon.wait_for_log("String name from datastore: NOT FOUND")
1522+
l1.daemon.wait_for_log("String name from datastore:.*object does not have member string")
15231523
l1.daemon.wait_for_log("Hex name from datastore: 00010203")
15241524

15251525
# Test commands

0 commit comments

Comments
 (0)