Skip to content

Commit

Permalink
lightningd: return features in connect response.
Browse files Browse the repository at this point in the history
This is useful in general, but in particular it allows fundchannel to avoid YA
query to figure out if it can wumbo.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: JSON: `connect` returns `features` of the connected peer on success.
  • Loading branch information
rustyrussell committed Apr 3, 2020
1 parent 8cb364d commit 41ebaff
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion doc/lightning-connect.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion doc/lightning-connect.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ lightning-fundchannel(7).
RETURN VALUE
------------

On success the peer *id* is returned.
On success the peer *id* is returned, as well as a hexidecimal *features*
bitmap.

ERRORS
------
Expand Down
13 changes: 7 additions & 6 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ static struct connect *find_connect(struct lightningd *ld,
}

static struct command_result *connect_cmd_succeed(struct command *cmd,
const struct node_id *id)
const struct peer *peer)
{
struct json_stream *response = json_stream_success(cmd);
json_add_node_id(response, "id", id);
json_add_node_id(response, "id", &peer->id);
json_add_hex_talarr(response, "features", peer->features);
return command_success(cmd, response);
}

Expand Down Expand Up @@ -139,7 +140,7 @@ static struct command_result *json_connect(struct command *cmd,

if (peer->uncommitted_channel
|| (channel && channel->connected)) {
return connect_cmd_succeed(cmd, &id);
return connect_cmd_succeed(cmd, peer);
}
}

Expand Down Expand Up @@ -256,14 +257,14 @@ static void connect_failed(struct lightningd *ld, const u8 *msg)
delay_then_reconnect(channel, seconds_to_delay, addrhint);
}

void connect_succeeded(struct lightningd *ld, const struct node_id *id)
void connect_succeeded(struct lightningd *ld, const struct peer *peer)
{
struct connect *c;

/* We can have multiple connect commands: fail them all */
while ((c = find_connect(ld, id)) != NULL) {
while ((c = find_connect(ld, &peer->id)) != NULL) {
/* They delete themselves from list */
connect_cmd_succeed(c->cmd, id);
connect_cmd_succeed(c->cmd, peer);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lightningd/connect_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void connectd_activate(struct lightningd *ld);

void delay_then_reconnect(struct channel *channel, u32 seconds_delay,
const struct wireaddr_internal *addrhint TAKES);
void connect_succeeded(struct lightningd *ld, const struct node_id *id);
void connect_succeeded(struct lightningd *ld, const struct peer *peer);
void gossip_connect_result(struct lightningd *ld, const u8 *msg);

#endif /* LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H */
6 changes: 3 additions & 3 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,6 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
per_peer_state_set_fds(hook_payload->pps,
peer_fd, gossip_fd, gossip_store_fd);

/* Complete any outstanding connect commands. */
connect_succeeded(ld, &id);

/* If we're already dealing with this peer, hand off to correct
* subdaemon. Otherwise, we'll hand to openingd to wait there. */
peer = peer_by_id(ld, &id);
Expand All @@ -1010,6 +1007,9 @@ void peer_connected(struct lightningd *ld, const u8 *msg,

peer_update_features(peer, features);

/* Complete any outstanding connect commands. */
connect_succeeded(ld, peer);

/* Can't be opening, since we wouldn't have sent peer_disconnected. */
assert(!peer->uncommitted_channel);
hook_payload->channel = peer_active_channel(peer);
Expand Down
2 changes: 1 addition & 1 deletion lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct command_result *command_success(struct command *cmd UNNEEDED,

{ fprintf(stderr, "command_success called!\n"); abort(); }
/* Generated stub for connect_succeeded */
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct node_id *id UNNEEDED)
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct peer *peer UNNEEDED)
{ fprintf(stderr, "connect_succeeded called!\n"); abort(); }
/* Generated stub for delay_then_reconnect */
void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED,
Expand Down
2 changes: 1 addition & 1 deletion wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct command_result *command_success(struct command *cmd UNNEEDED,

{ fprintf(stderr, "command_success called!\n"); abort(); }
/* Generated stub for connect_succeeded */
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct node_id *id UNNEEDED)
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct peer *peer UNNEEDED)
{ fprintf(stderr, "connect_succeeded called!\n"); abort(); }
/* Generated stub for create_onionreply */
struct onionreply *create_onionreply(const tal_t *ctx UNNEEDED,
Expand Down

0 comments on commit 41ebaff

Please sign in to comment.