Browse Source

channeld: don't manually disable channel.

gossipd will do it when peer dies anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
2d533dc82e
  1. 18
      channeld/channel.c
  2. 2
      closingd/closing.c
  3. 32
      common/read_peer_msg.c
  4. 13
      common/read_peer_msg.h
  5. 1
      openingd/opening.c

18
channeld/channel.c

@ -1627,13 +1627,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
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)
{
/* 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);
}
/* 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,
int peer_fd 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,
&peer->channel_id,
channeld_send_reply,
channeld_io_error,
peer);
}
@ -2659,7 +2645,6 @@ int main(int argc, char *argv[])
fromwire_peektype(msg));
handle_gossip_msg(take(msg), &peer->cs,
channeld_send_reply,
channeld_io_error,
peer);
continue;
}
@ -2712,10 +2697,9 @@ int main(int argc, char *argv[])
/* Gossipd hangs up on us to kill us when a new
* connection comes in. */
if (!msg)
peer_conn_broken(peer);
peer_failed_connection_lost();
handle_gossip_msg(msg, &peer->cs,
channeld_send_reply,
channeld_io_error,
peer);
} else if (FD_ISSET(PEER_FD, &rfds)) {
/* This could take forever, but who cares? */

2
closingd/closing.c

@ -117,7 +117,6 @@ static void do_reconnect(struct crypto_state *cs,
channel_reestablish
= read_peer_msg(tmpctx, cs, channel_id,
sync_crypto_write_arg,
status_fail_io,
NULL);
}
@ -231,7 +230,6 @@ static uint64_t receive_offer(struct crypto_state *cs,
msg = read_peer_msg(tmpctx, cs, channel_id,
sync_crypto_write_arg,
status_fail_io,
NULL);
/* BOLT #2:

32
common/read_peer_msg.c

@ -18,7 +18,6 @@ static void handle_ping(const u8 *msg,
const struct channel_id *channel,
bool (*send_reply)(struct crypto_state *, int,
const u8 *, void *),
void (*io_error)(void *),
void *arg)
{
u8 *pong;
@ -28,7 +27,7 @@ static void handle_ping(const u8 *msg,
take(towire_errorfmt(NULL, channel,
"Bad ping %s",
tal_hex(msg, msg))), arg);
io_error(arg);
peer_failed_connection_lost();
}
status_debug("Got ping, sending %s", pong ?
@ -36,14 +35,13 @@ static void handle_ping(const u8 *msg,
: "nothing");
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,
struct crypto_state *cs,
bool (*send_msg)(struct crypto_state *cs, int fd,
const u8 *TAKES, void *arg),
void (*io_error)(void *arg),
void *arg)
{
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)) {
status_broken("Got bad message from gossipd: %s",
tal_hex(msg, msg));
io_error(arg);
peer_failed_connection_lost();
}
/* Gossipd can send us gossip messages, OR errors */
if (is_msg_for_gossipd(gossip)) {
if (!send_msg(cs, peer_fd, gossip, arg))
io_error(arg);
peer_failed_connection_lost();
} else if (fromwire_peektype(gossip) == WIRE_ERROR) {
status_debug("Gossipd told us to send error");
send_msg(cs, peer_fd, gossip, arg);
io_error(arg);
peer_failed_connection_lost();
} else {
status_broken("Gossipd gave us bad send_gossip message %s",
tal_hex(msg, msg));
io_error(arg);
peer_failed_connection_lost();
}
if (taken(msg))
tal_free(msg);
@ -77,7 +75,6 @@ u8 *read_peer_msg_(const tal_t *ctx,
const struct channel_id *channel,
bool (*send_reply)(struct crypto_state *cs, int fd,
const u8 *TAKES, void *arg),
void (*io_error)(void *arg),
void *arg)
{
u8 *msg;
@ -97,16 +94,16 @@ u8 *read_peer_msg_(const tal_t *ctx,
msg = wire_sync_read(NULL, gossip_fd);
if (!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;
}
msg = sync_crypto_read(ctx, cs, peer_fd);
if (!msg)
io_error(arg);
peer_failed_connection_lost();
if (is_msg_for_gossipd(msg)) {
/* Forward to gossip daemon */
@ -115,8 +112,7 @@ u8 *read_peer_msg_(const tal_t *ctx,
}
if (fromwire_peektype(msg) == WIRE_PING) {
handle_ping(msg, peer_fd, cs, channel,
send_reply, io_error, arg);
handle_ping(msg, peer_fd, cs, channel, send_reply, arg);
return tal_free(msg);
}
@ -158,7 +154,7 @@ u8 *read_peer_msg_(const tal_t *ctx,
"Multiple channels"
" unsupported")),
arg))
io_error(arg);
peer_failed_connection_lost();
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);
}
/* Helper: calls peer_failed_connection_lost. */
void status_fail_io(void *unused UNUSED)
{
peer_failed_connection_lost();
}

13
common/read_peer_msg.h

@ -14,36 +14,29 @@ struct channel_id;
* @cs: the cryptostate (updated)
* @chanid: the channel id (for identifying errors)
* @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
* 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), \
(chanid), \
typesafe_cb_preargs(bool, void *, (send_reply), (arg), \
struct crypto_state *, int, \
const u8 *), \
typesafe_cb(void, void *, (io_error), (arg)), \
arg)
/* Helper: sync_crypto_write, with extra args it ignores */
bool sync_crypto_write_arg(struct crypto_state *cs, int fd, const u8 *TAKES,
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. */
#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), \
typesafe_cb_preargs(bool, void *, \
(send_reply), (arg), \
struct crypto_state *, int, \
const u8 *), \
typesafe_cb(void, void *, (io_error), (arg)), \
arg)
void handle_gossip_msg_(const u8 *msg TAKES,
@ -51,7 +44,6 @@ void handle_gossip_msg_(const u8 *msg TAKES,
struct crypto_state *cs,
bool (*send_msg)(struct crypto_state *cs, int fd,
const u8 *TAKES, void *arg),
void (*io_error)(void *arg),
void *arg);
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,
bool (*send_reply)(struct crypto_state *cs, int fd,
const u8 *TAKES, void *arg),
void (*io_error)(void *arg),
void *arg);
#endif /* LIGHTNING_COMMON_READ_PEER_MSG_H */

1
openingd/opening.c

@ -236,7 +236,6 @@ static u8 *opening_read_peer_msg(struct state *state)
while ((msg = read_peer_msg(state, &state->cs,
&state->channel_id,
sync_crypto_write_arg,
status_fail_io,
state)) == NULL)
clean_tmpctx();

Loading…
Cancel
Save