Skip to content

Commit

Permalink
lightningd: use connectd to send the final error message, not opening…
Browse files Browse the repository at this point in the history
…d/dualopend

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jun 3, 2021
1 parent 7cffea1 commit e2f225e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 25 deletions.
11 changes: 10 additions & 1 deletion connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,7 @@ static struct io_plan *peer_final_msg(struct io_conn *conn,
u8 *finalmsg;
int fds[3];

f->daemon = daemon;
/* pps is allocated off f, so fds are closed when f freed. */
if (!fromwire_connectd_peer_final_msg(f, msg, &f->id, &pps, &finalmsg))
master_badmsg(WIRE_CONNECTD_PEER_FINAL_MSG, msg);
Expand All @@ -1662,8 +1663,16 @@ static struct io_plan *peer_final_msg(struct io_conn *conn,
tal_add_destructor(f, destroy_final_msg_data);

/* Get the fds for this peer. */
for (size_t i = 0; i < ARRAY_SIZE(fds); i++)
io_fd_block(io_conn_fd(conn), true);
for (size_t i = 0; i < ARRAY_SIZE(fds); i++) {
fds[i] = fdpass_recv(io_conn_fd(conn));
if (fds[i] == -1)
status_failed(STATUS_FAIL_MASTER_IO,
"Getting fd %zu after peer_final_msg: %s",
i, strerror(errno));
}
io_fd_block(io_conn_fd(conn), false);

/* We put peer fd into conn, but pps needs to free the rest */
per_peer_state_set_fds(pps, -1, fds[1], fds[2]);

Expand Down
3 changes: 0 additions & 3 deletions gossipd/test/run-bench-find_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
const struct channel_id *channel UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_warningfmt called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

#if DEVELOPER
Expand Down
3 changes: 0 additions & 3 deletions gossipd/test/run-find_route-specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
const struct channel_id *channel UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_warningfmt called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

#if DEVELOPER
Expand Down
3 changes: 0 additions & 3 deletions gossipd/test/run-find_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
const struct channel_id *channel UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_warningfmt called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

#if DEVELOPER
Expand Down
3 changes: 0 additions & 3 deletions gossipd/test/run-overlong.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
const struct channel_id *channel UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_warningfmt called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

#if DEVELOPER
Expand Down
27 changes: 20 additions & 7 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,10 +1136,6 @@ static void peer_connected_hook_final(struct peer_connected_hook_payload *payloa

notify_connect(ld, &peer->id, payload->incoming, &addr);

/* No err, all good. */
error = NULL;

send_error:
if (feature_negotiated(ld->our_features,
peer->their_features,
OPT_DUAL_FUND)) {
Expand All @@ -1150,11 +1146,28 @@ static void peer_connected_hook_final(struct peer_connected_hook_payload *payloa
|| channel->state == AWAITING_UNILATERAL);
channel->peer->addr = addr;
channel->peer->connected_incoming = payload->incoming;
peer_restart_dualopend(peer, payload->pps, channel, error);
peer_restart_dualopend(peer, payload->pps, channel, NULL);
} else
peer_start_dualopend(peer, payload->pps, error);
peer_start_dualopend(peer, payload->pps, NULL);
} else
peer_start_openingd(peer, payload->pps, error);
peer_start_openingd(peer, payload->pps, NULL);
return;

send_error:
log_debug(ld->log, "Telling connectd to send error %s",
tal_hex(tmpctx, error));
/* Get connectd to send error and close. */
subd_send_msg(ld->connectd,
take(towire_connectd_peer_final_msg(NULL, &peer->id,
payload->pps, error)));
subd_send_fd(ld->connectd, payload->pps->peer_fd);
subd_send_fd(ld->connectd, payload->pps->gossip_fd);
subd_send_fd(ld->connectd, payload->pps->gossip_store_fd);
/* Don't close those fds! */
payload->pps->peer_fd
= payload->pps->gossip_fd
= payload->pps->gossip_store_fd
= -1;
}

static bool
Expand Down
6 changes: 6 additions & 0 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ void subd_req_(const tal_t *ctx UNNEEDED,
void (*replycb)(struct subd * UNNEEDED, const u8 * UNNEEDED, const int * UNNEEDED, void *) UNNEEDED,
void *replycb_data UNNEEDED)
{ fprintf(stderr, "subd_req_ called!\n"); abort(); }
/* Generated stub for subd_send_fd */
void subd_send_fd(struct subd *sd UNNEEDED, int fd UNNEEDED)
{ fprintf(stderr, "subd_send_fd called!\n"); abort(); }
/* Generated stub for subd_send_msg */
void subd_send_msg(struct subd *sd UNNEEDED, const u8 *msg_out UNNEEDED)
{ fprintf(stderr, "subd_send_msg called!\n"); abort(); }
Expand All @@ -637,6 +640,9 @@ u8 *towire_channeld_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_bas
/* Generated stub for towire_connectd_connect_to_peer */
u8 *towire_connectd_connect_to_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u32 seconds_waited UNNEEDED, const struct wireaddr_internal *addrhint UNNEEDED)
{ fprintf(stderr, "towire_connectd_connect_to_peer called!\n"); abort(); }
/* Generated stub for towire_connectd_peer_final_msg */
u8 *towire_connectd_peer_final_msg(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, const struct per_peer_state *pps UNNEEDED, const u8 *msg UNNEEDED)
{ fprintf(stderr, "towire_connectd_peer_final_msg called!\n"); abort(); }
/* Generated stub for towire_dualopend_send_shutdown */
u8 *towire_dualopend_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED)
{ fprintf(stderr, "towire_dualopend_send_shutdown called!\n"); abort(); }
Expand Down
2 changes: 1 addition & 1 deletion wallet/db_postgres_sqlgen.c

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

2 changes: 1 addition & 1 deletion wallet/db_sqlite3_sqlgen.c

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

6 changes: 3 additions & 3 deletions wallet/statements_gettextgen.po

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

6 changes: 6 additions & 0 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ void subd_req_(const tal_t *ctx UNNEEDED,
void (*replycb)(struct subd * UNNEEDED, const u8 * UNNEEDED, const int * UNNEEDED, void *) UNNEEDED,
void *replycb_data UNNEEDED)
{ fprintf(stderr, "subd_req_ called!\n"); abort(); }
/* Generated stub for subd_send_fd */
void subd_send_fd(struct subd *sd UNNEEDED, int fd UNNEEDED)
{ fprintf(stderr, "subd_send_fd called!\n"); abort(); }
/* Generated stub for subd_send_msg */
void subd_send_msg(struct subd *sd UNNEEDED, const u8 *msg_out UNNEEDED)
{ fprintf(stderr, "subd_send_msg called!\n"); abort(); }
Expand Down Expand Up @@ -760,6 +763,9 @@ u8 *towire_connectd_connect_to_peer(const tal_t *ctx UNNEEDED, const struct node
/* Generated stub for towire_connectd_peer_disconnected */
u8 *towire_connectd_peer_disconnected(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_connectd_peer_disconnected called!\n"); abort(); }
/* Generated stub for towire_connectd_peer_final_msg */
u8 *towire_connectd_peer_final_msg(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, const struct per_peer_state *pps UNNEEDED, const u8 *msg UNNEEDED)
{ fprintf(stderr, "towire_connectd_peer_final_msg called!\n"); abort(); }
/* Generated stub for towire_custommsg_out */
u8 *towire_custommsg_out(const tal_t *ctx UNNEEDED, const u8 *msg UNNEEDED)
{ fprintf(stderr, "towire_custommsg_out called!\n"); abort(); }
Expand Down

0 comments on commit e2f225e

Please sign in to comment.