mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
lightningd: Added plugin hook to notify whenever started in rocover mode.
This commit is contained in:
parent
88a2c0d17e
commit
51f72c1d1d
@ -50,6 +50,7 @@
|
||||
#include <common/daemon.h>
|
||||
#include <common/ecdh_hsmd.h>
|
||||
#include <common/hsm_encryption.h>
|
||||
#include <common/json_stream.h>
|
||||
#include <common/memleak.h>
|
||||
#include <common/timeout.h>
|
||||
#include <common/trace.h>
|
||||
@ -72,6 +73,7 @@
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/onchain_control.h>
|
||||
#include <lightningd/plugin.h>
|
||||
#include <lightningd/plugin_hook.h>
|
||||
#include <lightningd/runes.h>
|
||||
#include <lightningd/subd.h>
|
||||
#include <sys/resource.h>
|
||||
@ -207,6 +209,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
|
||||
* parsing, we know they're to be set to the defaults. */
|
||||
ld->alias = NULL;
|
||||
ld->rgb = NULL;
|
||||
ld->recover = NULL;
|
||||
list_head_init(&ld->connects);
|
||||
list_head_init(&ld->waitsendpay_commands);
|
||||
list_head_init(&ld->sendpay_commands);
|
||||
@ -910,6 +913,49 @@ void lightningd_exit(struct lightningd *ld, int exit_code)
|
||||
io_break(ld);
|
||||
}
|
||||
|
||||
struct recover_payload {
|
||||
const char *codex32secret;
|
||||
};
|
||||
|
||||
static bool
|
||||
recover_hook_deserialize(struct recover_payload *payload,
|
||||
const char *buffer, const jsmntok_t *toks)
|
||||
{
|
||||
const jsmntok_t *t_res;
|
||||
|
||||
if (!toks || !buffer)
|
||||
return true;
|
||||
|
||||
t_res = json_get_member(buffer, toks, "result");
|
||||
|
||||
/* fail */
|
||||
if (!t_res || !json_tok_streq(buffer, t_res, "continue"))
|
||||
fatal("Plugin returned an invalid response to the "
|
||||
"recover hook: %s", buffer);
|
||||
|
||||
/* call next hook */
|
||||
return true;
|
||||
}
|
||||
|
||||
static void recover_hook_final(struct recover_payload *payload STEALS)
|
||||
{
|
||||
tal_steal(tmpctx, payload);
|
||||
}
|
||||
|
||||
static void recover_hook_serialize(struct recover_payload *payload,
|
||||
struct json_stream *stream,
|
||||
struct plugin *plugin)
|
||||
{
|
||||
json_add_string(stream, "codex32", payload->codex32secret);
|
||||
}
|
||||
|
||||
|
||||
REGISTER_PLUGIN_HOOK(recover,
|
||||
recover_hook_deserialize,
|
||||
recover_hook_final,
|
||||
recover_hook_serialize,
|
||||
struct recover_payload *);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct lightningd *ld;
|
||||
@ -1001,6 +1047,7 @@ int main(int argc, char *argv[])
|
||||
orig_argv = notleak(tal_arr(ld, char *, argc + 1));
|
||||
for (size_t i = 1; i < argc; i++)
|
||||
orig_argv[i] = tal_strdup(orig_argv, argv[i]);
|
||||
|
||||
/*~ Turn argv[0] into an absolute path (if not already) */
|
||||
orig_argv[0] = path_join(orig_argv, take(path_cwd(NULL)), argv[0]);
|
||||
orig_argv[argc] = NULL;
|
||||
@ -1220,6 +1267,12 @@ int main(int argc, char *argv[])
|
||||
tal_hex(tmpctx, ld->rgb), version());
|
||||
ld->state = LD_STATE_RUNNING;
|
||||
|
||||
if (ld->recover) {
|
||||
struct recover_payload *payload = tal(NULL, struct recover_payload);
|
||||
payload->codex32secret = tal_strdup(payload,
|
||||
ld->recover);
|
||||
plugin_hook_call_recover(ld, NULL, payload);
|
||||
}
|
||||
/*~ If `closefrom_may_be_slow`, we limit ourselves to 4096 file
|
||||
* descriptors; tell the user about it as that limits the number
|
||||
* of channels they can have.
|
||||
|
@ -271,6 +271,9 @@ struct lightningd {
|
||||
/* Indexes used by all the wait infra */
|
||||
struct indexes indexes[NUM_WAIT_SUBSYSTEM];
|
||||
|
||||
/* Contains the codex32 string used with --recover flag */
|
||||
char *recover;
|
||||
|
||||
#if DEVELOPER
|
||||
/* If we want to debug a subdaemon/plugin. */
|
||||
char *dev_debug_subprocess;
|
||||
|
@ -1322,6 +1322,8 @@ static char *opt_set_codex32(const char *arg, struct lightningd *ld)
|
||||
return tal_fmt(tmpctx, "fsyncdir: %s", strerror(errno));
|
||||
}
|
||||
close(fd);
|
||||
|
||||
ld->recover = tal_strdup(ld, arg);
|
||||
opt_set_offline(ld);
|
||||
|
||||
return NULL;
|
||||
|
@ -114,6 +114,11 @@ void htlcs_notify_new_block(struct lightningd *ld UNNEEDED, u32 height UNNEEDED)
|
||||
void htlcs_resubmit(struct lightningd *ld UNNEEDED,
|
||||
struct htlc_in_map *unconnected_htlcs_in STEALS UNNEEDED)
|
||||
{ fprintf(stderr, "htlcs_resubmit called!\n"); abort(); }
|
||||
/* Generated stub for json_add_string */
|
||||
void json_add_string(struct json_stream *js UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
const char *str TAKES UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
|
||||
/* Generated stub for jsonrpc_listen */
|
||||
void jsonrpc_listen(struct jsonrpc *rpc UNNEEDED, struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "jsonrpc_listen called!\n"); abort(); }
|
||||
@ -170,6 +175,12 @@ struct chain_topology *new_topology(struct lightningd *ld UNNEEDED, struct logge
|
||||
/* Generated stub for onchaind_replay_channels */
|
||||
void onchaind_replay_channels(struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "onchaind_replay_channels called!\n"); abort(); }
|
||||
/* Generated stub for plugin_hook_call_ */
|
||||
bool plugin_hook_call_(struct lightningd *ld UNNEEDED,
|
||||
const struct plugin_hook *hook UNNEEDED,
|
||||
const char *cmd_id TAKES UNNEEDED,
|
||||
tal_t *cb_arg STEALS UNNEEDED)
|
||||
{ fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); }
|
||||
/* Generated stub for plugins_config */
|
||||
bool plugins_config(struct plugins *plugins UNNEEDED)
|
||||
{ fprintf(stderr, "plugins_config called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user