mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-09 09:04:25 +01:00
gossipd: hand a gossip_store_fd to all subdaemons.
This will let them read from the gossip store directly. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -185,8 +185,8 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
|
||||
{
|
||||
struct peer_comms *pcomms = new_peer_comms(msg);
|
||||
|
||||
/* We expect 2 fds. */
|
||||
assert(tal_count(fds) == 2);
|
||||
/* We expect 3 fds. */
|
||||
assert(tal_count(fds) == 3);
|
||||
|
||||
if (!fromwire_channel_shutdown_complete(msg, &pcomms->cs)) {
|
||||
channel_internal_error(channel, "bad shutdown_complete: %s",
|
||||
@@ -195,6 +195,7 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
|
||||
}
|
||||
pcomms->peer_fd = fds[0];
|
||||
pcomms->gossip_fd = fds[1];
|
||||
pcomms->gossip_store_fd = fds[2];
|
||||
|
||||
/* This sets channel->owner, closes down channeld. */
|
||||
peer_start_closingd(channel, pcomms, false, NULL);
|
||||
@@ -222,9 +223,9 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
|
||||
peer_got_shutdown(sd->channel, msg);
|
||||
break;
|
||||
case WIRE_CHANNEL_SHUTDOWN_COMPLETE:
|
||||
/* We expect 2 fds. */
|
||||
/* We expect 3 fds. */
|
||||
if (!fds)
|
||||
return 2;
|
||||
return 3;
|
||||
peer_start_closingd_after_shutdown(sd->channel, msg, fds);
|
||||
break;
|
||||
case WIRE_CHANNEL_FAIL_FALLEN_BEHIND:
|
||||
@@ -292,6 +293,7 @@ void peer_start_channeld(struct channel *channel,
|
||||
channel_set_billboard,
|
||||
take(&pcomms->peer_fd),
|
||||
take(&pcomms->gossip_fd),
|
||||
take(&pcomms->gossip_store_fd),
|
||||
take(&hsmfd), NULL),
|
||||
false);
|
||||
|
||||
|
||||
@@ -185,6 +185,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
channel_set_billboard,
|
||||
take(&pcomms->peer_fd),
|
||||
take(&pcomms->gossip_fd),
|
||||
take(&pcomms->gossip_store_fd),
|
||||
take(&hsmfd),
|
||||
NULL),
|
||||
false);
|
||||
|
||||
@@ -304,9 +304,9 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
|
||||
break;
|
||||
|
||||
case WIRE_CONNECT_PEER_CONNECTED:
|
||||
if (tal_count(fds) != 2)
|
||||
return 2;
|
||||
peer_connected(connectd->ld, msg, fds[0], fds[1]);
|
||||
if (tal_count(fds) != 3)
|
||||
return 3;
|
||||
peer_connected(connectd->ld, msg, fds[0], fds[1], fds[2]);
|
||||
break;
|
||||
|
||||
case WIRE_CONNECTCTL_CONNECT_FAILED:
|
||||
|
||||
@@ -301,9 +301,10 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
u8 *remote_upfront_shutdown_script;
|
||||
struct peer_comms *pcomms = new_peer_comms(resp);
|
||||
|
||||
assert(tal_count(fds) == 2);
|
||||
assert(tal_count(fds) == 3);
|
||||
pcomms->peer_fd = fds[0];
|
||||
pcomms->gossip_fd = fds[1];
|
||||
pcomms->gossip_store_fd = fds[2];
|
||||
|
||||
/* This is a new channel_info.their_config so set its ID to 0 */
|
||||
channel_info.their_config.id = 0;
|
||||
@@ -493,9 +494,10 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
struct peer_comms *pcomms = new_peer_comms(reply);
|
||||
|
||||
log_debug(uc->log, "Got opening_fundee_finish_response");
|
||||
assert(tal_count(fds) == 2);
|
||||
assert(tal_count(fds) == 3);
|
||||
pcomms->peer_fd = fds[0];
|
||||
pcomms->gossip_fd = fds[1];
|
||||
pcomms->gossip_store_fd = fds[2];
|
||||
|
||||
/* This is a new channel_info.their_config, set its ID to 0 */
|
||||
channel_info.their_config.id = 0;
|
||||
@@ -567,6 +569,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
failed:
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
close(fds[3]);
|
||||
tal_free(uc);
|
||||
}
|
||||
|
||||
@@ -736,8 +739,8 @@ static unsigned int openingd_msg(struct subd *openingd,
|
||||
tal_free(openingd);
|
||||
return 0;
|
||||
}
|
||||
if (tal_count(fds) != 2)
|
||||
return 2;
|
||||
if (tal_count(fds) != 3)
|
||||
return 3;
|
||||
opening_funder_finished(openingd, msg, fds, uc->fc);
|
||||
return 0;
|
||||
|
||||
@@ -752,8 +755,8 @@ static unsigned int openingd_msg(struct subd *openingd,
|
||||
return 0;
|
||||
|
||||
case WIRE_OPENING_FUNDEE:
|
||||
if (tal_count(fds) != 2)
|
||||
return 2;
|
||||
if (tal_count(fds) != 3)
|
||||
return 3;
|
||||
opening_fundee_finished(openingd, msg, fds, uc);
|
||||
return 0;
|
||||
|
||||
@@ -799,6 +802,7 @@ void peer_start_openingd(struct peer *peer,
|
||||
opening_channel_set_billboard,
|
||||
take(&pcomms->peer_fd),
|
||||
take(&pcomms->gossip_fd),
|
||||
take(&pcomms->gossip_store_fd),
|
||||
take(&hsmfd), NULL);
|
||||
if (!uc->openingd) {
|
||||
uncommitted_channel_disconnect(uc,
|
||||
|
||||
@@ -7,6 +7,8 @@ static void destroy_peer_comms(struct peer_comms *pcomms)
|
||||
close(pcomms->peer_fd);
|
||||
if (pcomms->gossip_fd != -1)
|
||||
close(pcomms->gossip_fd);
|
||||
if (pcomms->gossip_store_fd != -1)
|
||||
close(pcomms->gossip_store_fd);
|
||||
}
|
||||
|
||||
struct peer_comms *new_peer_comms(const tal_t *ctx)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
struct peer_comms {
|
||||
struct crypto_state cs;
|
||||
/* If not -1, closed on freeing */
|
||||
int peer_fd, gossip_fd;
|
||||
int peer_fd, gossip_fd, gossip_store_fd;
|
||||
};
|
||||
|
||||
struct peer_comms *new_peer_comms(const tal_t *ctx);
|
||||
|
||||
@@ -795,7 +795,7 @@ REGISTER_PLUGIN_HOOK(peer_connected, peer_connected_hook_cb,
|
||||
/* Connectd tells us a peer has connected: it never hands us duplicates, since
|
||||
* it holds them until we say peer_died. */
|
||||
void peer_connected(struct lightningd *ld, const u8 *msg,
|
||||
int peer_fd, int gossip_fd)
|
||||
int peer_fd, int gossip_fd, int gossip_store_fd)
|
||||
{
|
||||
struct node_id id;
|
||||
u8 *globalfeatures, *localfeatures;
|
||||
@@ -807,6 +807,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
||||
hook_payload->pcomms = new_peer_comms(hook_payload);
|
||||
hook_payload->pcomms->peer_fd = peer_fd;
|
||||
hook_payload->pcomms->gossip_fd = gossip_fd;
|
||||
hook_payload->pcomms->gossip_store_fd = gossip_store_fd;
|
||||
|
||||
if (!fromwire_connect_peer_connected(msg, msg,
|
||||
&id, &hook_payload->addr,
|
||||
|
||||
@@ -69,7 +69,7 @@ struct peer *peer_from_json(struct lightningd *ld,
|
||||
const jsmntok_t *peeridtok);
|
||||
|
||||
void peer_connected(struct lightningd *ld, const u8 *msg,
|
||||
int peer_fd, int gossip_fd);
|
||||
int peer_fd, int gossip_fd, int gossip_store_fd);
|
||||
|
||||
/* Could be configurable. */
|
||||
#define OUR_CHANNEL_FLAGS CHANNEL_FLAGS_ANNOUNCE_CHANNEL
|
||||
|
||||
@@ -363,7 +363,7 @@ static bool log_status_fail(struct subd *sd, const u8 *msg)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[2])
|
||||
static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[3])
|
||||
{
|
||||
void *channel = sd->channel;
|
||||
struct channel_id channel_id;
|
||||
@@ -378,6 +378,7 @@ static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[2])
|
||||
|
||||
pcomms->peer_fd = fds[0];
|
||||
pcomms->gossip_fd = fds[1];
|
||||
pcomms->gossip_store_fd = fds[2];
|
||||
|
||||
/* Don't free sd; we may be about to free channel. */
|
||||
sd->channel = NULL;
|
||||
@@ -455,11 +456,11 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
|
||||
if (sd->channel) {
|
||||
switch ((enum peer_status)type) {
|
||||
case WIRE_STATUS_PEER_ERROR:
|
||||
/* We expect 2 fds after this */
|
||||
/* We expect 3 fds after this */
|
||||
if (!sd->fds_in) {
|
||||
/* Don't free msg_in: we go around again. */
|
||||
tal_steal(sd, sd->msg_in);
|
||||
plan = sd_collect_fds(conn, sd, 2);
|
||||
plan = sd_collect_fds(conn, sd, 3);
|
||||
goto out;
|
||||
}
|
||||
if (!handle_peer_error(sd, sd->msg_in, sd->fds_in))
|
||||
|
||||
Reference in New Issue
Block a user