Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chanbackup: even if they enable experimental-peer-storage, check peers #6072

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions plugins/chanbackup.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,30 @@ static struct command_result *after_listpeers(struct command *cmd,
bool is_connected;
u8 *serialise_scb;

if (!peer_backup)
return notification_handled(cmd);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to short circuit here rather than in after_staticbackup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was aiming for minimal changes. but I pulled this out of the loop. I think you're right, the check could be done earlier..


serialise_scb = towire_peer_storage(cmd,
get_file_data(tmpctx, cmd->plugin));

peers = json_get_member(buf, params, "peers");

info->idx = 0;
json_for_each_arr(i, peer, peers) {
json_to_bool(buf, json_get_member(buf, peer, "connected"),
&is_connected);

if (is_connected && peer_backup) {
const char *err;
u8 *features;

/* If connected is false, features is missing, so this fails */
err = json_scan(cmd, buf, peer,
"{connected:%,features:%}",
JSON_SCAN(json_to_bool, &is_connected),
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex,
&features));
if (err || !is_connected)
continue;

/* We shouldn't have to check, but LND hangs up? */
if (feature_offered(features, OPT_PROVIDE_PEER_BACKUP_STORAGE)) {
const jsmntok_t *nodeid;
struct node_id node_id;

Expand Down Expand Up @@ -533,6 +546,7 @@ static struct command_result *peer_connected(struct command *cmd,
struct out_req *req;
u8 *serialise_scb;
const char *err;
u8 *features;

if (!peer_backup)
return command_hook_success(cmd);
Expand All @@ -541,15 +555,22 @@ static struct command_result *peer_connected(struct command *cmd,
get_file_data(tmpctx, cmd->plugin));
node_id = tal(cmd, struct node_id);
err = json_scan(cmd, buf, params,
"{peer:{id:%}}",
JSON_SCAN(json_to_node_id, node_id));
"{peer:{id:%,features:%}}",
JSON_SCAN(json_to_node_id, node_id),
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &features));
if (err) {
plugin_err(cmd->plugin,
"peer_connected hook did not scan %s: %.*s",
err, json_tok_full_len(params),
json_tok_full(buf, params));
}

/* We shouldn't have to check, but LND hangs up? */
if (!feature_offered(features, OPT_WANT_PEER_BACKUP_STORAGE)
&& !feature_offered(features, OPT_PROVIDE_PEER_BACKUP_STORAGE)) {
return command_hook_success(cmd);
}

req = jsonrpc_request_start(cmd->plugin,
cmd,
"sendcustommsg",
Expand Down