channeld: don't manually disable channel.
gossipd will do it when peer dies anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8e571ba688
commit
2d533dc82e
|
@ -1627,13 +1627,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
|
||||||
type, wire_type_name(type));
|
type, wire_type_name(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peer_conn_broken(struct peer *peer)
|
|
||||||
{
|
|
||||||
/* If we have signatures, send an update to say we're disabled. */
|
|
||||||
send_channel_update(peer, ROUTING_FLAGS_DISABLED);
|
|
||||||
peer_failed_connection_lost();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void resend_revoke(struct peer *peer)
|
static void resend_revoke(struct peer *peer)
|
||||||
{
|
{
|
||||||
/* Current commit is peer->next_index[LOCAL]-1, revoke prior */
|
/* Current commit is peer->next_index[LOCAL]-1, revoke prior */
|
||||||
|
@ -1733,12 +1726,6 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
|
||||||
peer->revocations_received);
|
peer->revocations_received);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Our local wrapper around read_peer_msg */
|
|
||||||
static void channeld_io_error(struct peer *peer)
|
|
||||||
{
|
|
||||||
peer_conn_broken(peer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool channeld_send_reply(struct crypto_state *cs UNUSED,
|
static bool channeld_send_reply(struct crypto_state *cs UNUSED,
|
||||||
int peer_fd UNUSED,
|
int peer_fd UNUSED,
|
||||||
const u8 *msg UNUSED,
|
const u8 *msg UNUSED,
|
||||||
|
@ -1753,7 +1740,6 @@ static u8 *channeld_read_peer_msg(struct peer *peer)
|
||||||
return read_peer_msg(peer, &peer->cs,
|
return read_peer_msg(peer, &peer->cs,
|
||||||
&peer->channel_id,
|
&peer->channel_id,
|
||||||
channeld_send_reply,
|
channeld_send_reply,
|
||||||
channeld_io_error,
|
|
||||||
peer);
|
peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2659,7 +2645,6 @@ int main(int argc, char *argv[])
|
||||||
fromwire_peektype(msg));
|
fromwire_peektype(msg));
|
||||||
handle_gossip_msg(take(msg), &peer->cs,
|
handle_gossip_msg(take(msg), &peer->cs,
|
||||||
channeld_send_reply,
|
channeld_send_reply,
|
||||||
channeld_io_error,
|
|
||||||
peer);
|
peer);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2712,10 +2697,9 @@ int main(int argc, char *argv[])
|
||||||
/* Gossipd hangs up on us to kill us when a new
|
/* Gossipd hangs up on us to kill us when a new
|
||||||
* connection comes in. */
|
* connection comes in. */
|
||||||
if (!msg)
|
if (!msg)
|
||||||
peer_conn_broken(peer);
|
peer_failed_connection_lost();
|
||||||
handle_gossip_msg(msg, &peer->cs,
|
handle_gossip_msg(msg, &peer->cs,
|
||||||
channeld_send_reply,
|
channeld_send_reply,
|
||||||
channeld_io_error,
|
|
||||||
peer);
|
peer);
|
||||||
} else if (FD_ISSET(PEER_FD, &rfds)) {
|
} else if (FD_ISSET(PEER_FD, &rfds)) {
|
||||||
/* This could take forever, but who cares? */
|
/* This could take forever, but who cares? */
|
||||||
|
|
|
@ -117,7 +117,6 @@ static void do_reconnect(struct crypto_state *cs,
|
||||||
channel_reestablish
|
channel_reestablish
|
||||||
= read_peer_msg(tmpctx, cs, channel_id,
|
= read_peer_msg(tmpctx, cs, channel_id,
|
||||||
sync_crypto_write_arg,
|
sync_crypto_write_arg,
|
||||||
status_fail_io,
|
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +230,6 @@ static uint64_t receive_offer(struct crypto_state *cs,
|
||||||
|
|
||||||
msg = read_peer_msg(tmpctx, cs, channel_id,
|
msg = read_peer_msg(tmpctx, cs, channel_id,
|
||||||
sync_crypto_write_arg,
|
sync_crypto_write_arg,
|
||||||
status_fail_io,
|
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
|
|
|
@ -18,7 +18,6 @@ static void handle_ping(const u8 *msg,
|
||||||
const struct channel_id *channel,
|
const struct channel_id *channel,
|
||||||
bool (*send_reply)(struct crypto_state *, int,
|
bool (*send_reply)(struct crypto_state *, int,
|
||||||
const u8 *, void *),
|
const u8 *, void *),
|
||||||
void (*io_error)(void *),
|
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
u8 *pong;
|
u8 *pong;
|
||||||
|
@ -28,7 +27,7 @@ static void handle_ping(const u8 *msg,
|
||||||
take(towire_errorfmt(NULL, channel,
|
take(towire_errorfmt(NULL, channel,
|
||||||
"Bad ping %s",
|
"Bad ping %s",
|
||||||
tal_hex(msg, msg))), arg);
|
tal_hex(msg, msg))), arg);
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
}
|
}
|
||||||
|
|
||||||
status_debug("Got ping, sending %s", pong ?
|
status_debug("Got ping, sending %s", pong ?
|
||||||
|
@ -36,14 +35,13 @@ static void handle_ping(const u8 *msg,
|
||||||
: "nothing");
|
: "nothing");
|
||||||
|
|
||||||
if (pong && !send_reply(cs, peer_fd, pong, arg))
|
if (pong && !send_reply(cs, peer_fd, pong, arg))
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_gossip_msg_(const u8 *msg TAKES, int peer_fd,
|
void handle_gossip_msg_(const u8 *msg TAKES, int peer_fd,
|
||||||
struct crypto_state *cs,
|
struct crypto_state *cs,
|
||||||
bool (*send_msg)(struct crypto_state *cs, int fd,
|
bool (*send_msg)(struct crypto_state *cs, int fd,
|
||||||
const u8 *TAKES, void *arg),
|
const u8 *TAKES, void *arg),
|
||||||
void (*io_error)(void *arg),
|
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
u8 *gossip;
|
u8 *gossip;
|
||||||
|
@ -51,21 +49,21 @@ void handle_gossip_msg_(const u8 *msg TAKES, int peer_fd,
|
||||||
if (!fromwire_gossip_send_gossip(tmpctx, msg, &gossip)) {
|
if (!fromwire_gossip_send_gossip(tmpctx, msg, &gossip)) {
|
||||||
status_broken("Got bad message from gossipd: %s",
|
status_broken("Got bad message from gossipd: %s",
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gossipd can send us gossip messages, OR errors */
|
/* Gossipd can send us gossip messages, OR errors */
|
||||||
if (is_msg_for_gossipd(gossip)) {
|
if (is_msg_for_gossipd(gossip)) {
|
||||||
if (!send_msg(cs, peer_fd, gossip, arg))
|
if (!send_msg(cs, peer_fd, gossip, arg))
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
} else if (fromwire_peektype(gossip) == WIRE_ERROR) {
|
} else if (fromwire_peektype(gossip) == WIRE_ERROR) {
|
||||||
status_debug("Gossipd told us to send error");
|
status_debug("Gossipd told us to send error");
|
||||||
send_msg(cs, peer_fd, gossip, arg);
|
send_msg(cs, peer_fd, gossip, arg);
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
} else {
|
} else {
|
||||||
status_broken("Gossipd gave us bad send_gossip message %s",
|
status_broken("Gossipd gave us bad send_gossip message %s",
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
}
|
}
|
||||||
if (taken(msg))
|
if (taken(msg))
|
||||||
tal_free(msg);
|
tal_free(msg);
|
||||||
|
@ -77,7 +75,6 @@ u8 *read_peer_msg_(const tal_t *ctx,
|
||||||
const struct channel_id *channel,
|
const struct channel_id *channel,
|
||||||
bool (*send_reply)(struct crypto_state *cs, int fd,
|
bool (*send_reply)(struct crypto_state *cs, int fd,
|
||||||
const u8 *TAKES, void *arg),
|
const u8 *TAKES, void *arg),
|
||||||
void (*io_error)(void *arg),
|
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
@ -97,16 +94,16 @@ u8 *read_peer_msg_(const tal_t *ctx,
|
||||||
msg = wire_sync_read(NULL, gossip_fd);
|
msg = wire_sync_read(NULL, gossip_fd);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
status_debug("Error reading gossip msg");
|
status_debug("Error reading gossip msg");
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_gossip_msg_(msg, peer_fd, cs, send_reply, io_error, arg);
|
handle_gossip_msg_(msg, peer_fd, cs, send_reply, arg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = sync_crypto_read(ctx, cs, peer_fd);
|
msg = sync_crypto_read(ctx, cs, peer_fd);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
|
|
||||||
if (is_msg_for_gossipd(msg)) {
|
if (is_msg_for_gossipd(msg)) {
|
||||||
/* Forward to gossip daemon */
|
/* Forward to gossip daemon */
|
||||||
|
@ -115,8 +112,7 @@ u8 *read_peer_msg_(const tal_t *ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromwire_peektype(msg) == WIRE_PING) {
|
if (fromwire_peektype(msg) == WIRE_PING) {
|
||||||
handle_ping(msg, peer_fd, cs, channel,
|
handle_ping(msg, peer_fd, cs, channel, send_reply, arg);
|
||||||
send_reply, io_error, arg);
|
|
||||||
return tal_free(msg);
|
return tal_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +154,7 @@ u8 *read_peer_msg_(const tal_t *ctx,
|
||||||
"Multiple channels"
|
"Multiple channels"
|
||||||
" unsupported")),
|
" unsupported")),
|
||||||
arg))
|
arg))
|
||||||
io_error(arg);
|
peer_failed_connection_lost();
|
||||||
return tal_free(msg);
|
return tal_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,9 +167,3 @@ bool sync_crypto_write_arg(struct crypto_state *cs, int fd, const u8 *msg,
|
||||||
{
|
{
|
||||||
return sync_crypto_write(cs, fd, msg);
|
return sync_crypto_write(cs, fd, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper: calls peer_failed_connection_lost. */
|
|
||||||
void status_fail_io(void *unused UNUSED)
|
|
||||||
{
|
|
||||||
peer_failed_connection_lost();
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,36 +14,29 @@ struct channel_id;
|
||||||
* @cs: the cryptostate (updated)
|
* @cs: the cryptostate (updated)
|
||||||
* @chanid: the channel id (for identifying errors)
|
* @chanid: the channel id (for identifying errors)
|
||||||
* @send_reply: the way to send a reply packet (eg. sync_crypto_write_arg)
|
* @send_reply: the way to send a reply packet (eg. sync_crypto_write_arg)
|
||||||
* @io_error: what to do if there's an IO error (eg. status_fail_io)
|
|
||||||
* (MUST NOT RETURN!)
|
|
||||||
*
|
*
|
||||||
* This returns NULL if it handled the message, so it's normally called in
|
* This returns NULL if it handled the message, so it's normally called in
|
||||||
* a loop.
|
* a loop.
|
||||||
*/
|
*/
|
||||||
#define read_peer_msg(ctx, cs, chanid, send_reply, io_error, arg) \
|
#define read_peer_msg(ctx, cs, chanid, send_reply, arg) \
|
||||||
read_peer_msg_((ctx), PEER_FD, GOSSIP_FD, (cs), \
|
read_peer_msg_((ctx), PEER_FD, GOSSIP_FD, (cs), \
|
||||||
(chanid), \
|
(chanid), \
|
||||||
typesafe_cb_preargs(bool, void *, (send_reply), (arg), \
|
typesafe_cb_preargs(bool, void *, (send_reply), (arg), \
|
||||||
struct crypto_state *, int, \
|
struct crypto_state *, int, \
|
||||||
const u8 *), \
|
const u8 *), \
|
||||||
typesafe_cb(void, void *, (io_error), (arg)), \
|
|
||||||
arg)
|
arg)
|
||||||
|
|
||||||
/* Helper: sync_crypto_write, with extra args it ignores */
|
/* Helper: sync_crypto_write, with extra args it ignores */
|
||||||
bool sync_crypto_write_arg(struct crypto_state *cs, int fd, const u8 *TAKES,
|
bool sync_crypto_write_arg(struct crypto_state *cs, int fd, const u8 *TAKES,
|
||||||
void *unused);
|
void *unused);
|
||||||
|
|
||||||
/* Helper: calls peer_failed_connection_lost. */
|
|
||||||
void status_fail_io(void *unused);
|
|
||||||
|
|
||||||
/* Handler for a gossip msg; used by channeld since it queues them. */
|
/* Handler for a gossip msg; used by channeld since it queues them. */
|
||||||
#define handle_gossip_msg(msg, cs, send_reply, io_error, arg) \
|
#define handle_gossip_msg(msg, cs, send_reply, arg) \
|
||||||
handle_gossip_msg_((msg), PEER_FD, (cs), \
|
handle_gossip_msg_((msg), PEER_FD, (cs), \
|
||||||
typesafe_cb_preargs(bool, void *, \
|
typesafe_cb_preargs(bool, void *, \
|
||||||
(send_reply), (arg), \
|
(send_reply), (arg), \
|
||||||
struct crypto_state *, int, \
|
struct crypto_state *, int, \
|
||||||
const u8 *), \
|
const u8 *), \
|
||||||
typesafe_cb(void, void *, (io_error), (arg)), \
|
|
||||||
arg)
|
arg)
|
||||||
|
|
||||||
void handle_gossip_msg_(const u8 *msg TAKES,
|
void handle_gossip_msg_(const u8 *msg TAKES,
|
||||||
|
@ -51,7 +44,6 @@ void handle_gossip_msg_(const u8 *msg TAKES,
|
||||||
struct crypto_state *cs,
|
struct crypto_state *cs,
|
||||||
bool (*send_msg)(struct crypto_state *cs, int fd,
|
bool (*send_msg)(struct crypto_state *cs, int fd,
|
||||||
const u8 *TAKES, void *arg),
|
const u8 *TAKES, void *arg),
|
||||||
void (*io_error)(void *arg),
|
|
||||||
void *arg);
|
void *arg);
|
||||||
|
|
||||||
u8 *read_peer_msg_(const tal_t *ctx,
|
u8 *read_peer_msg_(const tal_t *ctx,
|
||||||
|
@ -60,7 +52,6 @@ u8 *read_peer_msg_(const tal_t *ctx,
|
||||||
const struct channel_id *channel,
|
const struct channel_id *channel,
|
||||||
bool (*send_reply)(struct crypto_state *cs, int fd,
|
bool (*send_reply)(struct crypto_state *cs, int fd,
|
||||||
const u8 *TAKES, void *arg),
|
const u8 *TAKES, void *arg),
|
||||||
void (*io_error)(void *arg),
|
|
||||||
void *arg);
|
void *arg);
|
||||||
|
|
||||||
#endif /* LIGHTNING_COMMON_READ_PEER_MSG_H */
|
#endif /* LIGHTNING_COMMON_READ_PEER_MSG_H */
|
||||||
|
|
|
@ -236,7 +236,6 @@ static u8 *opening_read_peer_msg(struct state *state)
|
||||||
while ((msg = read_peer_msg(state, &state->cs,
|
while ((msg = read_peer_msg(state, &state->cs,
|
||||||
&state->channel_id,
|
&state->channel_id,
|
||||||
sync_crypto_write_arg,
|
sync_crypto_write_arg,
|
||||||
status_fail_io,
|
|
||||||
state)) == NULL)
|
state)) == NULL)
|
||||||
clean_tmpctx();
|
clean_tmpctx();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue