diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index d86e3bb05..4961b2dc4 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -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 */ diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 111c2f7bf..8f296aeb8 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -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(); }