From c797b6fb2096c0677752235ffa984f69a7429517 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 7 Nov 2024 11:57:37 +1030 Subject: [PATCH] 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 --- plugins/askrene/askrene.c | 1 + plugins/autoclean.c | 18 ++---- plugins/bkpr/bookkeeper.c | 31 +++++++--- plugins/chanbackup.c | 13 +++- plugins/commando.c | 16 +++-- plugins/establish_onion_path.c | 3 + plugins/fetchinvoice.c | 8 ++- plugins/funder.c | 23 +++++-- plugins/keysend.c | 9 ++- plugins/libplugin-pay.c | 52 +++++++++++----- plugins/libplugin.c | 97 ++++++++++++++++++++++++------ plugins/libplugin.h | 51 +++++++++++++++- plugins/offers.c | 6 ++ plugins/offers.h | 4 ++ plugins/offers_inv_hook.c | 4 ++ plugins/offers_invreq_hook.c | 10 ++- plugins/offers_offer.c | 6 +- plugins/pay.c | 12 +++- plugins/recover.c | 11 +++- plugins/renepay/mods.c | 8 +++ plugins/renepay/routefail.c | 4 +- plugins/renepay/routetracker.c | 2 + plugins/spender/fundchannel.c | 2 + plugins/spender/multifundchannel.c | 19 +++++- plugins/spender/multifundchannel.h | 1 + plugins/spender/multiwithdraw.c | 9 +++ plugins/spender/openchannel.c | 6 ++ plugins/sql.c | 3 + plugins/test/run-route-calc.c | 2 + plugins/test/run-route-overlong.c | 2 + plugins/topology.c | 26 +++----- plugins/txprepare.c | 6 ++ tests/plugins/test_libplugin.c | 4 +- 33 files changed, 367 insertions(+), 102 deletions(-) diff --git a/plugins/askrene/askrene.c b/plugins/askrene/askrene.c index 0d35add21..d01d4a90c 100644 --- a/plugins/askrene/askrene.c +++ b/plugins/askrene/askrene.c @@ -719,6 +719,7 @@ static void add_localchan(struct gossmap_localmods *mods, static struct command_result * listpeerchannels_done(struct command *cmd, + const char *method UNUSED, const char *buffer, const jsmntok_t *toks, struct getroutes_info *info) diff --git a/plugins/autoclean.c b/plugins/autoclean.c index c69683cfe..197d65966 100644 --- a/plugins/autoclean.c +++ b/plugins/autoclean.c @@ -305,6 +305,7 @@ static struct command_result *clean_finished_one(struct clean_info *cinfo) } static struct command_result *del_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct per_variant *variant) @@ -314,6 +315,7 @@ static struct command_result *del_done(struct command *cmd, } static struct command_result *del_failed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct per_variant *variant) @@ -477,6 +479,7 @@ static void add_forward_del_fields(struct out_req *req, } static struct command_result *list_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct per_subsystem *subsystem) @@ -520,6 +523,7 @@ static struct command_result *list_done(struct command *cmd, } static struct command_result *list_failed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct per_subsystem *subsystem) @@ -577,6 +581,7 @@ static struct command_result *do_clean(struct clean_info *cinfo) } static struct command_result *wait_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct per_subsystem *ps) @@ -599,17 +604,6 @@ static struct command_result *wait_done(struct command *cmd, return do_clean(ps->cinfo); } -static struct command_result *wait_failed(struct command *cmd, - const char *buf, - const jsmntok_t *result, - struct per_subsystem *subsystem) -{ - plugin_err(plugin, "Failed wait '%s': '%.*s'", - get_subsystem_ops(subsystem)->system_name, - json_tok_full_len(result), - json_tok_full(buf, result)); -} - static struct command_result *start_clean(struct clean_info *cinfo) { cinfo->cleanup_reqs_remaining = 0; @@ -630,7 +624,7 @@ static struct command_result *start_clean(struct clean_info *cinfo) req = jsonrpc_request_start(cinfo->cmd, "wait", - wait_done, wait_failed, ps); + wait_done, plugin_broken_cb, ps); json_add_string(req->js, "subsystem", ops->system_name); json_add_string(req->js, "indexname", "created"); json_add_u64(req->js, "nextvalue", 0); diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c index 13821538c..596d64ddd 100644 --- a/plugins/bkpr/bookkeeper.c +++ b/plugins/bkpr/bookkeeper.c @@ -52,7 +52,9 @@ struct apy_req { }; static struct command_result * -getblockheight_done(struct command *cmd, const char *buf, +getblockheight_done(struct command *cmd, + const char *method, + const char *buf, const jsmntok_t *result, struct apy_req *req) { @@ -851,19 +853,21 @@ static void log_journal_entry(struct account *acct, } static struct command_result *log_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, void *arg UNNEEDED) { plugin_log(cmd->plugin, LOG_BROKEN, - "error calling rpc: %.*s", - json_tok_full_len(error), + "error calling %s: %.*s", + method, json_tok_full_len(error), json_tok_full(buf, error)); return notification_handled(cmd); } static struct command_result *listpeerchannels_multi_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct new_account_info **new_accts) @@ -1198,8 +1202,11 @@ static char *fetch_out_desc_invstr(const tal_t *ctx, const char *buf, } static struct command_result * -listinvoices_done(struct command *cmd, const char *buf, - const jsmntok_t *result, struct sha256 *payment_hash) +listinvoices_done(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + struct sha256 *payment_hash) { size_t i; const jsmntok_t *inv_arr_tok, *inv_tok; @@ -1243,8 +1250,11 @@ listinvoices_done(struct command *cmd, const char *buf, } static struct command_result * -listsendpays_done(struct command *cmd, const char *buf, - const jsmntok_t *result, struct sha256 *payment_hash) +listsendpays_done(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + struct sha256 *payment_hash) { size_t i; const jsmntok_t *pays_arr_tok, *pays_tok; @@ -1310,8 +1320,11 @@ struct event_info { }; static struct command_result * -listpeerchannels_done(struct command *cmd, const char *buf, - const jsmntok_t *result, struct event_info *info) +listpeerchannels_done(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + struct event_info *info) { struct acct_balance **balances, *bal; struct amount_msat credit_diff, debit_diff; diff --git a/plugins/chanbackup.c b/plugins/chanbackup.c index 98835af1b..34d1b50a4 100644 --- a/plugins/chanbackup.c +++ b/plugins/chanbackup.c @@ -216,6 +216,7 @@ static u8 *decrypt_scb(struct plugin *p) } static struct command_result *after_recover_rpc(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *params, void *cb_arg UNUSED) @@ -263,7 +264,7 @@ static struct command_result *json_emergencyrecover(struct command *cmd, req = jsonrpc_request_start(cmd, "recoverchannel", after_recover_rpc, - &forward_error, NULL); + forward_error, NULL); json_array_start(req->js, "scb"); for (size_t i=0; ioff = 0; - return send_response(command, NULL, NULL, reply); + return send_response(command, NULL, NULL, NULL, reply); } static struct command_result *commando_error(struct command *cmd, @@ -216,7 +218,7 @@ static struct command_result *commando_error(struct command *cmd, reply->off = 0; reply->len = tal_bytelen(reply->buf) - 1; - return send_response(cmd, NULL, NULL, reply); + return send_response(cmd, NULL, NULL, NULL, reply); } struct cond_info { @@ -320,6 +322,7 @@ static struct command_result *execute_command(struct command *cmd, } static struct command_result *checkrune_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct cond_info *cinfo) @@ -347,6 +350,7 @@ static struct command_result *checkrune_done(struct command *cmd, } static struct command_result *checkrune_failed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct cond_info *cinfo) @@ -617,6 +621,7 @@ struct outgoing { }; static struct command_result *send_more_cmd(struct command *cmd, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct outgoing *outgoing) @@ -703,19 +708,20 @@ static struct command_result *json_commando(struct command *cmd, outgoing->msgs[i] = cmd_msg; } - return send_more_cmd(cmd, NULL, NULL, outgoing); + return send_more_cmd(cmd, NULL, NULL, NULL, outgoing); } /* Handles error or success */ static struct command_result *forward_reply(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *arg) { const jsmntok_t *err = json_get_member(buf, result, "error"); if (err) - return forward_error(cmd, buf, err, arg); - return forward_result(cmd, buf, json_get_member(buf, result, "result"), arg); + return forward_error(cmd, method, buf, err, arg); + return forward_result(cmd, method, buf, json_get_member(buf, result, "result"), arg); } static struct command_result *forward_command(struct command *cmd, diff --git a/plugins/establish_onion_path.c b/plugins/establish_onion_path.c index c58702b92..2659a839e 100644 --- a/plugins/establish_onion_path.c +++ b/plugins/establish_onion_path.c @@ -20,6 +20,7 @@ struct connect_info { }; static struct command_result *connect_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct connect_info *ci) @@ -34,6 +35,7 @@ static struct command_result *connect_ok(struct command *cmd, } static struct command_result *command_failed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct connect_info *ci) @@ -185,6 +187,7 @@ fail: } static struct command_result *listpeers_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct connect_info *ci) diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index 8ce7fc963..93fc23bab 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -407,6 +407,7 @@ static struct command_result *timeout_sent_invreq(struct command *timer_cmd, } static struct command_result *sendonionmsg_done(struct command *cmd, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct sent *sent) @@ -493,6 +494,7 @@ struct establishing_paths { struct sent *sent; struct tlv_onionmsg_tlv *final_tlv; struct command_result *(*done)(struct command *cmd, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct sent *sent); @@ -605,6 +607,7 @@ static struct command_result *send_message(struct command *cmd, struct tlv_onionmsg_tlv *final_tlv STEALS, struct command_result *(*done) (struct command *cmd, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct sent *sent)) @@ -637,6 +640,7 @@ static struct command_result *timeout_sent_inv(struct command *timer_cmd, } static struct command_result *prepare_inv_timeout(struct command *cmd, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct sent *sent) @@ -644,10 +648,11 @@ static struct command_result *prepare_inv_timeout(struct command *cmd, command_timer(cmd, time_from_sec(sent->wait_timeout), timeout_sent_inv, sent); - return sendonionmsg_done(cmd, buf, result, sent); + return sendonionmsg_done(cmd, method, buf, result, sent); } static struct command_result *invreq_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct sent *sent) @@ -1106,6 +1111,7 @@ struct command_result *invoice_payment(struct command *cmd, } static struct command_result *createinvoice_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct sent *sent) diff --git a/plugins/funder.c b/plugins/funder.c index 20c38a3d6..285c2a13c 100644 --- a/plugins/funder.c +++ b/plugins/funder.c @@ -74,6 +74,7 @@ new_channel_open(const tal_t *ctx, static struct command_result * unreserve_done(struct command *aux_cmd, + const char *method, const char *buf, const jsmntok_t *result, struct pending_open *open) @@ -140,6 +141,7 @@ command_hook_cont_psbt(struct command *cmd, struct wally_psbt *psbt) static struct command_result * datastore_del_fail(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, void *data UNUSED) @@ -150,6 +152,7 @@ datastore_del_fail(struct command *cmd, static struct command_result * datastore_del_success(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *data UNUSED) @@ -165,14 +168,15 @@ datastore_del_success(struct command *cmd, static struct command_result * datastore_add_fail(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct wally_psbt *signed_psbt) { /* Oops, something's broken */ plugin_log(cmd->plugin, LOG_BROKEN, - "`datastore` add failed: %*.s", - json_tok_full_len(error), + "%s failed: %*.s", + method, json_tok_full_len(error), json_tok_full(buf, error)); return command_hook_cont_psbt(cmd, signed_psbt); @@ -180,6 +184,7 @@ datastore_add_fail(struct command *cmd, static struct command_result * datastore_add_success(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct wally_psbt *signed_psbt) @@ -242,6 +247,7 @@ remember_channel_utxos(struct command *cmd, static struct command_result * signpsbt_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct pending_open *open) @@ -417,6 +423,7 @@ static struct open_info *new_open_info(const tal_t *ctx) static struct command_result * psbt_funded(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct open_info *info) @@ -462,6 +469,7 @@ psbt_funded(struct command *cmd, static struct command_result * psbt_fund_failed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct open_info *info) @@ -469,9 +477,10 @@ psbt_fund_failed(struct command *cmd, /* Attempt to fund a psbt for this open failed. * We probably ran out of funds (race?) */ plugin_log(cmd->plugin, LOG_INFORM, - "Unable to secure %s from wallet," + "%s: unable to secure %s from wallet," " continuing channel open to %s" " without our participation. err %.*s", + method, fmt_amount_sat(tmpctx, info->our_funding), fmt_node_id(tmpctx, &info->id), json_tok_full_len(error), @@ -567,6 +576,7 @@ build_utxopsbt_request(struct command *cmd, static struct command_result * listfunds_success(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct open_info *info) @@ -750,6 +760,7 @@ listfunds_success(struct command *cmd, static struct command_result * listfunds_failed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct open_info *info) @@ -903,6 +914,7 @@ json_openchannel2_call(struct command *cmd, static struct command_result * datastore_list_fail(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct open_info *info) @@ -927,6 +939,7 @@ datastore_list_fail(struct command *cmd, static struct command_result * datastore_list_success(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct open_info *info) @@ -1317,7 +1330,9 @@ parse_lease_rates(struct command *cmd, const char *buffer, } static struct command_result * -leaserates_set(struct command *cmd, const char *buf, +leaserates_set(struct command *cmd, + const char *method, + const char *buf, const jsmntok_t *result, struct funder_policy *policy) { diff --git a/plugins/keysend.c b/plugins/keysend.c index a2020f155..b92f22c73 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -198,6 +198,7 @@ struct payment_modifier *pay_mods[] = { static struct command_result * preapprovekeysend_succeed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct payment *p) @@ -378,7 +379,9 @@ static bool keysend_accept_extra_tlv_type(u64 type) } static struct command_result * -htlc_accepted_invoice_created(struct command *cmd, const char *buf, +htlc_accepted_invoice_created(struct command *cmd, + const char *method, + const char *buf, const jsmntok_t *result, struct keysend_in *ki) { @@ -445,7 +448,9 @@ htlc_accepted_invoice_created(struct command *cmd, const char *buf, } static struct command_result * -htlc_accepted_invoice_failed(struct command *cmd, const char *buf, +htlc_accepted_invoice_failed(struct command *cmd, + const char *method, + const char *buf, const jsmntok_t *error, struct keysend_in *ki) { diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 7a086a262..ed78d7681 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -216,13 +216,14 @@ paymod_err(struct payment *p, const char *fmt, ...) /* Generic handler for RPC failures that should end up failing the payment. */ static struct command_result *payment_rpc_failure(struct command *cmd, + const char *method, const char *buffer, const jsmntok_t *toks, struct payment *p) { return payment_fail(p, - "Failing a partial payment due to a failed RPC call: %.*s", - toks->end - toks->start, buffer + toks->start); + "Failing a partial payment due to a failed RPC call %s: %.*s", + method, toks->end - toks->start, buffer + toks->start); } struct payment_tree_result payment_collect_result(struct payment *p) @@ -279,6 +280,7 @@ struct payment_tree_result payment_collect_result(struct payment *p) } static struct command_result *payment_waitblockheight_cb(struct command *cmd, + const char *method, const char *buffer, const jsmntok_t *toks, struct payment *p) @@ -300,6 +302,7 @@ static struct command_result *payment_waitblockheight_cb(struct command *cmd, static struct command_result * payment_getblockheight_success(struct command *cmd, + const char *method, const char *buffer, const jsmntok_t *toks, struct payment *p) @@ -954,8 +957,11 @@ static bool payment_listpeerchannels_balance_sum(struct payment *p, } static struct command_result * -payment_listpeerchannels_success(struct command *cmd, const char *buffer, - const jsmntok_t *toks, struct payment *p) +payment_listpeerchannels_success(struct command *cmd, + const char *method, + const char *buffer, + const jsmntok_t *toks, + struct payment *p) { /* The maximum amount we may end up trying to send. This * includes the value and the full fee budget. If the @@ -1566,7 +1572,9 @@ static u8 *channel_update_from_onion_error(const tal_t *ctx, static struct command_result * -payment_addgossip_success(struct command *cmd, const char *buffer, +payment_addgossip_success(struct command *cmd, + const char *method, + const char *buffer, const jsmntok_t *toks, struct payment *p) { const struct node_id *errnode; @@ -1592,18 +1600,22 @@ payment_addgossip_success(struct command *cmd, const char *buffer, /* If someone gives us an invalid update, all we can do is log it */ static struct command_result * -payment_addgossip_failure(struct command *cmd, const char *buffer, +payment_addgossip_failure(struct command *cmd, + const char *method, + const char *buffer, const jsmntok_t *toks, struct payment *p) { paymod_log(p, LOG_DBG, "Invalid channel_update: %.*s", json_tok_full_len(toks), json_tok_full(buffer, toks)); - return payment_addgossip_success(cmd, NULL, NULL, p); + return payment_addgossip_success(cmd, NULL, NULL, NULL, p); } static struct command_result * -payment_waitsendpay_finished(struct command *cmd, const char *buffer, +payment_waitsendpay_finished(struct command *cmd, + const char *method, + const char *buffer, const jsmntok_t *toks, struct payment *p) { u8 *update; @@ -1646,13 +1658,14 @@ payment_waitsendpay_finished(struct command *cmd, const char *buffer, return send_outreq(req); } - return payment_addgossip_success(cmd, NULL, NULL, p); + return payment_addgossip_success(cmd, NULL, NULL, NULL, p); } static struct command_result *payment_sendonion_success(struct command *cmd, - const char *buffer, - const jsmntok_t *toks, - struct payment *p) + const char *method, + const char *buffer, + const jsmntok_t *toks, + struct payment *p) { struct out_req *req; req = jsonrpc_request_start(payment_cmd(p), "waitsendpay", @@ -1665,6 +1678,7 @@ static struct command_result *payment_sendonion_success(struct command *cmd, } static struct command_result *payment_createonion_success(struct command *cmd, + const char *method, const char *buffer, const jsmntok_t *toks, struct payment *p) @@ -2481,7 +2495,9 @@ REGISTER_PAYMENT_MODIFIER(retry, struct retry_mod_data *, retry_data_init, retry_step_cb); static struct command_result * -local_channel_hints_listpeerchannels(struct command *cmd, const char *buffer, +local_channel_hints_listpeerchannels(struct command *cmd, + const char *method, + const char *buffer, const jsmntok_t *toks, struct payment *p) { struct listpeers_channel **chans; @@ -3176,6 +3192,7 @@ static struct shadow_route_data *shadow_route_init(struct payment *p) /* Mutual recursion */ static struct command_result *shadow_route_listchannels(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct payment *p); @@ -3192,9 +3209,10 @@ static struct command_result *shadow_route_extend(struct shadow_route_data *d, } static struct command_result *shadow_route_listchannels(struct command *cmd, - const char *buf, - const jsmntok_t *result, - struct payment *p) + const char *method, + const char *buf, + const jsmntok_t *result, + struct payment *p) { struct shadow_route_data *d = payment_mod_shadowroute_get_data(p); struct payment_constraints *cons = &d->constraints; @@ -3399,6 +3417,7 @@ static struct command_result *direct_pay_override(struct payment *p) * for a direct channel that is a) connected and b) in state normal. We will * check the capacity based on the channel_hints in the override. */ static struct command_result *direct_pay_listpeerchannels(struct command *cmd, + const char *method, const char *buffer, const jsmntok_t *toks, struct payment *p) @@ -3702,6 +3721,7 @@ REGISTER_PAYMENT_MODIFIER(adaptive_splitter, struct adaptive_split_mod_data *, static struct command_result * payee_incoming_limit_count(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct payment *p) diff --git a/plugins/libplugin.c b/plugins/libplugin.c index a912082b7..384850033 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -258,6 +258,7 @@ static void ld_rpc_send(struct plugin *plugin, struct json_stream *stream) /* When cmd for request is gone, we use this as noop callback */ static struct command_result *ignore_cb(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg) @@ -265,6 +266,62 @@ static struct command_result *ignore_cb(struct command *command, return &complete; } +/* Ignore the result, and terminate the timer/aux/hook */ +struct command_result *ignore_and_complete(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + void *arg) +{ + switch (cmd->type) { + case COMMAND_TYPE_NORMAL: + case COMMAND_TYPE_CHECK: + case COMMAND_TYPE_USAGE_ONLY: + plugin_err(cmd->plugin, + "%s: cannot ignore_and_complete type %u", + method, cmd->type); + case COMMAND_TYPE_HOOK: + return command_hook_success(cmd); + /* Terminate with aux_command_done */ + case COMMAND_TYPE_AUX: + return aux_command_done(cmd); + case COMMAND_TYPE_NOTIFICATION: + return notification_handled(cmd); + case COMMAND_TYPE_TIMER: + return timer_complete(cmd); + } + abort(); +} + +/* Broken the result, and terminate the command */ +struct command_result *log_broken_and_complete(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + void *arg) +{ + plugin_log(cmd->plugin, LOG_BROKEN, + "%s failed with %.*s", + method, + json_tok_full_len(result), + json_tok_full(buf, result)); + return ignore_and_complete(cmd, method, buf, result, arg); +} + +/* Call plugin_err */ +struct command_result *plugin_broken_cb(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + void *arg) +{ + plugin_err(cmd->plugin, + "%s failed with %.*s", + method, + json_tok_full_len(result), + json_tok_full(buf, result)); +} + static void disable_request_cb(struct command *cmd, struct out_req *out) { out->errcb = NULL; @@ -308,10 +365,12 @@ jsonrpc_request_start_(struct command *cmd, const char *id_prefix, const char *filter, struct command_result *(*cb)(struct command *command, + const char *methodname, const char *buf, const jsmntok_t *result, void *arg), struct command_result *(*errcb)(struct command *command, + const char *methodname, const char *buf, const jsmntok_t *result, void *arg), @@ -321,6 +380,7 @@ jsonrpc_request_start_(struct command *cmd, assert(cmd); out = tal(cmd, struct out_req); + out->method = tal_strdup(out, method); out->id = json_id(out, cmd->plugin, method, id_prefix ? id_prefix : cmd->id); out->cmd = cmd; out->cb = cb; @@ -577,6 +637,7 @@ struct command_result *timer_complete(struct command *cmd) } struct command_result *forward_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, void *arg UNNEEDED) @@ -587,6 +648,7 @@ struct command_result *forward_error(struct command *cmd, } struct command_result *forward_result(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *arg UNNEEDED) @@ -846,26 +908,18 @@ void rpc_enable_batching(struct plugin *plugin) sync_req(tmpctx, plugin, "batching", take(params), &p); } -static struct command_result *datastore_fail(struct command *command, - const char *buf, - const jsmntok_t *result, - void *unused) -{ - plugin_err(command->plugin, "datastore failed: %.*s", - json_tok_full_len(result), - json_tok_full(buf, result)); -} - struct command_result *jsonrpc_set_datastore_(struct command *cmd, const char *path, const void *value, bool value_is_string, const char *mode, struct command_result *(*cb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), struct command_result *(*errcb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), @@ -876,7 +930,7 @@ struct command_result *jsonrpc_set_datastore_(struct command *cmd, if (!cb) cb = ignore_cb; if (!errcb) - errcb = datastore_fail; + errcb = plugin_broken_cb; req = jsonrpc_request_start(cmd, "datastore", cb, errcb, arg); @@ -900,6 +954,7 @@ struct get_ds_info { }; static struct command_result *listdatastore_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct get_ds_info *dsi) @@ -957,7 +1012,7 @@ struct command_result *jsonrpc_get_datastore_(struct command *cmd, /* listdatastore doesn't fail (except API misuse) */ req = jsonrpc_request_start(cmd, "listdatastore", - listdatastore_done, datastore_fail, dsi); + listdatastore_done, plugin_broken_cb, dsi); tal_steal(req, dsi); json_add_keypath(req->js->jout, "key", path); @@ -1006,9 +1061,9 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks) contenttok = json_get_member(buf, toks, "error"); if (contenttok) { if (out->errcb) - res = out->errcb(out->cmd, buf, contenttok, out->arg); + res = out->errcb(out->cmd, out->method, buf, contenttok, out->arg); else - res = out->cb(out->cmd, buf, toks, out->arg); + res = out->cb(out->cmd, out->method, buf, toks, out->arg); } else { contenttok = json_get_member(buf, toks, "result"); if (!contenttok) @@ -1017,9 +1072,9 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks) json_tok_full(buf, toks)); /* errcb is NULL if it's a single whole-object callback */ if (out->errcb) - res = out->cb(out->cmd, buf, contenttok, out->arg); + res = out->cb(out->cmd, out->method, buf, contenttok, out->arg); else - res = out->cb(out->cmd, buf, toks, out->arg); + res = out->cb(out->cmd, out->method, buf, toks, out->arg); } if (res == &complete) { @@ -1050,10 +1105,12 @@ struct request_batch { size_t num_remaining; struct command_result *(*cb)(struct command *, + const char *, const char *, const jsmntok_t *, void *); struct command_result *(*errcb)(struct command *, + const char *, const char *, const jsmntok_t *, void *); @@ -1064,10 +1121,12 @@ struct request_batch { struct request_batch *request_batch_new_(const tal_t *ctx, struct command_result *(*cb)(struct command *, + const char *, const char *, const jsmntok_t *, void *), struct command_result *(*errcb)(struct command *, + const char *, const char *, const jsmntok_t *, void *), @@ -1103,23 +1162,25 @@ static struct command_result *batch_one_complete(struct command *cmd, } static struct command_result *batch_one_success(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct request_batch *batch) { /* If this frees stuff (e.g. fails), just return */ - if (batch->cb && batch->cb(cmd, buf, result, batch->arg) == &complete) + if (batch->cb && batch->cb(cmd, method, buf, result, batch->arg) == &complete) return &complete; return batch_one_complete(cmd, batch); } static struct command_result *batch_one_failed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct request_batch *batch) { /* If this frees stuff (e.g. fails), just return */ - if (batch->errcb && batch->errcb(cmd, buf, result, batch->arg) == &complete) + if (batch->errcb && batch->errcb(cmd, method, buf, result, batch->arg) == &complete) return &complete; return batch_one_complete(cmd, batch); } diff --git a/plugins/libplugin.h b/plugins/libplugin.h index 7d13ae226..b7c2fc44e 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -34,15 +34,19 @@ struct out_req { const char *id; /* The command which is why we're calling this rpc. */ struct command *cmd; + /* The method this is calling */ + const char *method; /* The request stream. */ struct json_stream *js; /* The callback when we get a response. */ struct command_result *(*cb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg); /* The callback when we get an error. */ struct command_result *(*errcb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *error, void *arg); @@ -58,8 +62,9 @@ enum command_type { COMMAND_TYPE_AUX, /* Terminate with notification_handled */ COMMAND_TYPE_NOTIFICATION, - /* These self-terminate */ + /* Terminate with timer_complete */ COMMAND_TYPE_TIMER, + /* These self-terminate */ COMMAND_TYPE_CHECK, COMMAND_TYPE_USAGE_ONLY, }; @@ -109,16 +114,39 @@ struct plugin_hook { /* Return the feature set of the current lightning node */ const struct feature_set *plugin_feature_set(const struct plugin *p); +/* Ignore the result, and terminate the command */ +struct command_result *ignore_and_complete(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + void *arg); + +/* Broken the result, and terminate the command */ +struct command_result *log_broken_and_complete(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + void *arg); + +/* Call plugin_err */ +struct command_result *plugin_broken_cb(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + void *arg); + /* Helper to create a JSONRPC2 request stream. Send it with `send_outreq`. */ struct out_req *jsonrpc_request_start_(struct command *cmd, const char *method, const char *id_prefix, const char *filter, struct command_result *(*cb)(struct command *command, + const char *methodname, const char *buf, const jsmntok_t *result, void *arg), struct command_result *(*errcb)(struct command *command, + const char *methodname, const char *buf, const jsmntok_t *result, void *arg), @@ -130,11 +158,13 @@ struct out_req *jsonrpc_request_start_(struct command *cmd, typesafe_cb_preargs(struct command_result *, void *, \ (cb), (arg), \ struct command *command, \ + const char *mthod, \ const char *buf, \ const jsmntok_t *result), \ typesafe_cb_preargs(struct command_result *, void *, \ (errcb), (arg), \ struct command *command, \ + const char *mthod, \ const char *buf, \ const jsmntok_t *result), \ (arg)) @@ -144,11 +174,13 @@ struct out_req *jsonrpc_request_start_(struct command *cmd, typesafe_cb_preargs(struct command_result *, void *, \ (cb), (arg), \ struct command *command, \ + const char *mthod, \ const char *buf, \ const jsmntok_t *result), \ typesafe_cb_preargs(struct command_result *, void *, \ (errcb), (arg), \ struct command *command, \ + const char *mthod, \ const char *buf, \ const jsmntok_t *result), \ (arg)) @@ -160,6 +192,7 @@ struct out_req *jsonrpc_request_start_(struct command *cmd, typesafe_cb_preargs(struct command_result *, void *, \ (cb), (arg), \ struct command *command, \ + const char *mthod, \ const char *buf, \ const jsmntok_t *result), \ NULL, \ @@ -168,10 +201,12 @@ struct out_req *jsonrpc_request_start_(struct command *cmd, /* Batch of requests: cb and errcb are optional, finalcb is called when all complete. */ struct request_batch *request_batch_new_(const tal_t *ctx, struct command_result *(*cb)(struct command *, + const char *method, const char *, const jsmntok_t *, void *), struct command_result *(*errcb)(struct command *, + const char *method, const char *, const jsmntok_t *, void *), @@ -184,11 +219,13 @@ struct request_batch *request_batch_new_(const tal_t *ctx, typesafe_cb_preargs(struct command_result *, void *, \ (cb), (arg), \ struct command *command, \ + const char *method, \ const char *buf, \ const jsmntok_t *result), \ typesafe_cb_preargs(struct command_result *, void *, \ (errcb), (arg), \ struct command *command, \ + const char *method, \ const char *buf, \ const jsmntok_t *result), \ typesafe_cb_preargs(struct command_result *, void *, \ @@ -238,10 +275,12 @@ struct command_result *jsonrpc_set_datastore_(struct command *cmd, bool value_is_string, const char *mode, struct command_result *(*cb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), struct command_result *(*errcb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), @@ -253,11 +292,13 @@ struct command_result *jsonrpc_set_datastore_(struct command *cmd, typesafe_cb_preargs(struct command_result *, void *, \ (cb), (arg), \ struct command *command, \ + const char *method, \ const char *buf, \ const jsmntok_t *result), \ typesafe_cb_preargs(struct command_result *, void *, \ (errcb), (arg), \ struct command *command, \ + const char *method, \ const char *buf, \ const jsmntok_t *result), \ (arg)) @@ -267,11 +308,13 @@ struct command_result *jsonrpc_set_datastore_(struct command *cmd, typesafe_cb_preargs(struct command_result *, void *, \ (cb), (arg), \ struct command *command, \ + const char *method, \ const char *buf, \ const jsmntok_t *result), \ typesafe_cb_preargs(struct command_result *, void *, \ (errcb), (arg), \ struct command *command, \ + const char *method, \ const char *buf, \ const jsmntok_t *result), \ (arg)) @@ -424,17 +467,19 @@ struct command_result *send_outreq(const struct out_req *req); /* Callback to just forward error and close request; @cmd cannot be NULL */ struct command_result *forward_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, void *arg) - NON_NULL_ARGS(1, 2, 3); + NON_NULL_ARGS(1, 2, 3, 4); /* Callback to just forward result and close request; @cmd cannot be NULL */ struct command_result *forward_result(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *arg) - NON_NULL_ARGS(1, 2, 3); + NON_NULL_ARGS(1, 2, 3, 4); /* Callback for timer where we expect a 'command_result'. All timers * must return this eventually, though they may do so via a convoluted diff --git a/plugins/offers.c b/plugins/offers.c index c4248455e..3bead103f 100644 --- a/plugins/offers.c +++ b/plugins/offers.c @@ -68,6 +68,7 @@ struct gossmap *get_gossmap(struct plugin *plugin) } static struct command_result *finished(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *unused) @@ -76,6 +77,7 @@ static struct command_result *finished(struct command *cmd, } static struct command_result *injectonionmessage_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *err, void *unused) @@ -93,10 +95,12 @@ struct command_result * inject_onionmessage_(struct command *cmd, const struct onion_message *omsg, struct command_result *(*cb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), struct command_result *(*errcb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), @@ -256,6 +260,7 @@ struct find_best_peer_data { }; static struct command_result *listincoming_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct find_best_peer_data *data) @@ -1299,6 +1304,7 @@ static void json_add_rune(struct command *cmd, struct json_stream *js, const str } static struct command_result *after_makesecret(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct decodable *decodable) diff --git a/plugins/offers.h b/plugins/offers.h index 038be35a8..d689046be 100644 --- a/plugins/offers.h +++ b/plugins/offers.h @@ -43,11 +43,13 @@ send_onion_reply(struct command *cmd, (success), (arg), \ struct command *, \ const char *, \ + const char *, \ const jsmntok_t *), \ typesafe_cb_preargs(struct command_result *, void *, \ (fail), (arg), \ struct command *, \ const char *, \ + const char *, \ const jsmntok_t *), \ (arg)) @@ -55,10 +57,12 @@ struct command_result * inject_onionmessage_(struct command *cmd, const struct onion_message *omsg, struct command_result *(*cb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), struct command_result *(*errcb)(struct command *command, + const char *method, const char *buf, const jsmntok_t *result, void *arg), diff --git a/plugins/offers_inv_hook.c b/plugins/offers_inv_hook.c index 658ae255b..67fda233b 100644 --- a/plugins/offers_inv_hook.c +++ b/plugins/offers_inv_hook.c @@ -91,6 +91,7 @@ fail_internalerr(struct command *cmd, } static struct command_result *pay_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct inv *inv) @@ -107,6 +108,7 @@ static struct command_result *pay_done(struct command *cmd, } static struct command_result *pay_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct inv *inv) @@ -119,6 +121,7 @@ static struct command_result *pay_error(struct command *cmd, } static struct command_result *listinvreqs_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct inv *inv) @@ -198,6 +201,7 @@ static struct command_result *listinvreqs_done(struct command *cmd, } static struct command_result *listinvreqs_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *err, struct inv *inv) diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index fdbcbcd59..a0c18428b 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -161,6 +161,7 @@ static void json_add_label(struct json_stream *js, * used at the same time between the check and now. */ static struct command_result *error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *err, struct invreq *ir) @@ -173,6 +174,7 @@ static struct command_result *error(struct command *cmd, /* We can fail to create the invoice if we've already done so. */ static struct command_result *createinvoice_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct invreq *ir) @@ -198,6 +200,7 @@ static struct command_result *createinvoice_done(struct command *cmd, } static struct command_result *createinvoice_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *err, struct invreq *ir) @@ -208,10 +211,10 @@ static struct command_result *createinvoice_error(struct command *cmd, if (json_scan(tmpctx, buf, err, "{code:%}", JSON_SCAN(json_to_u32, &code)) == NULL && code == INVOICE_LABEL_ALREADY_EXISTS) { - return createinvoice_done(cmd, buf, + return createinvoice_done(cmd, method, buf, json_get_member(buf, err, "data"), ir); } - return error(cmd, buf, err, ir); + return error(cmd, method, buf, err, ir); } static struct command_result *create_invoicereq(struct command *cmd, @@ -483,6 +486,7 @@ static struct command_result *check_period(struct command *cmd, } static struct command_result *prev_invoice_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct invreq *ir) @@ -690,6 +694,7 @@ static struct command_result *handle_amount_and_recurrence(struct command *cmd, } static struct command_result *currency_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct invreq *ir) @@ -760,6 +765,7 @@ static struct command_result *convert_currency(struct command *cmd, } static struct command_result *listoffers_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct invreq *ir) diff --git a/plugins/offers_offer.c b/plugins/offers_offer.c index 5541a1979..0f84843c7 100644 --- a/plugins/offers_offer.c +++ b/plugins/offers_offer.c @@ -235,6 +235,7 @@ struct offer_info { }; static struct command_result *check_result(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *arg UNNEEDED) @@ -256,7 +257,7 @@ static struct command_result *check_result(struct command *cmd, "Already exists, but isn't active"); /* Otherwise, push through the result. */ - return forward_result(cmd, buf, result, arg); + return forward_result(cmd, method, buf, result, arg); } static struct command_result *create_offer(struct command *cmd, @@ -339,13 +340,14 @@ static struct command_result *maybe_add_path(struct command *cmd, } static struct command_result *currency_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct offer_info *offinfo) { /* Fail in this case, by forwarding warnings. */ if (!json_get_member(buf, result, "msat")) - return forward_error(cmd, buf, result, offinfo); + return forward_error(cmd, method, buf, result, offinfo); return maybe_add_path(cmd, offinfo); } diff --git a/plugins/pay.c b/plugins/pay.c index 9d91fabdb..6f1590b3e 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -416,6 +416,7 @@ static void add_new_entry(struct json_stream *ret, } static struct command_result *listsendpays_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, char *invstring) @@ -808,6 +809,7 @@ static void on_payment_failure(struct payment *payment) } static struct command_result *selfpay_success(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct payment *p) @@ -864,8 +866,11 @@ static struct command_result *selfpay(struct command *cmd, struct payment *p) * about an eventual previous complete payment so we can return that * as a no-op. */ static struct command_result * -payment_listsendpays_previous(struct command *cmd, const char *buf, - const jsmntok_t *result, struct payment *p) +payment_listsendpays_previous(struct command *cmd, + const char *method, + const char *buf, + const jsmntok_t *result, + struct payment *p) { size_t i; const jsmntok_t *t, *arr, *err; @@ -1058,6 +1063,7 @@ static bool scidtok_eq(const char *buf, /* We are the entry point, so the next hop could actually be an scid alias, * so we can't just use gossmap. */ static struct command_result *listpeerchannels_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct payment *p) @@ -1106,6 +1112,7 @@ static struct command_result *listpeerchannels_done(struct command *cmd, static struct command_result * decrypt_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct payment *p) @@ -1189,6 +1196,7 @@ decrypt_done(struct command *cmd, static struct command_result * preapproveinvoice_succeed(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct payment *p) diff --git a/plugins/recover.c b/plugins/recover.c index e2f069859..6ceee127a 100644 --- a/plugins/recover.c +++ b/plugins/recover.c @@ -49,6 +49,7 @@ static const char *nodes_for_gossip[] = { static struct command_result *connect_success(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *params, void *cb_arg UNUSED) @@ -58,6 +59,7 @@ static struct command_result *connect_success(struct command *cmd, } static struct command_result *connect_fail(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *params, void *cb_arg UNUSED) @@ -67,6 +69,7 @@ static struct command_result *connect_fail(struct command *cmd, } static struct command_result *after_emergency_recover(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *params, void *cb_arg UNUSED) @@ -77,9 +80,10 @@ static struct command_result *after_emergency_recover(struct command *cmd, } static struct command_result *after_restorefrompeer(struct command *cmd, - const char *buf, - const jsmntok_t *params, - void *cb_arg UNUSED) + const char *method, + const char *buf, + const jsmntok_t *params, + void *cb_arg UNUSED) { plugin_log(plugin, LOG_DBG, "restorefrompeer called"); @@ -186,6 +190,7 @@ static void entering_recovery_mode(struct command *cmd) } static struct command_result *after_listpeerchannels(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *params, void *cb_arg UNUSED) diff --git a/plugins/renepay/mods.c b/plugins/renepay/mods.c index 4b167aec5..dd601f23b 100644 --- a/plugins/renepay/mods.c +++ b/plugins/renepay/mods.c @@ -73,6 +73,7 @@ struct command_result *payment_continue(struct payment *payment) /* Generic handler for RPC failures that should end up failing the payment. */ static struct command_result *payment_rpc_failure(struct command *cmd, + const char *method UNUSED, const char *buffer, const jsmntok_t *toks, struct payment *payment) @@ -180,6 +181,7 @@ static bool success_data_from_listsendpays(const char *buf, } static struct command_result *previoussuccess_done(struct command *cmd, + const char *method UNUSED, const char *buf, const jsmntok_t *result, struct payment *payment) @@ -252,6 +254,7 @@ REGISTER_PAYMENT_MODIFIER(initial_sanity_checks, initial_sanity_checks_cb); */ static struct command_result *selfpay_success(struct command *cmd, + const char *method UNUSED, const char *buf, const jsmntok_t *tok, struct route *route) @@ -275,6 +278,7 @@ static struct command_result *selfpay_success(struct command *cmd, return payment_success(payment, &preimage); } static struct command_result *selfpay_failure(struct command *cmd, + const char *method UNUSED, const char *buf, const jsmntok_t *tok, struct route *route) @@ -431,6 +435,7 @@ static void gossmod_cb(struct gossmap_localmods *mods, } static struct command_result *getmychannels_done(struct command *cmd, + const char *method UNUSED, const char *buf, const jsmntok_t *result, struct payment *payment) @@ -576,6 +581,7 @@ function_error: } static struct command_result *routehints_done(struct command *cmd UNUSED, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct payment *payment) @@ -867,6 +873,7 @@ REGISTER_PAYMENT_MODIFIER(collect_results, collect_results_cb); * The default ending of a payment. */ static struct command_result *end_done(struct command *cmd UNUSED, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct payment *payment) @@ -912,6 +919,7 @@ REGISTER_PAYMENT_MODIFIER(checktimeout, checktimeout_cb); */ static struct command_result *pendingsendpays_done(struct command *cmd, + const char *method UNUSED, const char *buf, const jsmntok_t *result, struct payment *payment) diff --git a/plugins/renepay/routefail.c b/plugins/renepay/routefail.c index 6b362dc86..29d515349 100644 --- a/plugins/renepay/routefail.c +++ b/plugins/renepay/routefail.c @@ -110,6 +110,7 @@ static u8 *channel_update_from_onion_error(const tal_t *ctx, } static struct command_result *update_gossip_done(struct command *cmd UNUSED, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct routefail *r) @@ -118,6 +119,7 @@ static struct command_result *update_gossip_done(struct command *cmd UNUSED, } static struct command_result *update_gossip_failure(struct command *cmd UNUSED, + const char *method UNUSED, const char *buf, const jsmntok_t *result, struct routefail *r) @@ -136,7 +138,7 @@ static struct command_result *update_gossip_failure(struct command *cmd UNUSED, r->payment, scidd, LOG_INFORM, "addgossip failed (%.*s)", json_tok_full_len(result), json_tok_full(buf, result)); - return update_gossip_done(cmd, buf, result, r); + return update_gossip_done(cmd, method, buf, result, r); } static struct command_result *update_gossip(struct routefail *r) diff --git a/plugins/renepay/routetracker.c b/plugins/renepay/routetracker.c index 3184eda7d..5309af1a8 100644 --- a/plugins/renepay/routetracker.c +++ b/plugins/renepay/routetracker.c @@ -194,6 +194,7 @@ static void route_pending_register(struct routetracker *routetracker, /* Callback function for sendpay request success. */ static struct command_result *sendpay_done(struct command *cmd, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct route *route) @@ -209,6 +210,7 @@ static struct command_result *sendpay_done(struct command *cmd, * 2. The first peer is disconnected. */ static struct command_result *sendpay_failed(struct command *cmd, + const char *method UNUSED, const char *buf, const jsmntok_t *tok, struct route *route) diff --git a/plugins/spender/fundchannel.c b/plugins/spender/fundchannel.c index 6fc722fa9..9dd48c22c 100644 --- a/plugins/spender/fundchannel.c +++ b/plugins/spender/fundchannel.c @@ -18,6 +18,7 @@ const size_t num_fundchannel_commands = ARRAY_SIZE(fundchannel_commands); static struct command_result * fundchannel_get_result(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *nothing UNUSED); @@ -122,6 +123,7 @@ static bool json_to_tok(const char *buffer, const jsmntok_t *tok, const jsmntok_ static struct command_result * fundchannel_get_result(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, void *nothing UNUSED) diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 952b9963b..ef854bee9 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -152,9 +152,10 @@ mfc_cleanup_complete(struct multifundchannel_cleanup *cleanup) static struct command_result * mfc_cleanup_done(struct command *cmd, - const char *buf UNUSED, - const jsmntok_t *res UNUSED, - struct multifundchannel_cleanup *cleanup) + const char *method, + const char *buf UNUSED, + const jsmntok_t *res UNUSED, + struct multifundchannel_cleanup *cleanup) { --cleanup->pending; if (cleanup->pending == 0) @@ -395,6 +396,7 @@ mfc_err_raw(struct multifundchannel_command *mfc, const char *json_string) } struct command_result * mfc_forward_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_command *mfc) { @@ -517,6 +519,7 @@ multifundchannel_finished(struct multifundchannel_command *mfc) static struct command_result * after_sendpsbt(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_command *mfc) @@ -551,6 +554,7 @@ after_sendpsbt(struct command *cmd, static struct command_result * after_signpsbt(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_command *mfc) @@ -737,6 +741,7 @@ fundchannel_complete_done(struct multifundchannel_destination *dest) static struct command_result * fundchannel_complete_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_destination *dest) @@ -763,6 +768,7 @@ fundchannel_complete_ok(struct command *cmd, static struct command_result * fundchannel_complete_err(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_destination *dest) @@ -1031,6 +1037,7 @@ struct channel_type *json_bits_to_channel_type(const tal_t *ctx, static struct command_result * fundchannel_start_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_destination *dest) @@ -1065,6 +1072,7 @@ fundchannel_start_ok(struct command *cmd, static struct command_result * fundchannel_start_err(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_destination *dest) @@ -1195,6 +1203,7 @@ perform_fundpsbt(struct multifundchannel_command *mfc, u32 feerate); static struct command_result * retry_fundpsbt_capped_all(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_command *mfc) @@ -1206,6 +1215,7 @@ retry_fundpsbt_capped_all(struct command *cmd, static struct command_result * after_fundpsbt(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_command *mfc) @@ -1422,6 +1432,7 @@ perform_fundpsbt(struct multifundchannel_command *mfc, u32 feerate) static struct command_result * after_getfeerate(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_command *mfc) @@ -1528,6 +1539,7 @@ connect_done(struct multifundchannel_destination *dest) static struct command_result * connect_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_destination *dest) @@ -1572,6 +1584,7 @@ connect_ok(struct command *cmd, static struct command_result * connect_err(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_destination *dest) diff --git a/plugins/spender/multifundchannel.h b/plugins/spender/multifundchannel.h index 0549a4165..966ebd4b3 100644 --- a/plugins/spender/multifundchannel.h +++ b/plugins/spender/multifundchannel.h @@ -240,6 +240,7 @@ struct multifundchannel_command { /* Use this instead of forward_error. */ struct command_result * mfc_forward_error(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_command *); diff --git a/plugins/spender/multiwithdraw.c b/plugins/spender/multiwithdraw.c index bf3747573..c6f448131 100644 --- a/plugins/spender/multiwithdraw.c +++ b/plugins/spender/multiwithdraw.c @@ -220,6 +220,7 @@ struct multiwithdraw_cleanup { static struct command_result * mw_after_cleanup(struct command *cmd UNUSED, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct multiwithdraw_cleanup *cleanup); @@ -257,6 +258,7 @@ mw_perform_cleanup(struct multiwithdraw_command *mw, } static struct command_result * mw_after_cleanup(struct command *cmd UNUSED, + const char *method UNUSED, const char *buf UNUSED, const jsmntok_t *result UNUSED, struct multiwithdraw_cleanup *cleanup) @@ -273,6 +275,7 @@ mw_after_cleanup(struct command *cmd UNUSED, /* Use this instead of forward_error. */ static struct command_result * mw_forward_error(struct command *cmd UNUSED, + const char *method, const char *buf, const jsmntok_t *error, struct multiwithdraw_command *mw) @@ -318,6 +321,7 @@ specified, from a `utxopsbt` command. static struct command_result * mw_after_fundpsbt(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multiwithdraw_command *mw); @@ -393,6 +397,7 @@ mw_load_outputs(struct multiwithdraw_command *mw); static struct command_result * mw_after_fundpsbt(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multiwithdraw_command *mw) @@ -484,6 +489,7 @@ we need to `newaddr` and get one. */ static struct command_result * mw_after_newaddr(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multiwithdraw_command *mw); @@ -506,6 +512,7 @@ mw_get_change_addr(struct multiwithdraw_command *mw) static struct command_result * mw_after_newaddr(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multiwithdraw_command *mw) @@ -612,6 +619,7 @@ Sign and Send PSBT static struct command_result * mw_after_signpsbt(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multiwithdraw_command *mw); @@ -635,6 +643,7 @@ mw_sign_and_send(struct multiwithdraw_command *mw) static struct command_result * mw_after_signpsbt(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multiwithdraw_command *mw) diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 944679976..90c5cdb28 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -380,6 +380,7 @@ after_openchannel_signed(struct multifundchannel_command *mfc) static struct command_result * openchannel_signed_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_destination *dest) @@ -420,6 +421,7 @@ openchannel_signed_ok(struct command *cmd, static struct command_result * openchannel_signed_err(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_destination *dest) @@ -670,6 +672,7 @@ openchannel_update_returned(struct multifundchannel_destination *dest) static struct command_result * openchannel_update_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_destination *dest) @@ -763,6 +766,7 @@ openchannel_update_ok(struct command *cmd, static struct command_result * openchannel_update_err(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_destination *dest) @@ -901,6 +905,7 @@ openchannel_init_done(struct multifundchannel_destination *dest) static struct command_result * openchannel_init_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct multifundchannel_destination *dest) @@ -950,6 +955,7 @@ openchannel_init_ok(struct command *cmd, static struct command_result * openchannel_init_err(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *error, struct multifundchannel_destination *dest) diff --git a/plugins/sql.c b/plugins/sql.c index 23b290156..c6ec13f4b 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -706,6 +706,7 @@ static struct command_result *process_json_result(struct command *cmd, } static struct command_result *default_list_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct db_query *dbq) @@ -797,6 +798,7 @@ static struct command_result *channels_refresh(struct command *cmd, struct db_query *dbq); static struct command_result *listchannels_one_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct db_query *dbq) @@ -896,6 +898,7 @@ static struct command_result *nodes_refresh(struct command *cmd, struct db_query *dbq); static struct command_result *listnodes_one_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct db_query *dbq) diff --git a/plugins/test/run-route-calc.c b/plugins/test/run-route-calc.c index f6a68ff64..6cef7eeee 100644 --- a/plugins/test/run-route-calc.c +++ b/plugins/test/run-route-calc.c @@ -251,10 +251,12 @@ struct out_req *jsonrpc_request_start_(struct command *cmd UNNEEDED, const char *id_prefix UNNEEDED, const char *filter UNNEEDED, struct command_result *(*cb)(struct command *command UNNEEDED, + const char *methodname UNNEEDED, const char *buf UNNEEDED, const jsmntok_t *result UNNEEDED, void *arg) UNNEEDED, struct command_result *(*errcb)(struct command *command UNNEEDED, + const char *methodname UNNEEDED, const char *buf UNNEEDED, const jsmntok_t *result UNNEEDED, void *arg) UNNEEDED, diff --git a/plugins/test/run-route-overlong.c b/plugins/test/run-route-overlong.c index 3a7e6888e..3e7bacfc2 100644 --- a/plugins/test/run-route-overlong.c +++ b/plugins/test/run-route-overlong.c @@ -248,10 +248,12 @@ struct out_req *jsonrpc_request_start_(struct command *cmd UNNEEDED, const char *id_prefix UNNEEDED, const char *filter UNNEEDED, struct command_result *(*cb)(struct command *command UNNEEDED, + const char *methodname UNNEEDED, const char *buf UNNEEDED, const jsmntok_t *result UNNEEDED, void *arg) UNNEEDED, struct command_result *(*errcb)(struct command *command UNNEEDED, + const char *methodname UNNEEDED, const char *buf UNNEEDED, const jsmntok_t *result UNNEEDED, void *arg) UNNEEDED, diff --git a/plugins/topology.c b/plugins/topology.c index ac05bc05d..77d34e48b 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -150,6 +150,7 @@ static struct command_result *try_route(struct command *cmd, static struct command_result * listpeerchannels_getroute_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct getroute_info *info) @@ -172,17 +173,6 @@ listpeerchannels_getroute_done(struct command *cmd, return res; } -static struct command_result *listpeerchannels_err(struct command *cmd, - const char *buf, - const jsmntok_t *result, - void *unused) -{ - plugin_err(cmd->plugin, - "Bad listpeerchannels: %.*s", - json_tok_full_len(result), - json_tok_full(buf, result)); -} - static struct command_result *json_getroute(struct command *cmd, const char *buffer, const jsmntok_t *params) @@ -206,7 +196,7 @@ static struct command_result *json_getroute(struct command *cmd, /* Add local info */ req = jsonrpc_request_start(cmd, "listpeerchannels", listpeerchannels_getroute_done, - listpeerchannels_err, info); + plugin_broken_cb, info); return send_outreq(req); } @@ -383,9 +373,10 @@ static void gossmod_add_unknown_localchan(struct gossmap_localmods *mods, } static struct command_result *listpeerchannels_done(struct command *cmd, - const char *buf, - const jsmntok_t *result, - struct listchannels_opts *opts) + const char *method, + const char *buf, + const jsmntok_t *result, + struct listchannels_opts *opts) { struct node_map *connected; struct gossmap_chan *c; @@ -483,7 +474,7 @@ static struct command_result *json_listchannels(struct command *cmd, // If deprecations are not necessary, call listpeerchannels_done directly, // the output will not be used there. - return listpeerchannels_done(cmd, NULL, NULL, opts); + return listpeerchannels_done(cmd, NULL, NULL, NULL, opts); } static void json_add_node(struct json_stream *js, @@ -613,6 +604,7 @@ static struct amount_msat peer_capacity(const struct gossmap *gossmap, static struct command_result * listpeerchannels_listincoming_done(struct command *cmd, + const char *method, const char *buffer, const jsmntok_t *result, void *unused) @@ -698,7 +690,7 @@ static struct command_result *json_listincoming(struct command *cmd, /* Add local info */ req = jsonrpc_request_start(cmd, "listpeerchannels", listpeerchannels_listincoming_done, - listpeerchannels_err, NULL); + plugin_broken_cb, NULL); return send_outreq(req); } diff --git a/plugins/txprepare.c b/plugins/txprepare.c index b1529c59e..b71b67177 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -128,6 +128,7 @@ static struct command_result *param_outputs(struct command *cmd, /* Called after lightningd has broadcast the transaction. */ static struct command_result *sendpsbt_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct unreleased_tx *utx) @@ -145,6 +146,7 @@ static struct command_result *sendpsbt_done(struct command *cmd, /* Called after lightningd has signed the inputs. */ static struct command_result *signpsbt_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct unreleased_tx *utx) @@ -235,6 +237,7 @@ static struct command_result *finish_txprepare(struct command *cmd, /* fundpsbt/utxopsbt gets a viable PSBT for us. */ static struct command_result *psbt_created(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct txprepare *txp) @@ -360,6 +363,7 @@ static struct command_result *json_txprepare(struct command *cmd, /* Called after we've unreserved the inputs. */ static struct command_result *unreserve_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct unreleased_tx *utx) @@ -493,6 +497,7 @@ struct listfunds_info { /* Find all the utxos that are p2sh in our wallet */ static struct command_result *listfunds_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct listfunds_info *info) @@ -566,6 +571,7 @@ static struct command_result *listfunds_done(struct command *cmd, /* We've got an address for sending funds */ static struct command_result *newaddr_sweep_done(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *result, struct listfunds_info *info) diff --git a/tests/plugins/test_libplugin.c b/tests/plugins/test_libplugin.c index 4116eef9b..d6f269610 100644 --- a/tests/plugins/test_libplugin.c +++ b/tests/plugins/test_libplugin.c @@ -123,6 +123,7 @@ static struct command_result *json_all_notifs(struct command *cmd, } static struct command_result *testrpc_cb(struct command *cmd, + const char *method UNUSED, const char *buf, const jsmntok_t *params, void *cb_arg UNUSED) @@ -153,6 +154,7 @@ static struct command_result *json_testrpc(struct command *cmd, } static struct command_result *listdatastore_ok(struct command *cmd, + const char *method, const char *buf, const jsmntok_t *params, void *cb_arg UNUSED) @@ -160,7 +162,7 @@ static struct command_result *listdatastore_ok(struct command *cmd, if (command_check_only(cmd)) return command_check_done(cmd); - return forward_result(cmd, buf, params, NULL); + return forward_result(cmd, method, buf, params, NULL); } /* A command which does async, even if it is a check */