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:
Rusty Russell
2019-05-04 15:23:13 +09:30
parent eaac0d7105
commit 13717c6ebb
24 changed files with 114 additions and 61 deletions

View File

@@ -9,7 +9,7 @@
#include <stdarg.h>
/* We only support one channel per peer anyway */
void peer_failed_(int peer_fd, int gossip_fd,
void peer_failed_(int peer_fd, int gossip_fd, int gossip_store_fd,
struct crypto_state *cs,
const struct channel_id *channel_id,
const char *fmt, ...)
@@ -32,11 +32,11 @@ void peer_failed_(int peer_fd, int gossip_fd,
err);
peer_billboard(true, desc);
tal_free(desc);
status_send_fatal(take(msg), peer_fd, gossip_fd);
status_send_fatal(take(msg), peer_fd, gossip_fd, gossip_store_fd);
}
/* We're failing because peer sent us an error message */
void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
void peer_failed_received_errmsg(int peer_fd, int gossip_fd, int gossip_store_fd,
struct crypto_state *cs,
const char *desc,
const struct channel_id *channel_id)
@@ -48,11 +48,11 @@ void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
channel_id = &all_channels;
msg = towire_status_peer_error(NULL, channel_id, desc, cs, NULL);
peer_billboard(true, "Received error from peer: %s", desc);
status_send_fatal(take(msg), peer_fd, gossip_fd);
status_send_fatal(take(msg), peer_fd, gossip_fd, gossip_store_fd);
}
void peer_failed_connection_lost(void)
{
status_send_fatal(take(towire_status_peer_connection_lost(NULL)),
-1, -1);
-1, -1, -1);
}

View File

@@ -12,18 +12,19 @@ struct channel_id;
* @channel_id: channel with error, or NULL for all.
* @fmt...: format as per status_failed(STATUS_FAIL_PEER_BAD)
*/
#define peer_failed(cs, channel_id, ...) \
peer_failed_(PEER_FD, GOSSIP_FD, (cs), (channel_id), __VA_ARGS__)
#define peer_failed(cs, channel_id, ...) \
peer_failed_(PEER_FD, GOSSIP_FD, GOSSIP_STORE_FD, \
(cs), (channel_id), __VA_ARGS__)
void peer_failed_(int peer_fd, int gossip_fd,
void peer_failed_(int peer_fd, int gossip_fd, int gossip_store_fd,
struct crypto_state *cs,
const struct channel_id *channel_id,
const char *fmt, ...)
PRINTF_FMT(5,6) NORETURN;
PRINTF_FMT(6,7) NORETURN;
/* We're failing because peer sent us an error message: NULL
* channel_id means all channels. */
void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
void peer_failed_received_errmsg(int peer_fd, int gossip_fd, int gossip_store_fd,
struct crypto_state *cs,
const char *desc,
const struct channel_id *channel_id) NORETURN;

View File

@@ -106,7 +106,7 @@ void handle_gossip_msg(int peer_fd, struct crypto_state *cs, const u8 *msg TAKES
tal_free(msg);
}
bool handle_peer_gossip_or_error(int peer_fd, int gossip_fd,
bool handle_peer_gossip_or_error(int peer_fd, int gossip_fd, int gossip_store_fd,
struct crypto_state *cs,
const struct channel_id *channel_id,
const u8 *msg TAKES)
@@ -124,6 +124,7 @@ bool handle_peer_gossip_or_error(int peer_fd, int gossip_fd,
if (is_peer_error(tmpctx, msg, channel_id, &err, &all_channels)) {
if (err)
peer_failed_received_errmsg(peer_fd, gossip_fd,
gossip_store_fd,
cs, err,
all_channels
? NULL : channel_id);

View File

@@ -57,7 +57,7 @@ bool is_wrong_channel(const u8 *msg, const struct channel_id *expected,
/**
* handle_peer_gossip_or_error - simple handler for all the above cases.
* @peer_fd, @gossip_fd: peer and gossip fd.
* @peer_fd, @gossip_fd, @gossip_store_fd: peer, gossip and gossip_store fds.
* @cs: the cryptostate (updated)
* @msg: the peer message (only taken if returns true).
*
@@ -65,7 +65,7 @@ bool is_wrong_channel(const u8 *msg, const struct channel_id *expected,
* to gossipd), an error packet (causes peer_failed_received_errmsg or
* ignored), or a message about the wrong channel (sends sync error reply).
*/
bool handle_peer_gossip_or_error(int peer_fd, int gossip_fd,
bool handle_peer_gossip_or_error(int peer_fd, int gossip_fd, int gossip_store_fd,
struct crypto_state *cs,
const struct channel_id *channel_id,
const u8 *msg TAKES);

View File

@@ -162,7 +162,7 @@ static NORETURN void flush_and_exit(int reason)
exit(0x80 | (reason & 0xFF));
}
void status_send_fatal(const u8 *msg TAKES, int fd1, int fd2)
void status_send_fatal(const u8 *msg TAKES, int fd1, int fd2, int fd3)
{
int reason = fromwire_peektype(msg);
breakpoint();
@@ -173,6 +173,7 @@ void status_send_fatal(const u8 *msg TAKES, int fd1, int fd2)
assert(!status_conn);
fdpass_send(status_fd, fd1);
fdpass_send(status_fd, fd2);
fdpass_send(status_fd, fd3);
}
flush_and_exit(reason);
@@ -193,7 +194,7 @@ void status_failed(enum status_failreason reason, const char *fmt, ...)
send_backtrace(str);
status_send_fatal(take(towire_status_fail(NULL, reason, str)),
-1, -1);
-1, -1, -1);
}
void master_badmsg(u32 type_expected, const u8 *msg)

View File

@@ -51,5 +51,5 @@ void status_failed(enum status_failreason code,
void master_badmsg(u32 type_expected, const u8 *msg) NORETURN;
void status_send(const u8 *msg TAKES);
void status_send_fatal(const u8 *msg TAKES, int fd1, int fd2) NORETURN;
void status_send_fatal(const u8 *msg TAKES, int fd1, int fd2, int fd3) NORETURN;
#endif /* LIGHTNING_COMMON_STATUS_H */