lightningd: avoid plugin timer indirection.

Now we know whether the command completed or not, we can correctly
call command_still_pending() if it didn't complete.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2020-05-05 10:42:19 +09:30
parent f8cdb523dd
commit 77094b7df8
2 changed files with 15 additions and 9 deletions

View File

@ -774,11 +774,6 @@ REGISTER_SINGLE_PLUGIN_HOOK(rpc_command,
rpc_command_hook_serialize,
struct rpc_command_hook_payload *);
static void call_rpc_command_hook(struct rpc_command_hook_payload *p)
{
plugin_hook_call_rpc_command(p->cmd->ld, p);
}
/* We return struct command_result so command_fail return value has a natural
* sink; we don't actually use the result. */
static struct command_result *
@ -787,6 +782,7 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
const jsmntok_t *method, *id, *params;
struct command *c;
struct rpc_command_hook_payload *rpc_hook;
bool completed;
if (tok[0].type != JSMN_OBJECT) {
json_command_malformed(jcon, "null",
@ -850,11 +846,15 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
/* Duplicate since we might outlive the connection */
rpc_hook->buffer = tal_dup_talarr(rpc_hook, char, jcon->buffer);
rpc_hook->request = tal_dup_talarr(rpc_hook, jsmntok_t, tok);
/* Prevent a race between was_pending and still_pending */
new_reltimer(c->ld->timers, rpc_hook, time_from_msec(1),
call_rpc_command_hook, rpc_hook);
return command_still_pending(c);
db_begin_transaction(jcon->ld->wallet->db);
completed = plugin_hook_call_rpc_command(jcon->ld, rpc_hook);
db_commit_transaction(jcon->ld->wallet->db);
/* If it's deferred, mark it (otherwise, it's completed) */
if (!completed)
return command_still_pending(c);
return NULL;
}
/* Mutual recursion */

View File

@ -9,6 +9,12 @@ size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNN
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for db_begin_transaction_ */
void db_begin_transaction_(struct db *db UNNEEDED, const char *location UNNEEDED)
{ fprintf(stderr, "db_begin_transaction_ called!\n"); abort(); }
/* Generated stub for db_commit_transaction */
void db_commit_transaction(struct db *db UNNEEDED)
{ fprintf(stderr, "db_commit_transaction called!\n"); abort(); }
/* Generated stub for fatal */
void fatal(const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "fatal called!\n"); abort(); }