Skip to content

Commit c4dfac5

Browse files
committed
plugins: remove now-unused single-hook infrastructure.
Should have really let @mschmook do this, as he did all the work to make it possible! Signed-off-by: Rusty Russell <[email protected]>
1 parent 9c3cf5a commit c4dfac5

File tree

2 files changed

+10
-69
lines changed

2 files changed

+10
-69
lines changed

lightningd/plugin_hook.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ struct plugin_hook *plugin_hook_register(struct plugin *plugin, const char *meth
8686
if (hook->hooks == NULL)
8787
hook->hooks = notleak(tal_arr(NULL, struct hook_instance *, 0));
8888

89-
/* If this is a single type hook and we have a plugin registered we
90-
* must fail this attempt to add the plugin to the hook. */
91-
if (hook->type == PLUGIN_HOOK_SINGLE && tal_count(hook->hooks) > 0)
92-
return NULL;
93-
9489
/* Ensure we don't register the same plugin multple times. */
9590
for (size_t i=0; i<tal_count(hook->hooks); i++)
9691
if (hook->hooks[i]->plugin == plugin)
@@ -187,16 +182,14 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
187182
r->hook->name, toks->end - toks->start,
188183
buffer + toks->start);
189184

190-
if (r->hook->type == PLUGIN_HOOK_CHAIN) {
191-
db_begin_transaction(db);
192-
if (!r->hook->deserialize_cb(r->cb_arg, buffer,
193-
resulttok)) {
194-
tal_free(r->cb_arg);
195-
db_commit_transaction(db);
196-
goto cleanup;
197-
}
198-
in_transaction = true;
185+
db_begin_transaction(db);
186+
if (!r->hook->deserialize_cb(r->cb_arg, buffer,
187+
resulttok)) {
188+
tal_free(r->cb_arg);
189+
db_commit_transaction(db);
190+
goto cleanup;
199191
}
192+
in_transaction = true;
200193
} else {
201194
/* plugin died */
202195
resulttok = NULL;
@@ -212,10 +205,7 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
212205
/* We optimize for the case where we already called deserialize_cb */
213206
if (!in_transaction)
214207
db_begin_transaction(db);
215-
if (r->hook->type == PLUGIN_HOOK_CHAIN)
216-
r->hook->final_cb(r->cb_arg);
217-
else
218-
r->hook->single_response_cb(r->cb_arg, buffer, resulttok);
208+
r->hook->final_cb(r->cb_arg);
219209
db_commit_transaction(db);
220210

221211
cleanup:
@@ -282,10 +272,7 @@ bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
282272
* roundtrip to the serializer and deserializer. If we
283273
* were expecting a default response it should have
284274
* been part of the `cb_arg`. */
285-
if (hook->type == PLUGIN_HOOK_CHAIN)
286-
hook->final_cb(cb_arg);
287-
else
288-
hook->single_response_cb(cb_arg, NULL, NULL);
275+
hook->final_cb(cb_arg);
289276
return true;
290277
}
291278
}
@@ -294,8 +281,7 @@ bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
294281
* annoying, and to make it clear that it's totally synchronous. */
295282

296283
/* Special synchronous hook for db */
297-
static struct plugin_hook db_write_hook = {"db_write", PLUGIN_HOOK_CHAIN, NULL,
298-
NULL, NULL};
284+
static struct plugin_hook db_write_hook = {"db_write", NULL, NULL};
299285
AUTODATA(hooks, &db_write_hook);
300286

301287
/* A `db_write` for one particular plugin hook. */

lightningd/plugin_hook.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@
3030
*
3131
* - `serialize_payload` which takes a payload of type `cb_arg_type`
3232
* and serializes it into the given `json_stream`. `
33-
*
34-
* For single-plugin hooks:
35-
* - `single_response_cb` is called once the plugin has responded (or with
36-
* buffer == NULL if there's no plugin). In addition an arbitrary
37-
* additional argument of type `cb_arg_type` can be passed along
38-
* that may contain any additional context necessary. It must free
39-
* or otherwise take ownership of the cb_arg_type argument.
40-
*
41-
* For chained-plugin hooks:
4233
* - `deserialize_cb` is called for each plugin, if it returns true the
4334
* next one is called, otherwise the cb_arg_type argument is free.
4435
* - If all `deserialize_cb` return true, `final_cb` is called. It must free
@@ -49,24 +40,9 @@
4940
* that all the provided functions for serialization, deserialization
5041
* and callback have the correct type.
5142
*/
52-
53-
enum plugin_hook_type {
54-
PLUGIN_HOOK_SINGLE,
55-
PLUGIN_HOOK_CHAIN,
56-
};
57-
5843
struct plugin_hook {
5944
const char *name;
6045

61-
/* Which type of plugin is this? It'll determine how many plugins can
62-
* register this hook, and how the hooks are called. */
63-
enum plugin_hook_type type;
64-
65-
/* For PLUGIN_HOOK_SINGLE hooks */
66-
void (*single_response_cb)(void *arg,
67-
const char *buffer, const jsmntok_t *toks);
68-
69-
/* For PLUGIN_HOOK_CHAIN hooks: */
7046
/* Returns false if we should stop iterating (and free arg). */
7147
bool (*deserialize_cb)(void *arg,
7248
const char *buffer, const jsmntok_t *toks);
@@ -114,31 +90,10 @@ bool plugin_hook_continue(void *arg, const char *buffer, const jsmntok_t *toks);
11490
* response_cb function accepts the deserialized response format and
11591
* an arbitrary extra argument used to maintain context.
11692
*/
117-
#define REGISTER_SINGLE_PLUGIN_HOOK(name, response_cb, \
118-
serialize_payload, cb_arg_type) \
119-
struct plugin_hook name##_hook_gen = { \
120-
stringify(name), \
121-
PLUGIN_HOOK_SINGLE, \
122-
typesafe_cb_cast( \
123-
void (*)(void *STEALS, const char *, const jsmntok_t *), \
124-
void (*)(cb_arg_type STEALS, const char *, const jsmntok_t *), \
125-
response_cb), \
126-
NULL, NULL, \
127-
typesafe_cb_cast(void (*)(void *, struct json_stream *), \
128-
void (*)(cb_arg_type, struct json_stream *), \
129-
serialize_payload), \
130-
NULL, /* .plugins */ \
131-
}; \
132-
AUTODATA(hooks, &name##_hook_gen); \
133-
PLUGIN_HOOK_CALL_DEF(name, cb_arg_type)
134-
135-
13693
#define REGISTER_PLUGIN_HOOK(name, deserialize_cb, final_cb, \
13794
serialize_payload, cb_arg_type) \
13895
struct plugin_hook name##_hook_gen = { \
13996
stringify(name), \
140-
PLUGIN_HOOK_CHAIN, \
141-
NULL, \
14297
typesafe_cb_cast( \
14398
bool (*)(void *, const char *, const jsmntok_t *), \
14499
bool (*)(cb_arg_type, const char *, const jsmntok_t *), \

0 commit comments

Comments
 (0)