Skip to content

Commit

Permalink
lightningd: provide peer address for reconnect if connect fails.
Browse files Browse the repository at this point in the history
It usually works out due to other reconnections, but I noticed this
diagnosing another test.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Jul 19, 2022
1 parent c57a5a0 commit e15e551
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,12 @@ static void connect_failed(struct lightningd *ld,
}
}

void connect_failed_disconnect(struct lightningd *ld, const struct node_id *id)
void connect_failed_disconnect(struct lightningd *ld,
const struct node_id *id,
const struct wireaddr_internal *addrhint)
{
connect_failed(ld, id, CONNECT_DISCONNECTED_DURING,
"disconnected during connection", 1, NULL);
"disconnected during connection", 1, addrhint);
}

static void handle_connect_failed(struct lightningd *ld, const u8 *msg)
Expand Down
4 changes: 3 additions & 1 deletion lightningd/connect_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ void try_reconnect(const tal_t *ctx,
void connect_succeeded(struct lightningd *ld, const struct peer *peer,
bool incoming,
const struct wireaddr_internal *addr);
void connect_failed_disconnect(struct lightningd *ld, const struct node_id *id);
void connect_failed_disconnect(struct lightningd *ld,
const struct node_id *id,
const struct wireaddr_internal *addr);

/* Disconnect a peer (if no subds want to talk any more) */
void maybe_disconnect_peer(struct lightningd *ld, struct peer *peer);
Expand Down
5 changes: 3 additions & 2 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1540,11 +1540,12 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg)
/* If there are literally no channels, might as well
* free immediately. */
if (!p->uncommitted_channel && list_empty(&p->channels))
tal_free(p);
p = tal_free(p);
}

/* If you were trying to connect, it failed. */
connect_failed_disconnect(ld, &id);
connect_failed_disconnect(ld, &id,
p && !p->connected_incoming ? &p->addr : NULL);

/* Fire off plugin notifications */
notify_disconnect(ld, &id);
Expand Down
4 changes: 3 additions & 1 deletion lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ struct command_result *command_success(struct command *cmd UNNEEDED,

{ fprintf(stderr, "command_success called!\n"); abort(); }
/* Generated stub for connect_failed_disconnect */
void connect_failed_disconnect(struct lightningd *ld UNNEEDED, const struct node_id *id UNNEEDED)
void connect_failed_disconnect(struct lightningd *ld UNNEEDED,
const struct node_id *id UNNEEDED,
const struct wireaddr_internal *addr UNNEEDED)
{ fprintf(stderr, "connect_failed_disconnect called!\n"); abort(); }
/* Generated stub for connect_succeeded */
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct peer *peer UNNEEDED,
Expand Down
4 changes: 3 additions & 1 deletion wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ struct command_result *command_success(struct command *cmd UNNEEDED,

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

0 comments on commit e15e551

Please sign in to comment.