diff --git a/state.c b/state.c index f7ed14381..00f415f4e 100644 --- a/state.c +++ b/state.c @@ -95,8 +95,7 @@ enum command_status state(const tal_t *ctx, const enum state_input input, const union input *idata, Pkt **out, - struct bitcoin_tx **broadcast, - struct state_effect **effect) + struct bitcoin_tx **broadcast) { Pkt *decline; struct bitcoin_tx *tx; @@ -106,9 +105,6 @@ enum command_status state(const tal_t *ctx, *out = NULL; *broadcast = NULL; - /* NULL-terminated linked list. */ - *effect = NULL; - switch (peer->state) { /* * Initial channel opening states. @@ -132,7 +128,7 @@ enum command_status state(const tal_t *ctx, break; case STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR: if (input_is(input, PKT_OPEN)) { - err = accept_pkt_open(ctx, peer, idata->pkt, effect); + err = accept_pkt_open(ctx, peer, idata->pkt); if (err) { complete_cmd(peer, &cstatus, CMD_FAIL); goto err_close_nocleanup; @@ -148,7 +144,7 @@ enum command_status state(const tal_t *ctx, break; case STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR: if (input_is(input, PKT_OPEN)) { - err = accept_pkt_open(ctx, peer, idata->pkt, effect); + err = accept_pkt_open(ctx, peer, idata->pkt); if (err) { complete_cmd(peer, &cstatus, CMD_FAIL); goto err_close_nocleanup; @@ -166,7 +162,7 @@ enum command_status state(const tal_t *ctx, break; case STATE_OPEN_WAIT_FOR_ANCHOR: if (input_is(input, PKT_OPEN_ANCHOR)) { - err = accept_pkt_anchor(ctx, peer, idata->pkt, effect); + err = accept_pkt_anchor(ctx, peer, idata->pkt); if (err) { complete_cmd(peer, &cstatus, CMD_FAIL); goto err_close_nocleanup; @@ -192,8 +188,7 @@ enum command_status state(const tal_t *ctx, break; case STATE_OPEN_WAIT_FOR_COMMIT_SIG: if (input_is(input, PKT_OPEN_COMMIT_SIG)) { - err = accept_pkt_open_commit_sig(ctx, peer, idata->pkt, - effect); + err = accept_pkt_open_commit_sig(ctx, peer, idata->pkt); if (err) { complete_cmd(peer, &cstatus, CMD_FAIL); goto err_start_unilateral_close; @@ -600,8 +595,7 @@ enum command_status state(const tal_t *ctx, case STATE_WAIT_FOR_CLOSE_COMPLETE: if (input_is(input, PKT_CLOSE_COMPLETE)) { - err = accept_pkt_close_complete(ctx, peer, idata->pkt, - effect); + err = accept_pkt_close_complete(ctx, peer, idata->pkt); if (err) goto err_start_unilateral_close_already_closing; queue_pkt(out, @@ -612,8 +606,7 @@ enum command_status state(const tal_t *ctx, } else if (input_is(input, PKT_CLOSE)) { /* We can use the sig just like CLOSE_COMPLETE */ err = accept_pkt_simultaneous_close(ctx, peer, - idata->pkt, - effect); + idata->pkt); if (err) goto err_start_unilateral_close_already_closing; queue_pkt(out, @@ -636,8 +629,7 @@ enum command_status state(const tal_t *ctx, case STATE_WAIT_FOR_CLOSE_ACK: if (input_is(input, PKT_CLOSE_ACK)) { - err = accept_pkt_close_ack(ctx, peer, idata->pkt, - effect); + err = accept_pkt_close_ack(ctx, peer, idata->pkt); if (err) queue_pkt(out, err); set_peer_cond(peer, PEER_CLOSED); @@ -997,7 +989,7 @@ them_unilateral: return next_state(peer, cstatus, STATE_CLOSE_WAIT_SPENDTHEM); accept_htlc_update: - err = accept_pkt_htlc_update(ctx, peer, idata->pkt, &decline, effect); + err = accept_pkt_htlc_update(ctx, peer, idata->pkt, &decline); if (err) goto err_start_unilateral_close; if (decline) { @@ -1014,7 +1006,7 @@ accept_htlc_update: prio(peer->state, STATE_WAIT_FOR_UPDATE_SIG)); accept_htlc_routefail: - err = accept_pkt_htlc_routefail(ctx, peer, idata->pkt, effect); + err = accept_pkt_htlc_routefail(ctx, peer, idata->pkt); if (err) goto err_start_unilateral_close; queue_pkt(out, pkt_update_accept(ctx, peer)); @@ -1022,7 +1014,7 @@ accept_htlc_routefail: prio(peer->state, STATE_WAIT_FOR_UPDATE_SIG)); accept_htlc_timedout: - err = accept_pkt_htlc_timedout(ctx, peer, idata->pkt, effect); + err = accept_pkt_htlc_timedout(ctx, peer, idata->pkt); if (err) goto err_start_unilateral_close; queue_pkt(out, pkt_update_accept(ctx, peer)); @@ -1056,7 +1048,7 @@ start_closing: return next_state(peer, cstatus, STATE_WAIT_FOR_CLOSE_COMPLETE); accept_closing: - err = accept_pkt_close(ctx, peer, idata->pkt, effect); + err = accept_pkt_close(ctx, peer, idata->pkt); if (err) goto err_start_unilateral_close; peer_watch_close(peer, BITCOIN_CLOSE_DONE, INPUT_NONE); diff --git a/state.h b/state.h index 41037eb95..28b2cf9d1 100644 --- a/state.h +++ b/state.h @@ -21,7 +21,6 @@ static inline bool state_is_error(enum state s) struct peer; struct bitcoin_tx; -struct state_effect; static inline bool input_is_pkt(enum state_input input) { @@ -41,8 +40,7 @@ enum command_status state(const tal_t *ctx, const enum state_input input, const union input *idata, Pkt **out, - struct bitcoin_tx **broadcast, - struct state_effect **effect); + struct bitcoin_tx **broadcast); /* Any CMD_SEND_HTLC_* */ #define CMD_SEND_UPDATE_ANY INPUT_MAX @@ -124,31 +122,25 @@ Pkt *pkt_err_unexpected(const tal_t *ctx, const Pkt *pkt); /* Process various packets: return an error packet on failure. */ Pkt *accept_pkt_open(const tal_t *ctx, - const struct peer *peer, - const Pkt *pkt, - struct state_effect **effect); + struct peer *peer, + const Pkt *pkt); Pkt *accept_pkt_anchor(const tal_t *ctx, - const struct peer *peer, - const Pkt *pkt, - struct state_effect **effect); + struct peer *peer, + const Pkt *pkt); Pkt *accept_pkt_open_commit_sig(const tal_t *ctx, - const struct peer *peer, const Pkt *pkt, - struct state_effect **effect); + struct peer *peer, const Pkt *pkt); Pkt *accept_pkt_htlc_update(const tal_t *ctx, struct peer *peer, const Pkt *pkt, - Pkt **decline, - struct state_effect **effect); + Pkt **decline); Pkt *accept_pkt_htlc_routefail(const tal_t *ctx, - struct peer *peer, const Pkt *pkt, - struct state_effect **effect); + struct peer *peer, const Pkt *pkt); Pkt *accept_pkt_htlc_timedout(const tal_t *ctx, - struct peer *peer, const Pkt *pkt, - struct state_effect **effect); + struct peer *peer, const Pkt *pkt); Pkt *accept_pkt_htlc_fulfill(const tal_t *ctx, struct peer *peer, const Pkt *pkt); @@ -163,22 +155,16 @@ Pkt *accept_pkt_update_signature(const tal_t *ctx, struct peer *peer, const Pkt *pkt); -Pkt *accept_pkt_close(const tal_t *ctx, - const struct peer *peer, const Pkt *pkt, - struct state_effect **effect); +Pkt *accept_pkt_close(const tal_t *ctx, struct peer *peer, const Pkt *pkt); Pkt *accept_pkt_close_complete(const tal_t *ctx, - const struct peer *peer, const Pkt *pkt, - struct state_effect **effect); + struct peer *peer, const Pkt *pkt); Pkt *accept_pkt_simultaneous_close(const tal_t *ctx, - const struct peer *peer, - const Pkt *pkt, - struct state_effect **effect); + struct peer *peer, + const Pkt *pkt); -Pkt *accept_pkt_close_ack(const tal_t *ctx, - const struct peer *peer, const Pkt *pkt, - struct state_effect **effect); +Pkt *accept_pkt_close_ack(const tal_t *ctx, struct peer *peer, const Pkt *pkt); /** * committed_to_htlcs: do we have any locked-in HTLCs? diff --git a/test/test_state_coverage.c b/test/test_state_coverage.c index 8c122936a..e5564a120 100644 --- a/test/test_state_coverage.c +++ b/test/test_state_coverage.c @@ -678,17 +678,15 @@ Pkt *pkt_err_unexpected(const tal_t *ctx, const Pkt *pkt) } Pkt *accept_pkt_open(const tal_t *ctx, - const struct peer *peer, - const Pkt *pkt, struct state_effect **effect) + struct peer *peer, + const Pkt *pkt) { if (fail(peer, FAIL_ACCEPT_OPEN)) return pkt_err(ctx, "Error inject"); return NULL; } -Pkt *accept_pkt_anchor(const tal_t *ctx, - const struct peer *peer, - const Pkt *pkt, struct state_effect **effect) +Pkt *accept_pkt_anchor(const tal_t *ctx, struct peer *peer, const Pkt *pkt) { if (fail(peer, FAIL_ACCEPT_ANCHOR)) return pkt_err(ctx, "Error inject"); @@ -696,8 +694,8 @@ Pkt *accept_pkt_anchor(const tal_t *ctx, } Pkt *accept_pkt_open_commit_sig(const tal_t *ctx, - const struct peer *peer, - const Pkt *pkt, struct state_effect **effect) + struct peer *peer, + const Pkt *pkt) { if (fail(peer, FAIL_ACCEPT_OPEN_COMMIT_SIG)) return pkt_err(ctx, "Error inject"); @@ -706,8 +704,7 @@ Pkt *accept_pkt_open_commit_sig(const tal_t *ctx, Pkt *accept_pkt_htlc_update(const tal_t *ctx, struct peer *peer, const Pkt *pkt, - Pkt **decline, - struct state_effect **effect) + Pkt **decline) { if (fail(peer, FAIL_ACCEPT_HTLC_UPDATE)) return pkt_err(ctx, "Error inject"); @@ -724,8 +721,7 @@ Pkt *accept_pkt_htlc_update(const tal_t *ctx, } Pkt *accept_pkt_htlc_routefail(const tal_t *ctx, - struct peer *peer, const Pkt *pkt, - struct state_effect **effect) + struct peer *peer, const Pkt *pkt) { unsigned int id = htlc_id_from_pkt(pkt); const struct htlc *h = find_htlc(peer, id); @@ -742,8 +738,7 @@ Pkt *accept_pkt_htlc_routefail(const tal_t *ctx, } Pkt *accept_pkt_htlc_timedout(const tal_t *ctx, - struct peer *peer, const Pkt *pkt, - struct state_effect **effect) + struct peer *peer, const Pkt *pkt) { unsigned int id = htlc_id_from_pkt(pkt); const struct htlc *h = find_htlc(peer, id); @@ -818,9 +813,7 @@ Pkt *accept_pkt_update_signature(const tal_t *ctx, return NULL; } -Pkt *accept_pkt_close(const tal_t *ctx, - const struct peer *peer, const Pkt *pkt, - struct state_effect **effect) +Pkt *accept_pkt_close(const tal_t *ctx, struct peer *peer, const Pkt *pkt) { if (fail(peer, FAIL_ACCEPT_CLOSE)) return pkt_err(ctx, "Error inject"); @@ -828,8 +821,7 @@ Pkt *accept_pkt_close(const tal_t *ctx, } Pkt *accept_pkt_close_complete(const tal_t *ctx, - const struct peer *peer, const Pkt *pkt, - struct state_effect **effect) + struct peer *peer, const Pkt *pkt) { if (fail(peer, FAIL_ACCEPT_CLOSE_COMPLETE)) return pkt_err(ctx, "Error inject"); @@ -837,9 +829,8 @@ Pkt *accept_pkt_close_complete(const tal_t *ctx, } Pkt *accept_pkt_simultaneous_close(const tal_t *ctx, - const struct peer *peer, - const Pkt *pkt, - struct state_effect **effect) + struct peer *peer, + const Pkt *pkt) { if (fail(peer, FAIL_ACCEPT_SIMULTANEOUS_CLOSE)) return pkt_err(ctx, "Error inject"); @@ -847,8 +838,7 @@ Pkt *accept_pkt_simultaneous_close(const tal_t *ctx, } Pkt *accept_pkt_close_ack(const tal_t *ctx, - const struct peer *peer, const Pkt *pkt, - struct state_effect **effect) + struct peer *peer, const Pkt *pkt) { if (fail(peer, FAIL_ACCEPT_CLOSE_ACK)) return pkt_err(ctx, "Error inject"); @@ -1780,7 +1770,6 @@ static void try_input(const struct peer *peer, { struct peer copy, other; struct trail t; - struct state_effect *effect; const char *problem; Pkt *output; struct bitcoin_tx *broadcast; @@ -1795,7 +1784,7 @@ static void try_input(const struct peer *peer, copy.trail = &t; eliminate_input(&hist->inputs_per_state[copy.state], i); - cstatus = state(ctx, ©, i, idata, &output, &broadcast, &effect); + cstatus = state(ctx, ©, i, idata, &output, &broadcast); normalpath &= normal_path(i, peer->state, copy.state); errorpath |= error_path(i, peer->state, copy.state); @@ -2208,13 +2197,12 @@ static enum state_input **map_inputs(void) /* This adds to mapping_inputs every input_is() call */ if (!state_is_error(i)) { struct peer dummy; - struct state_effect *effect; struct bitcoin_tx *dummy_tx; Pkt *dummy_pkt; memset(&dummy, 0, sizeof(dummy)); dummy.state = i; state(ctx, &dummy, INPUT_NONE, NULL, &dummy_pkt, - &dummy_tx, &effect); + &dummy_tx); } inps[i] = mapping_inputs; }