From 99e48c7c871255f366300358e5e27ccd2692a5a2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 9 Nov 2016 08:04:25 +1030 Subject: [PATCH] peer: don't differentiate who is funding via state when waiting for open. It doesn't actually help here; we only did it because we differentiate the states later, and with refactoring we do that via the explicit offer_anchor flag. Signed-off-by: Rusty Russell --- daemon/peer.c | 17 ++++++----------- state.h | 6 ------ state_types.h | 3 +-- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/daemon/peer.c b/daemon/peer.c index bee639c4e..78ac41ed2 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -504,9 +504,7 @@ static bool open_pkt_in(struct peer *peer, const Pkt *pkt) Pkt *err; struct commit_info *ci; - /* FIXME: Collapse these two states */ - assert(peer->state == STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR - || peer->state == STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR); + assert(peer->state == STATE_OPEN_WAIT_FOR_OPENPKT); /* FIXME: Handle PKT_SHUTDOWN? */ if (pkt->pkt_case != PKT__PKT_OPEN) @@ -2229,7 +2227,7 @@ static struct io_plan *pkt_in(struct io_conn *conn, struct peer *peer) keep_going = shutdown_pkt_in(peer, peer->inpkt); else if (peer->state == STATE_MUTUAL_CLOSING) keep_going = closing_pkt_in(peer, peer->inpkt); - else if (state_is_waiting_for_open(peer->state)) + else if (peer->state == STATE_OPEN_WAIT_FOR_OPENPKT) keep_going = open_pkt_in(peer, peer->inpkt); else if (state_is_opening(peer->state)) { if (peer->local.offer_anchor) @@ -2599,16 +2597,13 @@ static struct io_plan *peer_crypto_on(struct io_conn *conn, struct peer *peer) assert(peer->state == STATE_INIT); + set_peer_state(peer, STATE_OPEN_WAIT_FOR_OPENPKT, __func__, false); + /* FIXME: Start timeout, and close peer if they don't progress! */ - if (peer->local.offer_anchor) { - set_peer_state(peer, STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR, - __func__, false); + if (peer->local.offer_anchor) anchor = OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR; - } else { - set_peer_state(peer, STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR, - __func__, false); + else anchor = OPEN_CHANNEL__ANCHOR_OFFER__WONT_CREATE_ANCHOR; - } /* FIXME: Delay db write until we have something to keep, or handle * reconnect with STATE_INIT state. */ diff --git a/state.h b/state.h index fce4dd52c..a5507f717 100644 --- a/state.h +++ b/state.h @@ -40,12 +40,6 @@ static inline bool state_is_opening(enum state s) return s < STATE_NORMAL; } -static inline bool state_is_waiting_for_open(enum state s) -{ - return s == STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR - || s == STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR; -} - static inline bool state_is_waiting_for_anchor(enum state s) { return s == STATE_OPEN_WAITING_OURANCHOR diff --git a/state_types.h b/state_types.h index 3f2dc38d4..6ede4f7bf 100644 --- a/state_types.h +++ b/state_types.h @@ -10,8 +10,7 @@ enum state { /* * Opening. */ - STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR, - STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR, + STATE_OPEN_WAIT_FOR_OPENPKT, STATE_OPEN_WAIT_FOR_ANCHOR, STATE_OPEN_WAIT_FOR_COMMIT_SIG, STATE_OPEN_WAITING_OURANCHOR,