MCPcopy Create free account
hub / github.com/ElementsProject/lightning / plugin_hook_callback

Function plugin_hook_callback

lightningd/plugin_hook.c:253–311  ·  view source on GitHub ↗

* Callback to be passed to the jsonrpc_request. * * Unbundles the arguments, deserializes the response and dispatches * it to the hook callback. */

Source from the content-addressed store, hash-verified

251 * it to the hook callback.
252 */
253static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
254 const jsmntok_t *idtok,
255 struct plugin_hook_request *ph_req)
256{
257 const jsmntok_t *resulttok;
258 const struct hook_instance *h;
259 enum jsonrpc_errcode ecode;
260
261 assert(ph_req->hook_index < tal_count(ph_req->hook->hooks));
262 /* NULL if it vanished */
263 h = ph_req->hook->hooks[ph_req->hook_index];
264
265 /* destructor NULLs out hooks[], but we get called first at the moment.
266 * We handle either */
267 ecode = 0;
268 json_scan(tmpctx, buffer, toks, "{error:{code:%}}",
269 JSON_SCAN(json_to_jsonrpc_errcode, &ecode));
270 if (ecode == PLUGIN_TERMINATED) {
271 /* An important plugin dying takes us down with it. Don't act
272 * as if it said "continue": leave the hook unanswered, like at
273 * shutdown, so it's called again when we restart. */
274 if (h && h->plugin->important) {
275 log_unusual(ph_req->ld->log,
276 "Important plugin %s died from %s hook call:"
277 " leaving it for restart",
278 h->plugin->shortname, ph_req->hook->name);
279 return;
280 }
281 h = NULL;
282 }
283
284 /* We really only handle plugins dying: other errors are fatal. */
285 if (h) {
286 log_trace(ph_req->ld->log,
287 "Plugin %s returned from %s hook call",
288 h->plugin->shortname, ph_req->hook->name);
289 resulttok = json_get_member(buffer, toks, "result");
290 if (!resulttok)
291 fatal("Plugin %s for %s returned non-result response %.*s",
292 h->plugin->shortname,
293 ph_req->hook->name, toks->end - toks->start,
294 buffer + toks->start);
295
296 dev_save_plugin_io_in(h->plugin->plugins, "hook_in",
297 ph_req->hook->name,
298 buffer, toks);
299 if (!ph_req->hook->deserialize_cb(ph_req->cb_arg,
300 buffer, resulttok)) {
301 tal_free(ph_req->cb_arg);
302 tal_free(ph_req);
303 return;
304 }
305 } else {
306 log_debug(ph_req->ld->log, "Plugin died from %s hook call",
307 ph_req->hook->name);
308 }
309
310 plugin_hook_call_next(ph_req);

Callers

nothing calls this directly

Calls 6

json_get_memberFunction · 0.85
dev_save_plugin_io_inFunction · 0.85
tal_freeFunction · 0.85
plugin_hook_call_nextFunction · 0.85
fatalFunction · 0.70
json_scanFunction · 0.50

Tested by

no test coverage detected