From 05ec56a968faa1bf294ed76077874857b49ea575 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 3 Jan 2019 17:56:51 +0100 Subject: [PATCH] plugin: Plugin hook callbacks need to be wrapped in a DB transaction We therefore keep a reference to the DB and will wrap and unwrap when a hook returns. Notice that this might cause behavior changes when moving logic into a hook callback, since the continuation runs in a different transaction than the event that triggered the hook in the first place. Should not matter too much, since we don't use DB rollbacks at the moment, but it's something to keep in mind. Signed-off-by: Christian Decker --- lightningd/plugin_hook.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index 1040a41e6..cefea2365 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -1,12 +1,14 @@ #include #include #include +#include /* Struct containing all the information needed to deserialize and * dispatch an eventual plugin_hook response. */ struct plugin_hook_request { const struct plugin_hook *hook; void *cb_arg; + struct db *db; }; static struct plugin_hook *plugin_hook_by_name(const char *name) @@ -51,7 +53,9 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks, { const jsmntok_t *resulttok = json_get_member(buffer, toks, "result"); void *response = r->hook->deserialize_response(r, buffer, resulttok); + db_begin_transaction(r->db); r->hook->response_cb(r->cb_arg, response); + db_commit_transaction(r->db); tal_free(r); } @@ -71,6 +75,7 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, plugin_hook_callback, ph_req); ph_req->hook = hook; ph_req->cb_arg = cb_arg; + ph_req->db = ld->wallet->db; hook->serialize_payload(payload, req->stream); jsonrpc_request_end(req); plugin_request_send(hook->plugin, req);