From fea7e10e159a161a6ca10ff02d87c114dcea4a6b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 25 Jul 2019 12:17:34 +0930 Subject: [PATCH] lightningd: make callers of channel_set_owner do reconnection. There's only one caller which used the flag. As a side-effect, now we'll try reconnect even if the previous owner was NULL (which mainly effects the case where we couldn't create the subd). Signed-off-by: Rusty Russell --- lightningd/channel.c | 19 ++++++++----------- lightningd/channel.h | 3 +-- lightningd/channel_control.c | 3 +-- lightningd/closing_control.c | 5 ++--- lightningd/onchain_control.c | 7 +++---- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/lightningd/channel.c b/lightningd/channel.c index 3a29f3930..f441a9c89 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -23,8 +23,7 @@ static bool connects_to_peer(struct subd *owner) return owner && owner->talks_to_peer; } -void channel_set_owner(struct channel *channel, struct subd *owner, - bool reconnect) +void channel_set_owner(struct channel *channel, struct subd *owner) { struct subd *old_owner = channel->owner; channel->owner = owner; @@ -46,12 +45,6 @@ void channel_set_owner(struct channel *channel, struct subd *owner, take(msg)); } } - - if (reconnect) { - /* Reconnect after 1 second: prevents some spurious - * reconnects during tests. */ - delay_then_reconnect(channel, 1, &channel->peer->addr); - } } channel->connected = connects_to_peer(owner); } @@ -105,7 +98,7 @@ static void destroy_channel(struct channel *channel) htlc_state_name(hin->hstate)); /* Free any old owner still hanging around. */ - channel_set_owner(channel, NULL, false); + channel_set_owner(channel, NULL); list_del_from(&channel->peer->channels, &channel->list); } @@ -379,7 +372,7 @@ void channel_fail_permanent(struct channel *channel, const char *fmt, ...) channel->error = towire_errorfmt(channel, &cid, "%s", why); } - channel_set_owner(channel, NULL, false); + channel_set_owner(channel, NULL); /* Drop non-cooperatively (unilateral) to chain. */ drop_to_chain(ld, channel, false); @@ -446,5 +439,9 @@ void channel_fail_transient(struct channel *channel, const char *fmt, ...) } #endif - channel_set_owner(channel, NULL, true); + channel_set_owner(channel, NULL); + + /* Reconnect after 1 second: prevents some spurious reconnects + * during tests. */ + delay_then_reconnect(channel, 1, &channel->peer->addr); } diff --git a/lightningd/channel.h b/lightningd/channel.h index df48d3ada..7dce3a5bc 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -172,8 +172,7 @@ void delete_channel(struct channel *channel); const char *channel_state_name(const struct channel *channel); const char *channel_state_str(enum channel_state state); -void channel_set_owner(struct channel *channel, struct subd *owner, - bool reconnect); +void channel_set_owner(struct channel *channel, struct subd *owner); /* Channel has failed, but can try again. */ PRINTF_FMT(2,3) void channel_fail_transient(struct channel *channel, diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 5ed5e40ff..4c8c6f017 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -312,8 +312,7 @@ void peer_start_channeld(struct channel *channel, take(&pps->peer_fd), take(&pps->gossip_fd), take(&pps->gossip_store_fd), - take(&hsmfd), NULL), - false); + take(&hsmfd), NULL)); if (!channel->owner) { log_unusual(channel->log, "Could not subdaemon channel: %s", diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 0f3f49628..b7eb56221 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -116,7 +116,7 @@ static void peer_closing_complete(struct channel *channel, const u8 *msg) } /* Don't report spurious failure when closingd exits. */ - channel_set_owner(channel, NULL, false); + channel_set_owner(channel, NULL); /* Clear any transient negotiation messages */ channel_set_billboard(channel, false, NULL); @@ -186,8 +186,7 @@ void peer_start_closingd(struct channel *channel, take(&pps->gossip_fd), take(&pps->gossip_store_fd), take(&hsmfd), - NULL), - false); + NULL)); if (!channel->owner) { log_unusual(channel->log, "Could not subdaemon closing: %s", diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 25c891fb3..08d7cd28c 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -102,7 +102,7 @@ static enum watch_result onchain_tx_watched(struct lightningd *ld, if (depth == 0) { log_unusual(channel->log, "Chain reorganization!"); - channel_set_owner(channel, NULL, false); + channel_set_owner(channel, NULL); /* We will most likely be freed, so this is a noop */ return KEEP_WATCHING; @@ -421,7 +421,7 @@ static void onchain_error(struct channel *channel, /* FIXME: re-launch? */ log_broken(channel->log, "%s", desc); channel_set_billboard(channel, true, desc); - channel_set_owner(channel, NULL, false); + channel_set_owner(channel, NULL); } /* With a reorg, this can get called multiple times; each time we'll kill @@ -457,8 +457,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, onchain_error, channel_set_billboard, take(&hsmfd), - NULL), - false); + NULL)); if (!channel->owner) { log_broken(channel->log, "Could not subdaemon onchain: %s",