Skip to content

Commit

Permalink
lightningd/notifications: Add notify_we_lost_state to tell the recove…
Browse files Browse the repository at this point in the history
…r plugin to start finding ways to recover the node because we have corrupt data.
  • Loading branch information
adi2011 committed Nov 8, 2023
1 parent 28fd70a commit 0af6f48
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lightningd/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,38 @@ void notify_channel_state_changed(struct lightningd *ld,
plugins_notify(ld->plugins, take(n));
}

static void we_lost_state_notification_serialize(struct json_stream *stream,
const struct channel_id *cid,
const struct short_channel_id *scid)
{
json_object_start(stream, "we_lost_state");
json_add_channel_id(stream, "channel_id", cid);
if (scid)
json_add_short_channel_id(stream, "short_channel_id", scid);
else
json_add_null(stream, "short_channel_id");
json_add_bool(stream, "unrecoverable", true);
json_object_end(stream);
}


REGISTER_NOTIFICATION(we_lost_state,
we_lost_state_notification_serialize);

void notify_we_lost_state(struct lightningd *ld,
const struct channel_id *cid,
const struct short_channel_id *scid)
{
void (*serialize)(struct json_stream *,
const struct channel_id *,
const struct short_channel_id *) = we_lost_state_notification_gen.serialize;
struct jsonrpc_notification *n
= jsonrpc_notification_start(NULL, we_lost_state_notification_gen.topic);
serialize(n->stream, cid, scid);
jsonrpc_notification_end(n);
plugins_notify(ld->plugins, take(n));
}

static void forward_event_notification_serialize(struct json_stream *stream,
const struct htlc_in *in,
const struct short_channel_id *scid_out,
Expand Down
4 changes: 4 additions & 0 deletions lightningd/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ void notify_channel_state_changed(struct lightningd *ld,
enum state_change cause,
const char *message);

void notify_we_lost_state(struct lightningd *ld,
const struct channel_id *cid,
const struct short_channel_id *scid);

void notify_forward_event(struct lightningd *ld,
const struct htlc_in *in,
/* May be NULL if we don't know. */
Expand Down

0 comments on commit 0af6f48

Please sign in to comment.