Skip to content

Commit 218aa6c

Browse files
committed
libplugin: clean up API.
When we used to allow cmd to be NULL, we had to hand the plugin everywhere. We no longer do. 1. Various jsonrpc_ functions no longer need the plugin arg. 2. send_outreq no longer needs a plugin arg. 3. The init function takes a command, not a plugin. 4. Remove command_deprecated_in_nocmd_ok. Signed-off-by: Rusty Russell <[email protected]>
1 parent 8407fe0 commit 218aa6c

35 files changed

+393
-455
lines changed

plugins/askrene/askrene.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,11 @@ static struct command_result *json_getroutes(struct command *cmd,
759759
if (have_layer(info->layers, "auto.localchans")) {
760760
struct out_req *req;
761761

762-
req = jsonrpc_request_start(cmd->plugin, cmd,
762+
req = jsonrpc_request_start(cmd,
763763
"listpeerchannels",
764764
listpeerchannels_done,
765765
forward_error, info);
766-
return send_outreq(cmd->plugin, req);
766+
return send_outreq(req);
767767
} else
768768
info->local_layer = NULL;
769769

@@ -1152,9 +1152,10 @@ static void askrene_markmem(struct plugin *plugin, struct htable *memtable)
11521152
reserve_memleak_mark(askrene, memtable);
11531153
}
11541154

1155-
static const char *init(struct plugin *plugin,
1155+
static const char *init(struct command *init_cmd,
11561156
const char *buf UNUSED, const jsmntok_t *config UNUSED)
11571157
{
1158+
struct plugin *plugin = init_cmd->plugin;
11581159
struct askrene *askrene = tal(plugin, struct askrene);
11591160
askrene->plugin = plugin;
11601161
list_head_init(&askrene->layers);
@@ -1165,7 +1166,7 @@ static const char *init(struct plugin *plugin,
11651166
plugin_err(plugin, "Could not load gossmap %s: %s",
11661167
GOSSIP_STORE_FILENAME, strerror(errno));
11671168
askrene->capacities = get_capacities(askrene, askrene->plugin, askrene->gossmap);
1168-
rpc_scan(plugin, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
1169+
rpc_scan(init_cmd, "getinfo", take(json_out_obj(NULL, NULL, NULL)),
11691170
"{id:%}", JSON_SCAN(json_to_node_id, &askrene->my_id));
11701171

11711172
plugin_set_data(plugin, askrene);

plugins/autoclean.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static struct command_result *clean_finished(struct clean_info *cinfo)
259259
plugin_log(plugin, LOG_DBG, "cleaned %zu from %s",
260260
num_cleaned, subsystem_to_str(&sv));
261261
*total_cleaned(&sv) += num_cleaned;
262-
jsonrpc_set_datastore_string(plugin, cinfo->cmd,
262+
jsonrpc_set_datastore_string(cinfo->cmd,
263263
datastore_path(tmpctx, &sv, "num"),
264264
tal_fmt(tmpctx, "%"PRIu64,
265265
*total_cleaned(&sv)),
@@ -509,10 +509,10 @@ static struct command_result *list_done(struct command *cmd,
509509
}
510510

511511
subsystem->cinfo->cleanup_reqs_remaining++;
512-
req = jsonrpc_request_start(plugin, cmd, ops->del_command,
512+
req = jsonrpc_request_start(cmd, ops->del_command,
513513
del_done, del_failed, variant);
514514
ops->add_del_fields(req, buf, t);
515-
send_outreq(plugin, req);
515+
send_outreq(req);
516516
}
517517

518518
subsystem->offset += max_entries_per_call;
@@ -555,7 +555,7 @@ static struct command_result *do_clean(struct clean_info *cinfo)
555555

556556
filter = tal_fmt(tmpctx, "{\"%s\":[{%s}]}",
557557
ops->arr_name, ops->list_filter);
558-
req = jsonrpc_request_with_filter_start(plugin, cinfo->cmd,
558+
req = jsonrpc_request_with_filter_start(cinfo->cmd,
559559
tal_fmt(tmpctx,
560560
"list%s",
561561
ops->system_name),
@@ -567,7 +567,7 @@ static struct command_result *do_clean(struct clean_info *cinfo)
567567
json_add_string(req->js, "index", "created");
568568
json_add_u64(req->js, "start", ps->offset);
569569
json_add_u64(req->js, "limit", max_entries_per_call);
570-
send_outreq(plugin, req);
570+
send_outreq(req);
571571
cinfo->cleanup_reqs_remaining++;
572572
}
573573

@@ -628,13 +628,13 @@ static struct command_result *start_clean(struct clean_info *cinfo)
628628
}
629629
ps->offset = 0;
630630

631-
req = jsonrpc_request_start(plugin, cinfo->cmd,
631+
req = jsonrpc_request_start(cinfo->cmd,
632632
"wait",
633633
wait_done, wait_failed, ps);
634634
json_add_string(req->js, "subsystem", ops->system_name);
635635
json_add_string(req->js, "indexname", "created");
636636
json_add_u64(req->js, "nextvalue", 0);
637-
send_outreq(plugin, req);
637+
send_outreq(req);
638638
cinfo->cleanup_reqs_remaining++;
639639
}
640640

@@ -742,29 +742,29 @@ static void memleak_mark_timer_cinfo(struct plugin *plugin,
742742
memleak_scan_obj(memtable, timer_cinfo);
743743
}
744744

745-
static const char *init(struct plugin *p,
745+
static const char *init(struct command *init_cmd,
746746
const char *buf UNUSED, const jsmntok_t *config UNUSED)
747747
{
748748
struct subsystem_and_variant sv;
749-
plugin = p;
749+
plugin = init_cmd->plugin;
750750

751751
/* Plugin owns global */
752752
tal_steal(plugin, timer_cinfo);
753753
plugin_set_memleak_handler(plugin, memleak_mark_timer_cinfo);
754754

755-
cleantimer = global_timer(p, time_from_sec(cycle_seconds), do_clean_timer, NULL);
755+
cleantimer = global_timer(plugin, time_from_sec(cycle_seconds), do_clean_timer, NULL);
756756

757757
/* We don't care if this fails (it usually does, since entries
758758
* don't exist! */
759759
sv = first_sv();
760760
do {
761-
rpc_scan_datastore_str(tmpctx, plugin,
761+
rpc_scan_datastore_str(tmpctx, init_cmd,
762762
datastore_path(tmpctx, &sv, "num"),
763763
JSON_SCAN(json_to_u64, total_cleaned(&sv)));
764764
} while (next_sv(&sv));
765765

766766
/* Optimization FTW! */
767-
rpc_enable_batching(p);
767+
rpc_enable_batching(plugin);
768768
return NULL;
769769
}
770770

plugins/bcli.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,19 +1100,19 @@ static void memleak_mark_bitcoind(struct plugin *p, struct htable *memtable)
11001100
memleak_scan_obj(memtable, bitcoind);
11011101
}
11021102

1103-
static const char *init(struct plugin *p, const char *buffer UNUSED,
1103+
static const char *init(struct command *init_cmd, const char *buffer UNUSED,
11041104
const jsmntok_t *config UNUSED)
11051105
{
1106-
wait_and_check_bitcoind(p);
1106+
wait_and_check_bitcoind(init_cmd->plugin);
11071107

11081108
/* Usually we fake up fees in regtest */
11091109
if (streq(chainparams->network_name, "regtest"))
11101110
bitcoind->fake_fees = !bitcoind->dev_no_fake_fees;
11111111
else
11121112
bitcoind->fake_fees = false;
11131113

1114-
plugin_set_memleak_handler(p, memleak_mark_bitcoind);
1115-
plugin_log(p, LOG_INFORM,
1114+
plugin_set_memleak_handler(init_cmd->plugin, memleak_mark_bitcoind);
1115+
plugin_log(init_cmd->plugin, LOG_INFORM,
11161116
"bitcoin-cli initialized and connected to bitcoind.");
11171117

11181118
return NULL;

plugins/bkpr/bookkeeper.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ static struct command_result *json_channel_apy(struct command *cmd,
123123
return command_param_failed();
124124

125125
/* First get the current blockheight */
126-
req = jsonrpc_request_start(cmd->plugin, cmd, "getinfo",
126+
req = jsonrpc_request_start(cmd, "getinfo",
127127
&getblockheight_done,
128128
forward_error,
129129
apyreq);
130-
return send_outreq(cmd->plugin, req);
130+
return send_outreq(req);
131131
}
132132

133133
static struct command_result *param_csv_format(struct command *cmd, const char *name,
@@ -1122,13 +1122,13 @@ static struct command_result *json_balance_snapshot(struct command *cmd,
11221122
if (tal_count(new_accts) > 0) {
11231123
struct out_req *req;
11241124

1125-
req = jsonrpc_request_start(cmd->plugin, cmd,
1125+
req = jsonrpc_request_start(cmd,
11261126
"listpeerchannels",
11271127
listpeerchannels_multi_done,
11281128
log_error,
11291129
new_accts);
11301130
/* FIXME(vicenzopalazzo) require the channel by channel_id to avoid parsing not useful json */
1131-
return send_outreq(cmd->plugin, req);
1131+
return send_outreq(req);
11321132
}
11331133

11341134
plugin_log(cmd->plugin, LOG_DBG, "Snapshot balances updated");
@@ -1288,20 +1288,20 @@ static struct command_result *lookup_invoice_desc(struct command *cmd,
12881288
/* Otherwise will go away when event is cleaned up */
12891289
tal_steal(cmd, payment_hash);
12901290
if (!amount_msat_is_zero(credit))
1291-
req = jsonrpc_request_start(cmd->plugin, cmd,
1291+
req = jsonrpc_request_start(cmd,
12921292
"listinvoices",
12931293
listinvoices_done,
12941294
log_error,
12951295
payment_hash);
12961296
else
1297-
req = jsonrpc_request_start(cmd->plugin, cmd,
1297+
req = jsonrpc_request_start(cmd,
12981298
"listsendpays",
12991299
listsendpays_done,
13001300
log_error,
13011301
payment_hash);
13021302

13031303
json_add_sha256(req->js, "payment_hash", payment_hash);
1304-
return send_outreq(cmd->plugin, req);
1304+
return send_outreq(req);
13051305
}
13061306

13071307
struct event_info {
@@ -1564,13 +1564,13 @@ parse_and_log_chain_move(struct command *cmd,
15641564
is_channel_account(acct) ?
15651565
acct : orig_acct);
15661566

1567-
req = jsonrpc_request_start(cmd->plugin, cmd,
1567+
req = jsonrpc_request_start(cmd,
15681568
"listpeerchannels",
15691569
listpeerchannels_done,
15701570
log_error,
15711571
info);
15721572
/* FIXME: use the peer_id to reduce work here */
1573-
return send_outreq(cmd->plugin, req);
1573+
return send_outreq(req);
15741574
}
15751575

15761576
/* Maybe mark acct as onchain resolved */
@@ -1977,8 +1977,10 @@ static const struct plugin_command commands[] = {
19771977
},
19781978
};
19791979

1980-
static const char *init(struct plugin *p, const char *b, const jsmntok_t *t)
1980+
static const char *init(struct command *init_cmd, const char *b, const jsmntok_t *t)
19811981
{
1982+
struct plugin *p = init_cmd->plugin;
1983+
19821984
/* Switch to bookkeeper-dir, if specified */
19831985
if (datadir && chdir(datadir) != 0) {
19841986
if (mkdir(datadir, 0700) != 0 && errno != EEXIST)

0 commit comments

Comments
 (0)