mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
state: move first state transition into peer.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
bbd1bbd931
commit
847ce8b092
@ -2329,20 +2329,37 @@ static struct io_plan *peer_send_init(struct io_conn *conn, struct peer *peer)
|
||||
/* Crypto is on, we are live. */
|
||||
static struct io_plan *peer_crypto_on(struct io_conn *conn, struct peer *peer)
|
||||
{
|
||||
OpenChannel__AnchorOffer anchor;
|
||||
|
||||
peer_secrets_init(peer);
|
||||
|
||||
peer_get_revocation_hash(peer, 0, &peer->local.next_revocation_hash);
|
||||
|
||||
assert(peer->state == STATE_INIT);
|
||||
|
||||
/* FIXME: Start timeout, and close peer if they don't progress! */
|
||||
if (peer->local.offer_anchor == CMD_OPEN_WITH_ANCHOR) {
|
||||
set_peer_state(peer, STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR,
|
||||
__func__, false);
|
||||
anchor = OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR;
|
||||
} else {
|
||||
set_peer_state(peer, STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR,
|
||||
__func__, false);
|
||||
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. */
|
||||
if (!db_create_peer(peer))
|
||||
fatal("Database error in %s", __func__);
|
||||
|
||||
/* FIXME: Start timeout, and close peer if they don't progress! */
|
||||
state_event(peer, peer->local.offer_anchor, NULL);
|
||||
/* Set up out commit info now: rest gets done in setup_first_commit
|
||||
* once anchor is established. */
|
||||
peer->local.commit = new_commit_info(peer, 0);
|
||||
peer->local.commit->revocation_hash = peer->local.next_revocation_hash;
|
||||
peer_get_revocation_hash(peer, 1, &peer->local.next_revocation_hash);
|
||||
|
||||
queue_pkt_open(peer, anchor);
|
||||
return peer_send_init(conn,peer);
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ struct commit_info {
|
||||
|
||||
struct peer_visible_state {
|
||||
/* CMD_OPEN_WITH_ANCHOR or CMD_OPEN_WITHOUT_ANCHOR */
|
||||
/* FIXME: Make a bool. */
|
||||
enum state_input offer_anchor;
|
||||
/* Key for commitment tx inputs, then key for commitment tx outputs */
|
||||
struct pubkey commitkey, finalkey;
|
||||
|
26
state.c
26
state.c
@ -22,18 +22,6 @@ static void queue_tx_broadcast(const struct bitcoin_tx **broadcast,
|
||||
*broadcast = tx;
|
||||
}
|
||||
|
||||
static void send_open_pkt(struct peer *peer,
|
||||
OpenChannel__AnchorOffer anchor)
|
||||
{
|
||||
/* Set up out commit info now: rest gets done in setup_first_commit
|
||||
* once anchor is established. */
|
||||
peer->local.commit = new_commit_info(peer, 0);
|
||||
peer->local.commit->revocation_hash = peer->local.next_revocation_hash;
|
||||
peer_get_revocation_hash(peer, 1, &peer->local.next_revocation_hash);
|
||||
|
||||
queue_pkt_open(peer, anchor);
|
||||
}
|
||||
|
||||
static Pkt *init_from_pkt_open(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
struct commit_info *ci = new_commit_info(peer, 0);
|
||||
@ -72,19 +60,6 @@ enum state state(struct peer *peer,
|
||||
/*
|
||||
* Initial channel opening states.
|
||||
*/
|
||||
case STATE_INIT:
|
||||
if (input_is(input, CMD_OPEN_WITH_ANCHOR)) {
|
||||
send_open_pkt(peer,
|
||||
OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR);
|
||||
return next_state(peer,
|
||||
STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR);
|
||||
} else if (input_is(input, CMD_OPEN_WITHOUT_ANCHOR)) {
|
||||
send_open_pkt(peer,
|
||||
OPEN_CHANNEL__ANCHOR_OFFER__WONT_CREATE_ANCHOR);
|
||||
return next_state(peer,
|
||||
STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR);
|
||||
}
|
||||
break;
|
||||
case STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR:
|
||||
if (input_is(input, PKT_OPEN)) {
|
||||
err = init_from_pkt_open(peer, pkt);
|
||||
@ -276,6 +251,7 @@ enum state state(struct peer *peer,
|
||||
break;
|
||||
|
||||
/* Should never happen. */
|
||||
case STATE_INIT:
|
||||
case STATE_NORMAL:
|
||||
case STATE_NORMAL_COMMITTING:
|
||||
case STATE_ERR_INTERNAL:
|
||||
|
Loading…
Reference in New Issue
Block a user