plugin: Add the plugin we're serializing for in the serializer

We will start annotating some of the in-memory objects with a message
indicating which plugin currently is processing the hook.
This commit is contained in:
Christian Decker 2021-06-02 17:33:23 +02:00 committed by Rusty Russell
parent eeba75ca7c
commit 6062b40a5d
9 changed files with 36 additions and 29 deletions

View File

@ -188,9 +188,9 @@ struct rbf_channel_payload {
char *err_msg;
};
static void
rbf_channel_hook_serialize(struct rbf_channel_payload *payload,
struct json_stream *stream)
static void rbf_channel_hook_serialize(struct rbf_channel_payload *payload,
struct json_stream *stream,
struct plugin *plugin)
{
json_object_start(stream, "rbf_channel");
json_add_node_id(stream, "id", &payload->peer_id);
@ -251,9 +251,9 @@ struct openchannel2_payload {
char *err_msg;
};
static void
openchannel2_hook_serialize(struct openchannel2_payload *payload,
struct json_stream *stream)
static void openchannel2_hook_serialize(struct openchannel2_payload *payload,
struct json_stream *stream,
struct plugin *plugin)
{
json_object_start(stream, "openchannel2");
json_add_node_id(stream, "id", &payload->peer_id);
@ -295,7 +295,8 @@ struct openchannel2_psbt_payload {
static void
openchannel2_changed_hook_serialize(struct openchannel2_psbt_payload *payload,
struct json_stream *stream)
struct json_stream *stream,
struct plugin *plugin)
{
json_object_start(stream, "openchannel2_changed");
json_add_psbt(stream, "psbt", payload->psbt);
@ -307,7 +308,8 @@ openchannel2_changed_hook_serialize(struct openchannel2_psbt_payload *payload,
static void
openchannel2_sign_hook_serialize(struct openchannel2_psbt_payload *payload,
struct json_stream *stream)
struct json_stream *stream,
struct plugin *plugin)
{
json_object_start(stream, "openchannel2_sign");
json_add_psbt(stream, "psbt", payload->psbt);

View File

@ -169,7 +169,8 @@ struct invoice_payment_hook_payload {
static void
invoice_payment_serialize(struct invoice_payment_hook_payload *payload,
struct json_stream *stream)
struct json_stream *stream,
struct plugin *plugin)
{
json_object_start(stream, "payment");
json_add_escaped_string(stream, "label", payload->label);

View File

@ -674,7 +674,8 @@ struct rpc_command_hook_payload {
};
static void rpc_command_hook_serialize(struct rpc_command_hook_payload *p,
struct json_stream *s)
struct json_stream *s,
struct plugin *plugin)
{
const jsmntok_t *tok;
size_t i;

View File

@ -15,9 +15,9 @@ struct onion_message_hook_payload {
struct tlv_onionmsg_payload *om;
};
static void
onion_message_serialize(struct onion_message_hook_payload *payload,
struct json_stream *stream)
static void onion_message_serialize(struct onion_message_hook_payload *payload,
struct json_stream *stream,
struct plugin *plugin)
{
json_object_start(stream, "onion_message");
if (payload->blinding_in)

View File

@ -615,9 +615,9 @@ struct openchannel_hook_payload {
char *errmsg;
};
static void
openchannel_hook_serialize(struct openchannel_hook_payload *payload,
struct json_stream *stream)
static void openchannel_hook_serialize(struct openchannel_hook_payload *payload,
struct json_stream *stream,
struct plugin *plugin)
{
struct uncommitted_channel *uc = payload->openingd->channel;
json_object_start(stream, "openchannel");

View File

@ -1039,7 +1039,7 @@ struct peer_connected_hook_payload {
static void
peer_connected_serialize(struct peer_connected_hook_payload *payload,
struct json_stream *stream)
struct json_stream *stream, struct plugin *plugin)
{
const struct peer *p = payload->peer;
json_object_start(stream, "peer");
@ -2782,7 +2782,8 @@ static void custommsg_final(struct custommsg_payload *payload STEALS)
}
static void custommsg_payload_serialize(struct custommsg_payload *payload,
struct json_stream *stream)
struct json_stream *stream,
struct plugin *plugin)
{
/* Backward compat for broken custommsg: if we get a custommsg
* from an old c-lightning node, then we must identify and

View File

@ -1011,7 +1011,8 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
}
static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
struct json_stream *s)
struct json_stream *s,
struct plugin *plugin)
{
const struct route_step *rs = p->route_step;
const struct htlc_in *hin = p->hin;
@ -2034,7 +2035,8 @@ struct commitment_revocation_payload {
};
static void commitment_revocation_hook_serialize(
struct commitment_revocation_payload *payload, struct json_stream *stream)
struct commitment_revocation_payload *payload, struct json_stream *stream,
struct plugin *plugin)
{
json_add_txid(stream, "commitment_txid", &payload->commitment_txid);
json_add_tx(stream, "penalty_tx", payload->penalty_tx);

View File

@ -232,7 +232,7 @@ static void plugin_hook_call_next(struct plugin_hook_request *ph_req)
NULL,
plugin_hook_callback, ph_req);
hook->serialize_payload(ph_req->cb_arg, req->stream);
hook->serialize_payload(ph_req->cb_arg, req->stream, ph_req->plugin);
jsonrpc_request_end(req);
plugin_request_send(ph_req->plugin, req);
}

View File

@ -49,7 +49,8 @@ struct plugin_hook {
void (*final_cb)(void *arg);
/* To send the payload to the plugin */
void (*serialize_payload)(void *src, struct json_stream *dest);
void (*serialize_payload)(void *src, struct json_stream *dest,
struct plugin *plugin);
/* Which plugins have registered this hook? This is a `tal_arr`
* initialized at creation. */
@ -91,20 +92,19 @@ bool plugin_hook_continue(void *arg, const char *buffer, const jsmntok_t *toks);
* an arbitrary extra argument used to maintain context.
*/
#define REGISTER_PLUGIN_HOOK(name, deserialize_cb, final_cb, \
serialize_payload, cb_arg_type) \
serialize_payload, cb_arg_type) \
struct plugin_hook name##_hook_gen = { \
stringify(name), \
typesafe_cb_cast( \
bool (*)(void *, const char *, const jsmntok_t *), \
bool (*)(cb_arg_type, const char *, const jsmntok_t *), \
deserialize_cb), \
typesafe_cb_cast(void (*)(void *STEALS), \
void (*)(cb_arg_type STEALS), final_cb), \
typesafe_cb_cast( \
void (*)(void *STEALS), \
void (*)(cb_arg_type STEALS), \
final_cb), \
typesafe_cb_cast(void (*)(void *, struct json_stream *), \
void (*)(cb_arg_type, struct json_stream *), \
serialize_payload), \
void (*)(void *, struct json_stream *, struct plugin *), \
void (*)(cb_arg_type, struct json_stream *, struct plugin *), \
serialize_payload), \
NULL, /* .plugins */ \
}; \
AUTODATA(hooks, &name##_hook_gen); \