Browse Source

state: remove unused input parameter from next_state()

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
2a603ea36d
  1. 45
      state.c

45
state.c

@ -8,9 +8,7 @@
#include <names.h> #include <names.h>
#include <state.h> #include <state.h>
static enum state next_state(struct peer *peer, static enum state next_state(struct peer *peer, const enum state state)
const enum state_input input,
const enum state state)
{ {
assert(peer->state != state); assert(peer->state != state);
return state; return state;
@ -78,12 +76,12 @@ enum state state(struct peer *peer,
if (input_is(input, CMD_OPEN_WITH_ANCHOR)) { if (input_is(input, CMD_OPEN_WITH_ANCHOR)) {
send_open_pkt(peer, send_open_pkt(peer,
OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR); OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR);
return next_state(peer, input, return next_state(peer,
STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR); STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR);
} else if (input_is(input, CMD_OPEN_WITHOUT_ANCHOR)) { } else if (input_is(input, CMD_OPEN_WITHOUT_ANCHOR)) {
send_open_pkt(peer, send_open_pkt(peer,
OPEN_CHANNEL__ANCHOR_OFFER__WONT_CREATE_ANCHOR); OPEN_CHANNEL__ANCHOR_OFFER__WONT_CREATE_ANCHOR);
return next_state(peer, input, return next_state(peer,
STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR); STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR);
} }
break; break;
@ -94,7 +92,7 @@ enum state state(struct peer *peer,
peer_open_complete(peer, err->error->problem); peer_open_complete(peer, err->error->problem);
goto err_breakdown; goto err_breakdown;
} }
return next_state(peer, input, STATE_OPEN_WAIT_FOR_ANCHOR); return next_state(peer, STATE_OPEN_WAIT_FOR_ANCHOR);
} else if (input_is_pkt(input)) { } else if (input_is_pkt(input)) {
peer_open_complete(peer, "unexpected packet"); peer_open_complete(peer, "unexpected packet");
goto unexpected_pkt; goto unexpected_pkt;
@ -118,8 +116,7 @@ enum state state(struct peer *peer,
goto err_breakdown; goto err_breakdown;
} }
queue_pkt_anchor(peer); queue_pkt_anchor(peer);
return next_state(peer, input, return next_state(peer, STATE_OPEN_WAIT_FOR_COMMIT_SIG);
STATE_OPEN_WAIT_FOR_COMMIT_SIG);
} else if (input_is_pkt(input)) { } else if (input_is_pkt(input)) {
peer_open_complete(peer, "unexpected packet"); peer_open_complete(peer, "unexpected packet");
goto unexpected_pkt; goto unexpected_pkt;
@ -190,8 +187,7 @@ enum state state(struct peer *peer,
BITCOIN_ANCHOR_DEPTHOK, BITCOIN_ANCHOR_DEPTHOK,
BITCOIN_ANCHOR_TIMEOUT); BITCOIN_ANCHOR_TIMEOUT);
return next_state(peer, input, return next_state(peer, STATE_OPEN_WAITING_THEIRANCHOR);
STATE_OPEN_WAITING_THEIRANCHOR);
} else if (input_is_pkt(input)) { } else if (input_is_pkt(input)) {
peer_open_complete(peer, "unexpected packet"); peer_open_complete(peer, "unexpected packet");
goto unexpected_pkt; goto unexpected_pkt;
@ -248,8 +244,7 @@ enum state state(struct peer *peer,
peer->local.mindepth, peer->local.mindepth,
BITCOIN_ANCHOR_DEPTHOK, BITCOIN_ANCHOR_DEPTHOK,
INPUT_NONE); INPUT_NONE);
return next_state(peer, input, return next_state(peer, STATE_OPEN_WAITING_OURANCHOR);
STATE_OPEN_WAITING_OURANCHOR);
} else if (input_is_pkt(input)) { } else if (input_is_pkt(input)) {
bitcoin_release_anchor(peer, INPUT_NONE); bitcoin_release_anchor(peer, INPUT_NONE);
peer_open_complete(peer, "unexpected packet"); peer_open_complete(peer, "unexpected packet");
@ -263,7 +258,7 @@ enum state state(struct peer *peer,
peer_open_complete(peer, err->error->problem); peer_open_complete(peer, err->error->problem);
goto err_breakdown; goto err_breakdown;
} }
return next_state(peer, input, return next_state(peer,
STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED); STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED);
} }
/* Fall thru */ /* Fall thru */
@ -272,9 +267,9 @@ enum state state(struct peer *peer,
queue_pkt_open_complete(peer); queue_pkt_open_complete(peer);
if (peer->state == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED) { if (peer->state == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED) {
peer_open_complete(peer, NULL); peer_open_complete(peer, NULL);
return next_state(peer, input, STATE_NORMAL); return next_state(peer, STATE_NORMAL);
} }
return next_state(peer, input, return next_state(peer,
STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR); STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR);
} else if (input_is(input, PKT_CLOSE_SHUTDOWN)) { } else if (input_is(input, PKT_CLOSE_SHUTDOWN)) {
peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN"); peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN");
@ -291,7 +286,7 @@ enum state state(struct peer *peer,
peer_open_complete(peer, err->error->problem); peer_open_complete(peer, err->error->problem);
goto err_breakdown; goto err_breakdown;
} }
return next_state(peer, input, return next_state(peer,
STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED); STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED);
} }
/* Fall thru */ /* Fall thru */
@ -299,14 +294,14 @@ enum state state(struct peer *peer,
if (input_is(input, BITCOIN_ANCHOR_TIMEOUT)) { if (input_is(input, BITCOIN_ANCHOR_TIMEOUT)) {
/* Anchor didn't reach blockchain in reasonable time. */ /* Anchor didn't reach blockchain in reasonable time. */
queue_pkt_err(peer, pkt_err(peer, "Anchor timed out")); queue_pkt_err(peer, pkt_err(peer, "Anchor timed out"));
return next_state(peer, input, STATE_ERR_ANCHOR_TIMEOUT); return next_state(peer, STATE_ERR_ANCHOR_TIMEOUT);
} else if (input_is(input, BITCOIN_ANCHOR_DEPTHOK)) { } else if (input_is(input, BITCOIN_ANCHOR_DEPTHOK)) {
queue_pkt_open_complete(peer); queue_pkt_open_complete(peer);
if (peer->state == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED) { if (peer->state == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED) {
peer_open_complete(peer, NULL); peer_open_complete(peer, NULL);
return next_state(peer, input, STATE_NORMAL); return next_state(peer, STATE_NORMAL);
} }
return next_state(peer, input, return next_state(peer,
STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR); STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR);
} else if (input_is(input, PKT_CLOSE_SHUTDOWN)) { } else if (input_is(input, PKT_CLOSE_SHUTDOWN)) {
peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN"); peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN");
@ -321,7 +316,7 @@ enum state state(struct peer *peer,
if (input_is(input, PKT_OPEN_COMPLETE)) { if (input_is(input, PKT_OPEN_COMPLETE)) {
/* Ready for business! */ /* Ready for business! */
peer_open_complete(peer, NULL); peer_open_complete(peer, NULL);
return next_state(peer, input, STATE_NORMAL); return next_state(peer, STATE_NORMAL);
} else if (input_is(input, PKT_CLOSE_SHUTDOWN)) { } else if (input_is(input, PKT_CLOSE_SHUTDOWN)) {
peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN"); peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN");
goto accept_shutdown; goto accept_shutdown;
@ -347,11 +342,11 @@ enum state state(struct peer *peer,
case STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL: case STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL:
case STATE_CLOSE_ONCHAIN_OUR_UNILATERAL: case STATE_CLOSE_ONCHAIN_OUR_UNILATERAL:
case STATE_CLOSE_ONCHAIN_MUTUAL: case STATE_CLOSE_ONCHAIN_MUTUAL:
return next_state(peer, input, STATE_ERR_INTERNAL); return next_state(peer, STATE_ERR_INTERNAL);
} }
/* State machine should handle all possible states. */ /* State machine should handle all possible states. */
return next_state(peer, input, STATE_ERR_INTERNAL); return next_state(peer, STATE_ERR_INTERNAL);
unexpected_pkt: unexpected_pkt:
peer_unexpected_pkt(peer, pkt, __func__); peer_unexpected_pkt(peer, pkt, __func__);
@ -366,7 +361,7 @@ unexpected_pkt:
err_breakdown: err_breakdown:
queue_pkt_err(peer, err); queue_pkt_err(peer, err);
breakdown: breakdown:
return next_state(peer, input, STATE_ERR_BREAKDOWN); return next_state(peer, STATE_ERR_BREAKDOWN);
accept_shutdown: accept_shutdown:
err = accept_pkt_close_shutdown(peer, pkt); err = accept_pkt_close_shutdown(peer, pkt);
@ -375,6 +370,6 @@ accept_shutdown:
/* If we've sent commit, we're still waiting for it when shutdown. */ /* If we've sent commit, we're still waiting for it when shutdown. */
if (peer->state == STATE_NORMAL_COMMITTING) if (peer->state == STATE_NORMAL_COMMITTING)
return next_state(peer, input, STATE_SHUTDOWN_COMMITTING); return next_state(peer, STATE_SHUTDOWN_COMMITTING);
return next_state(peer, input, STATE_SHUTDOWN); return next_state(peer, STATE_SHUTDOWN);
} }

Loading…
Cancel
Save