mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 16:44:20 +01:00
cleanup: Remove current_plugin from plugin_hook_request
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.
This commit is contained in:
committed by
Rusty Russell
parent
23149c3daa
commit
8f87579589
@@ -12,7 +12,6 @@
|
|||||||
struct plugin_hook_request {
|
struct plugin_hook_request {
|
||||||
struct list_head call_chain;
|
struct list_head call_chain;
|
||||||
struct plugin *plugin;
|
struct plugin *plugin;
|
||||||
int current_plugin;
|
|
||||||
const struct plugin_hook *hook;
|
const struct plugin_hook *hook;
|
||||||
void *cb_arg;
|
void *cb_arg;
|
||||||
void *payload;
|
void *payload;
|
||||||
@@ -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
|
/* Call next will unlink, so we don't need to. This is treated
|
||||||
* equivalent to the plugin returning a continue-result.
|
* equivalent to the plugin returning a continue-result.
|
||||||
*/
|
*/
|
||||||
link->req->current_plugin--;
|
|
||||||
plugin_hook_callback(NULL, NULL, NULL, link->req);
|
plugin_hook_callback(NULL, NULL, NULL, link->req);
|
||||||
} else {
|
} else {
|
||||||
/* The plugin is in the list waiting to be called, just remove
|
/* The plugin is in the list waiting to be called, just remove
|
||||||
@@ -188,12 +186,11 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
|
|||||||
resrestok = NULL;
|
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
|
/* 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
|
* plugins queue the next call. In that case we discard the remainder
|
||||||
* of the result, and let the next plugin decide. */
|
* 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) {
|
if (cont && more_plugins) {
|
||||||
plugin_hook_call_next(r);
|
plugin_hook_call_next(r);
|
||||||
} else {
|
} else {
|
||||||
@@ -217,9 +214,8 @@ static void plugin_hook_call_next(struct plugin_hook_request *ph_req)
|
|||||||
{
|
{
|
||||||
struct jsonrpc_request *req;
|
struct jsonrpc_request *req;
|
||||||
const struct plugin_hook *hook = ph_req->hook;
|
const struct plugin_hook *hook = ph_req->hook;
|
||||||
ph_req->current_plugin++;
|
assert(!list_empty(&ph_req->call_chain));
|
||||||
assert(ph_req->current_plugin < tal_count(hook->plugins));
|
ph_req->plugin = list_top(&ph_req->call_chain, struct plugin_hook_call_link, list)->plugin;
|
||||||
ph_req->plugin = ph_req->hook->plugins[ph_req->current_plugin];
|
|
||||||
|
|
||||||
req = jsonrpc_request_start(NULL, hook->name,
|
req = jsonrpc_request_start(NULL, hook->name,
|
||||||
plugin_get_log(ph_req->plugin),
|
plugin_get_log(ph_req->plugin),
|
||||||
@@ -246,7 +242,6 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
|
|||||||
ph_req->cb_arg = cb_arg;
|
ph_req->cb_arg = cb_arg;
|
||||||
ph_req->db = ld->wallet->db;
|
ph_req->db = ld->wallet->db;
|
||||||
ph_req->payload = tal_steal(ph_req, payload);
|
ph_req->payload = tal_steal(ph_req, payload);
|
||||||
ph_req->current_plugin = -1;
|
|
||||||
ph_req->ld = ld;
|
ph_req->ld = ld;
|
||||||
|
|
||||||
list_head_init(&ph_req->call_chain);
|
list_head_init(&ph_req->call_chain);
|
||||||
@@ -349,8 +344,7 @@ void plugin_hook_db_sync(struct db *db)
|
|||||||
|
|
||||||
ph_req->hook = hook;
|
ph_req->hook = hook;
|
||||||
ph_req->db = db;
|
ph_req->db = db;
|
||||||
ph_req->current_plugin = 0;
|
plugin = ph_req->plugin = hook->plugins[0];
|
||||||
plugin = ph_req->plugin = hook->plugins[ph_req->current_plugin];
|
|
||||||
|
|
||||||
json_add_num(req->stream, "data_version", db_data_version_get(db));
|
json_add_num(req->stream, "data_version", db_data_version_get(db));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user