Skip to content

Commit 0951526

Browse files
committed
libplugin: add method string to jsonrpc callbacks, implement generic helpers.
Without knowing what method was called, we can't have useful general logging methods, so go through the pain of adding "const char *method" everywhere, and add: 1. ignore_and_complete - we're done when jsonrpc returned 2. log_broken_and_complete - we're done, but emit BROKEN log. 3. plugin_broken_cb - if this happens, fail the plugin. Signed-off-by: Rusty Russell <[email protected]>
1 parent 82743db commit 0951526

33 files changed

+367
-102
lines changed

plugins/askrene/askrene.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ static void add_localchan(struct gossmap_localmods *mods,
719719

720720
static struct command_result *
721721
listpeerchannels_done(struct command *cmd,
722+
const char *method UNUSED,
722723
const char *buffer,
723724
const jsmntok_t *toks,
724725
struct getroutes_info *info)

plugins/autoclean.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ static struct command_result *clean_finished_one(struct clean_info *cinfo)
305305
}
306306

307307
static struct command_result *del_done(struct command *cmd,
308+
const char *method,
308309
const char *buf,
309310
const jsmntok_t *result,
310311
struct per_variant *variant)
@@ -314,6 +315,7 @@ static struct command_result *del_done(struct command *cmd,
314315
}
315316

316317
static struct command_result *del_failed(struct command *cmd,
318+
const char *method,
317319
const char *buf,
318320
const jsmntok_t *result,
319321
struct per_variant *variant)
@@ -477,6 +479,7 @@ static void add_forward_del_fields(struct out_req *req,
477479
}
478480

479481
static struct command_result *list_done(struct command *cmd,
482+
const char *method,
480483
const char *buf,
481484
const jsmntok_t *result,
482485
struct per_subsystem *subsystem)
@@ -520,6 +523,7 @@ static struct command_result *list_done(struct command *cmd,
520523
}
521524

522525
static struct command_result *list_failed(struct command *cmd,
526+
const char *method,
523527
const char *buf,
524528
const jsmntok_t *result,
525529
struct per_subsystem *subsystem)
@@ -577,6 +581,7 @@ static struct command_result *do_clean(struct clean_info *cinfo)
577581
}
578582

579583
static struct command_result *wait_done(struct command *cmd,
584+
const char *method,
580585
const char *buf,
581586
const jsmntok_t *result,
582587
struct per_subsystem *ps)
@@ -599,17 +604,6 @@ static struct command_result *wait_done(struct command *cmd,
599604
return do_clean(ps->cinfo);
600605
}
601606

602-
static struct command_result *wait_failed(struct command *cmd,
603-
const char *buf,
604-
const jsmntok_t *result,
605-
struct per_subsystem *subsystem)
606-
{
607-
plugin_err(plugin, "Failed wait '%s': '%.*s'",
608-
get_subsystem_ops(subsystem)->system_name,
609-
json_tok_full_len(result),
610-
json_tok_full(buf, result));
611-
}
612-
613607
static struct command_result *start_clean(struct clean_info *cinfo)
614608
{
615609
cinfo->cleanup_reqs_remaining = 0;
@@ -630,7 +624,7 @@ static struct command_result *start_clean(struct clean_info *cinfo)
630624

631625
req = jsonrpc_request_start(cinfo->cmd,
632626
"wait",
633-
wait_done, wait_failed, ps);
627+
wait_done, plugin_broken_cb, ps);
634628
json_add_string(req->js, "subsystem", ops->system_name);
635629
json_add_string(req->js, "indexname", "created");
636630
json_add_u64(req->js, "nextvalue", 0);

plugins/bkpr/bookkeeper.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ struct apy_req {
5252
};
5353

5454
static struct command_result *
55-
getblockheight_done(struct command *cmd, const char *buf,
55+
getblockheight_done(struct command *cmd,
56+
const char *method,
57+
const char *buf,
5658
const jsmntok_t *result,
5759
struct apy_req *req)
5860
{
@@ -851,19 +853,21 @@ static void log_journal_entry(struct account *acct,
851853
}
852854

853855
static struct command_result *log_error(struct command *cmd,
856+
const char *method,
854857
const char *buf,
855858
const jsmntok_t *error,
856859
void *arg UNNEEDED)
857860
{
858861
plugin_log(cmd->plugin, LOG_BROKEN,
859-
"error calling rpc: %.*s",
860-
json_tok_full_len(error),
862+
"error calling %s: %.*s",
863+
method, json_tok_full_len(error),
861864
json_tok_full(buf, error));
862865

863866
return notification_handled(cmd);
864867
}
865868

866869
static struct command_result *listpeerchannels_multi_done(struct command *cmd,
870+
const char *method,
867871
const char *buf,
868872
const jsmntok_t *result,
869873
struct new_account_info **new_accts)
@@ -1198,8 +1202,11 @@ static char *fetch_out_desc_invstr(const tal_t *ctx, const char *buf,
11981202
}
11991203

12001204
static struct command_result *
1201-
listinvoices_done(struct command *cmd, const char *buf,
1202-
const jsmntok_t *result, struct sha256 *payment_hash)
1205+
listinvoices_done(struct command *cmd,
1206+
const char *method,
1207+
const char *buf,
1208+
const jsmntok_t *result,
1209+
struct sha256 *payment_hash)
12031210
{
12041211
size_t i;
12051212
const jsmntok_t *inv_arr_tok, *inv_tok;
@@ -1243,8 +1250,11 @@ listinvoices_done(struct command *cmd, const char *buf,
12431250
}
12441251

12451252
static struct command_result *
1246-
listsendpays_done(struct command *cmd, const char *buf,
1247-
const jsmntok_t *result, struct sha256 *payment_hash)
1253+
listsendpays_done(struct command *cmd,
1254+
const char *method,
1255+
const char *buf,
1256+
const jsmntok_t *result,
1257+
struct sha256 *payment_hash)
12481258
{
12491259
size_t i;
12501260
const jsmntok_t *pays_arr_tok, *pays_tok;
@@ -1310,8 +1320,11 @@ struct event_info {
13101320
};
13111321

13121322
static struct command_result *
1313-
listpeerchannels_done(struct command *cmd, const char *buf,
1314-
const jsmntok_t *result, struct event_info *info)
1323+
listpeerchannels_done(struct command *cmd,
1324+
const char *method,
1325+
const char *buf,
1326+
const jsmntok_t *result,
1327+
struct event_info *info)
13151328
{
13161329
struct acct_balance **balances, *bal;
13171330
struct amount_msat credit_diff, debit_diff;

plugins/chanbackup.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ static u8 *decrypt_scb(struct plugin *p)
216216
}
217217

218218
static struct command_result *after_recover_rpc(struct command *cmd,
219+
const char *method,
219220
const char *buf,
220221
const jsmntok_t *params,
221222
void *cb_arg UNUSED)
@@ -263,7 +264,7 @@ static struct command_result *json_emergencyrecover(struct command *cmd,
263264

264265
req = jsonrpc_request_start(cmd, "recoverchannel",
265266
after_recover_rpc,
266-
&forward_error, NULL);
267+
forward_error, NULL);
267268

268269
json_array_start(req->js, "scb");
269270
for (size_t i=0; i<tal_count(scb); i++) {
@@ -319,6 +320,7 @@ static void update_scb(struct plugin *p, struct scb_chan **channels)
319320

320321
static struct command_result
321322
*peer_after_send_their_peer_strg(struct command *cmd,
323+
const char *method,
322324
const char *buf,
323325
const jsmntok_t *params,
324326
void *cb_arg UNUSED)
@@ -329,6 +331,7 @@ static struct command_result
329331

330332
static struct command_result
331333
*peer_after_send_their_peer_strg_err(struct command *cmd,
334+
const char *method,
332335
const char *buf,
333336
const jsmntok_t *params,
334337
void *cb_arg UNUSED)
@@ -367,6 +370,7 @@ static struct command_result *peer_after_listdatastore(struct command *cmd,
367370
}
368371

369372
static struct command_result *peer_after_send_scb(struct command *cmd,
373+
const char *method,
370374
const char *buf,
371375
const jsmntok_t *params,
372376
struct node_id *nodeid)
@@ -383,6 +387,7 @@ static struct command_result *peer_after_send_scb(struct command *cmd,
383387
}
384388

385389
static struct command_result *peer_after_send_scb_failed(struct command *cmd,
390+
const char *method,
386391
const char *buf,
387392
const jsmntok_t *params,
388393
struct node_id *nodeid)
@@ -397,6 +402,7 @@ struct info {
397402
};
398403

399404
static struct command_result *after_send_scb_single(struct command *cmd,
405+
const char *method,
400406
const char *buf,
401407
const jsmntok_t *params,
402408
struct info *info)
@@ -409,6 +415,7 @@ static struct command_result *after_send_scb_single(struct command *cmd,
409415
}
410416

411417
static struct command_result *after_send_scb_single_fail(struct command *cmd,
418+
const char *method,
412419
const char *buf,
413420
const jsmntok_t *params,
414421
struct info *info)
@@ -421,6 +428,7 @@ static struct command_result *after_send_scb_single_fail(struct command *cmd,
421428
}
422429

423430
static struct command_result *after_listpeers(struct command *cmd,
431+
const char *method,
424432
const char *buf,
425433
const jsmntok_t *params,
426434
void *cb_arg UNUSED)
@@ -482,6 +490,7 @@ static struct command_result *after_listpeers(struct command *cmd,
482490
}
483491

484492
static struct command_result *after_staticbackup(struct command *cmd,
493+
const char *method,
485494
const char *buf,
486495
const jsmntok_t *params,
487496
void *cb_arg UNUSED)
@@ -588,6 +597,7 @@ static struct command_result *failed_peer_restore(struct command *cmd,
588597
}
589598

590599
static struct command_result *datastore_success(struct command *cmd,
600+
const char *method,
591601
const char *buf,
592602
const jsmntok_t *result,
593603
char *what)
@@ -597,6 +607,7 @@ static struct command_result *datastore_success(struct command *cmd,
597607
}
598608

599609
static struct command_result *datastore_failed(struct command *cmd,
610+
const char *method,
600611
const char *buf,
601612
const jsmntok_t *result,
602613
char *what)

plugins/commando.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct reply {
118118

119119
/* Calls itself repeatedly: first time, result is NULL */
120120
static struct command_result *send_response(struct command *cmd,
121+
const char *method UNUSED,
121122
const char *buf UNUSED,
122123
const jsmntok_t *result,
123124
struct reply *reply)
@@ -157,6 +158,7 @@ static struct command_result *send_response(struct command *cmd,
157158
}
158159

159160
static struct command_result *cmd_done(struct command *command,
161+
const char *method,
160162
const char *buf,
161163
const jsmntok_t *obj,
162164
struct commando *incoming)
@@ -190,7 +192,7 @@ static struct command_result *cmd_done(struct command *command,
190192
}
191193
reply->off = 0;
192194

193-
return send_response(command, NULL, NULL, reply);
195+
return send_response(command, NULL, NULL, NULL, reply);
194196
}
195197

196198
static struct command_result *commando_error(struct command *cmd,
@@ -216,7 +218,7 @@ static struct command_result *commando_error(struct command *cmd,
216218
reply->off = 0;
217219
reply->len = tal_bytelen(reply->buf) - 1;
218220

219-
return send_response(cmd, NULL, NULL, reply);
221+
return send_response(cmd, NULL, NULL, NULL, reply);
220222
}
221223

222224
struct cond_info {
@@ -322,6 +324,7 @@ static struct command_result *execute_command(struct command *cmd,
322324
}
323325

324326
static struct command_result *checkrune_done(struct command *cmd,
327+
const char *method,
325328
const char *buf,
326329
const jsmntok_t *result,
327330
struct cond_info *cinfo)
@@ -349,6 +352,7 @@ static struct command_result *checkrune_done(struct command *cmd,
349352
}
350353

351354
static struct command_result *checkrune_failed(struct command *cmd,
355+
const char *method,
352356
const char *buf,
353357
const jsmntok_t *result,
354358
struct cond_info *cinfo)
@@ -619,6 +623,7 @@ struct outgoing {
619623
};
620624

621625
static struct command_result *send_more_cmd(struct command *cmd,
626+
const char *method UNUSED,
622627
const char *buf UNUSED,
623628
const jsmntok_t *result UNUSED,
624629
struct outgoing *outgoing)
@@ -705,19 +710,20 @@ static struct command_result *json_commando(struct command *cmd,
705710
outgoing->msgs[i] = cmd_msg;
706711
}
707712

708-
return send_more_cmd(cmd, NULL, NULL, outgoing);
713+
return send_more_cmd(cmd, NULL, NULL, NULL, outgoing);
709714
}
710715

711716
/* Handles error or success */
712717
static struct command_result *forward_reply(struct command *cmd,
718+
const char *method,
713719
const char *buf,
714720
const jsmntok_t *result,
715721
void *arg)
716722
{
717723
const jsmntok_t *err = json_get_member(buf, result, "error");
718724
if (err)
719-
return forward_error(cmd, buf, err, arg);
720-
return forward_result(cmd, buf, json_get_member(buf, result, "result"), arg);
725+
return forward_error(cmd, method, buf, err, arg);
726+
return forward_result(cmd, method, buf, json_get_member(buf, result, "result"), arg);
721727
}
722728

723729
static struct command_result *forward_command(struct command *cmd,

plugins/establish_onion_path.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct connect_info {
2020
};
2121

2222
static struct command_result *connect_ok(struct command *cmd,
23+
const char *method,
2324
const char *buf,
2425
const jsmntok_t *result,
2526
struct connect_info *ci)
@@ -34,6 +35,7 @@ static struct command_result *connect_ok(struct command *cmd,
3435
}
3536

3637
static struct command_result *command_failed(struct command *cmd,
38+
const char *method,
3739
const char *buf,
3840
const jsmntok_t *result,
3941
struct connect_info *ci)
@@ -185,6 +187,7 @@ static const struct pubkey *path_to_node(const tal_t *ctx,
185187
}
186188

187189
static struct command_result *listpeers_done(struct command *cmd,
190+
const char *method,
188191
const char *buf,
189192
const jsmntok_t *result,
190193
struct connect_info *ci)

0 commit comments

Comments
 (0)