From c05f63a4db90dd9de2fa3fdf338b05f0b46ab65a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 1 Jul 2017 11:11:17 +0930 Subject: [PATCH] peer_control: fix double-state transition on reconnect. We actually don't need to transition if we're reconnecting, and logic to go to CHANNELD_NORMAL was wrong: we checked that we'd seen funding tx locked, but not that we'd received a msg from the remote peer. We need to fix the tests now we no longer double-transition, too. Fixes: #188 Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 13 +++++-------- tests/test_lightningd.py | 4 +--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index c0d003f37..4c38e8dc3 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -172,7 +172,6 @@ void peer_set_condition(struct peer *peer, enum peer_state old_state, /* FIXME: Reshuffle. */ static bool peer_start_channeld(struct peer *peer, - enum peer_state old_state, const struct crypto_state *cs, int peer_fd, int gossip_fd, const u8 *funding_signed); @@ -232,8 +231,7 @@ static bool get_peer_gossipfd_reply(struct subd *subd, const u8 *msg, } /* We never re-transmit funding_signed. */ - peer_start_channeld(peer, peer->state, &ggf->cs, ggf->peer_fd, fds[0], - NULL); + peer_start_channeld(peer, &ggf->cs, ggf->peer_fd, fds[0], NULL); goto out; close_gossipfd: @@ -863,7 +861,8 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc, command_success(fc->cmd, null_response(fc->cmd)); /* Start normal channel daemon. */ - peer_start_channeld(fc->peer, OPENINGD, cs, peer_fd, gossip_fd, NULL); + peer_start_channeld(fc->peer, cs, peer_fd, gossip_fd, NULL); + peer_set_condition(fc->peer, OPENINGD, CHANNELD_AWAITING_LOCKIN); wallet_confirm_utxos(fc->peer->ld->wallet, fc->utxomap); tal_free(fc); @@ -1117,7 +1116,6 @@ static int channel_msg(struct subd *sd, const u8 *msg, const int *unused) } static bool peer_start_channeld(struct peer *peer, - enum peer_state old_state, const struct crypto_state *cs, int peer_fd, int gossip_fd, const u8 *funding_signed) @@ -1176,10 +1174,8 @@ static bool peer_start_channeld(struct peer *peer, if (peer->scid) { funding_channel_id = *peer->scid; log_debug(peer->log, "Already have funding locked in"); - peer_set_condition(peer, old_state, CHANNELD_NORMAL); } else { log_debug(peer->log, "Waiting for funding confirmations"); - peer_set_condition(peer, old_state, CHANNELD_AWAITING_LOCKIN); memset(&funding_channel_id, 0, sizeof(funding_channel_id)); } @@ -1396,7 +1392,8 @@ static bool opening_fundee_finished(struct subd *opening, peer->owner = NULL; /* On to normal operation! */ - peer_start_channeld(peer, OPENINGD, &cs, fds[0], fds[1], funding_signed); + peer_start_channeld(peer, &cs, fds[0], fds[1], funding_signed); + peer_set_condition(peer, OPENINGD, CHANNELD_AWAITING_LOCKIN); /* Tell opening daemon to exit. */ return false; diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 3f451b98a..039a32db4 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -572,10 +572,8 @@ class LightningDTests(BaseLightningDTests): # Technically, this is async to fundchannel. l1.daemon.wait_for_log('sendrawtx exit 0') - # Wait for reconnect, then another ->LOCKIN transition. + # Wait for reconnect, awaiting lockin.. l1.daemon.wait_for_log('Peer has reconnected, state CHANNELD_AWAITING_LOCKIN'); - l1.daemon.wait_for_log('-> CHANNELD_AWAITING_LOCKIN', 100) - l2.daemon.wait_for_log('-> CHANNELD_AWAITING_LOCKIN', 100) l1.bitcoin.rpc.generate(6)