Skip to content

Commit

Permalink
cleanup: Remove current_plugin from plugin_hook_request
Browse files Browse the repository at this point in the history
It was a pointer into the list of plugins for the hook, but it was rather
unstable: if a plugin exits after handling the event we could end up skipping
a later plugin. We now rely on the much more stable `call_chain` list, so we
can clean up that useless field.
  • Loading branch information
cdecker committed Feb 25, 2020
1 parent a8bc1ee commit acaec67
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lightningd/plugin_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
struct plugin_hook_request {
struct list_head call_chain;
struct plugin *plugin;
int current_plugin;
const struct plugin_hook *hook;
void *cb_arg;
void *payload;
Expand Down Expand Up @@ -133,7 +132,6 @@ static void plugin_hook_killed(struct plugin_hook_call_link *link)
/* Call next will unlink, so we don't need to. This is treated
* equivalent to the plugin returning a continue-result.
*/
link->req->current_plugin--;
plugin_hook_callback(NULL, NULL, NULL, link->req);
} else {
/* The plugin is in the list waiting to be called, just remove
Expand Down Expand Up @@ -188,12 +186,11 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
resrestok = NULL;
}

more_plugins = r->current_plugin + 1 < tal_count(r->hook->plugins);
cont = buffer == NULL || (resrestok && json_tok_streq(buffer, resrestok, "continue"));

/* If this is a hook response containing a `continue` and we have more
* plugins queue the next call. In that case we discard the remainder
* of the result, and let the next plugin decide. */
cont = buffer == NULL || (resrestok && json_tok_streq(buffer, resrestok, "continue"));
more_plugins = !list_empty(&r->call_chain);
if (cont && more_plugins) {
plugin_hook_call_next(r);
} else {
Expand All @@ -217,9 +214,8 @@ static void plugin_hook_call_next(struct plugin_hook_request *ph_req)
{
struct jsonrpc_request *req;
const struct plugin_hook *hook = ph_req->hook;
ph_req->current_plugin++;
assert(ph_req->current_plugin < tal_count(hook->plugins));
ph_req->plugin = ph_req->hook->plugins[ph_req->current_plugin];
assert(!list_empty(&ph_req->call_chain));
ph_req->plugin = list_top(&ph_req->call_chain, struct plugin_hook_call_link, list)->plugin;

req = jsonrpc_request_start(NULL, hook->name,
plugin_get_log(ph_req->plugin),
Expand All @@ -246,7 +242,6 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
ph_req->cb_arg = cb_arg;
ph_req->db = ld->wallet->db;
ph_req->payload = tal_steal(ph_req, payload);
ph_req->current_plugin = -1;
ph_req->ld = ld;

list_head_init(&ph_req->call_chain);
Expand Down Expand Up @@ -349,8 +344,7 @@ void plugin_hook_db_sync(struct db *db)

ph_req->hook = hook;
ph_req->db = db;
ph_req->current_plugin = 0;
plugin = ph_req->plugin = hook->plugins[ph_req->current_plugin];
plugin = ph_req->plugin = hook->plugins[0];

json_add_num(req->stream, "data_version", db_data_version_get(db));

Expand Down

0 comments on commit acaec67

Please sign in to comment.