Browse Source

state: remove non-HTLC updates.

They're still in the base protocol (good for testing), just not here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
ca68c5c47f
  1. 28
      state.c
  2. 9
      state.h
  3. 5
      state_types.h
  4. 22
      test/test_state_coverage.c

28
state.c

@ -307,12 +307,7 @@ enum state state(const enum state state, const struct state_data *sdata,
*/ */
case STATE_NORMAL_LOWPRIO: case STATE_NORMAL_LOWPRIO:
case STATE_NORMAL_HIGHPRIO: case STATE_NORMAL_HIGHPRIO:
if (input_is(input, CMD_SEND_UPDATE)) { if (input_is(input, CMD_SEND_HTLC_UPDATE)) {
/* We are to send an update. */
set_effect(effect, send,
pkt_update(effect, sdata, idata->cmd));
return prio(state, STATE_WAIT_FOR_UPDATE_ACCEPT);
} else if (input_is(input, CMD_SEND_HTLC_UPDATE)) {
/* We are to send an HTLC update. */ /* We are to send an HTLC update. */
set_effect(effect, send, set_effect(effect, send,
pkt_htlc_update(effect, sdata, idata->cmd)); pkt_htlc_update(effect, sdata, idata->cmd));
@ -335,8 +330,6 @@ enum state state(const enum state state, const struct state_data *sdata,
return prio(state, STATE_WAIT_FOR_HTLC_ACCEPT); return prio(state, STATE_WAIT_FOR_HTLC_ACCEPT);
} else if (input_is(input, CMD_CLOSE)) { } else if (input_is(input, CMD_CLOSE)) {
goto start_closing; goto start_closing;
} else if (input_is(input, PKT_UPDATE)) {
goto accept_update;
} else if (input_is(input, PKT_UPDATE_ADD_HTLC)) { } else if (input_is(input, PKT_UPDATE_ADD_HTLC)) {
goto accept_htlc_update; goto accept_htlc_update;
} else if (input_is(input, PKT_UPDATE_COMPLETE_HTLC)) { } else if (input_is(input, PKT_UPDATE_COMPLETE_HTLC)) {
@ -364,18 +357,6 @@ enum state state(const enum state state, const struct state_data *sdata,
fail_cmd(effect, CMD_SEND_HTLC_UPDATE, idata->pkt); fail_cmd(effect, CMD_SEND_HTLC_UPDATE, idata->pkt);
/* Toggle between high and low priority states. */ /* Toggle between high and low priority states. */
return toggle_prio(state, STATE_NORMAL); return toggle_prio(state, STATE_NORMAL);
}
/* Fall thru... */
case STATE_WAIT_FOR_UPDATE_ACCEPT_LOWPRIO:
case STATE_WAIT_FOR_UPDATE_ACCEPT_HIGHPRIO:
if (input_is(input, PKT_UPDATE)) {
/* If we're high priority, ignore their packet */
if (high_priority(state))
return state;
/* Otherwise, process their request first: defer ours */
requeue_cmd(effect, CMD_SEND_UPDATE_ANY);
goto accept_update;
} else if (input_is(input, PKT_UPDATE_ADD_HTLC)) { } else if (input_is(input, PKT_UPDATE_ADD_HTLC)) {
/* If we're high priority, ignore their packet */ /* If we're high priority, ignore their packet */
if (high_priority(state)) if (high_priority(state))
@ -736,13 +717,6 @@ them_unilateral:
BITCOIN_SPEND_THEIRS_DONE)); BITCOIN_SPEND_THEIRS_DONE));
return STATE_CLOSE_WAIT_SPENDTHEM; return STATE_CLOSE_WAIT_SPENDTHEM;
accept_update:
err = accept_pkt_update(effect, sdata, idata->pkt);
if (err)
goto err_start_unilateral_close;
set_effect(effect, send, pkt_update_accept(effect, sdata));
return prio(state, STATE_WAIT_FOR_UPDATE_SIG);
accept_htlc_update: accept_htlc_update:
err = accept_pkt_htlc_update(effect, sdata, idata->pkt, &decline); err = accept_pkt_htlc_update(effect, sdata, idata->pkt, &decline);
if (err) if (err)

9
state.h

@ -71,7 +71,7 @@ enum state state(const enum state state, const struct state_data *sdata,
const enum state_input input, const union input *idata, const enum state_input input, const union input *idata,
struct state_effect *effect); struct state_effect *effect);
/* Either CMD_SEND_UPDATE or CMD_SEND_HTLC_UPDATE */ /* Any CMD_SEND_HTLC_* */
#define CMD_SEND_UPDATE_ANY INPUT_MAX #define CMD_SEND_UPDATE_ANY INPUT_MAX
/* a == b? (or one of several for CMD_SEND_UPDATE_ANY) */ /* a == b? (or one of several for CMD_SEND_UPDATE_ANY) */
@ -79,8 +79,7 @@ static inline bool input_is(enum state_input a, enum state_input b)
{ {
if (b == CMD_SEND_UPDATE_ANY) { if (b == CMD_SEND_UPDATE_ANY) {
/* Single | here, we want to record all. */ /* Single | here, we want to record all. */
return input_is(a, CMD_SEND_UPDATE) return input_is(a, CMD_SEND_HTLC_UPDATE)
| input_is(a, CMD_SEND_HTLC_UPDATE)
| input_is(a, CMD_SEND_HTLC_COMPLETE) | input_is(a, CMD_SEND_HTLC_COMPLETE)
| input_is(a, CMD_SEND_HTLC_TIMEDOUT) | input_is(a, CMD_SEND_HTLC_TIMEDOUT)
| input_is(a, CMD_SEND_HTLC_ROUTEFAIL); | input_is(a, CMD_SEND_HTLC_ROUTEFAIL);
@ -98,7 +97,6 @@ Pkt *pkt_open(const tal_t *ctx, const struct state_data *sdata);
Pkt *pkt_anchor(const tal_t *ctx, const struct state_data *sdata); Pkt *pkt_anchor(const tal_t *ctx, const struct state_data *sdata);
Pkt *pkt_open_commit_sig(const tal_t *ctx, const struct state_data *sdata); Pkt *pkt_open_commit_sig(const tal_t *ctx, const struct state_data *sdata);
Pkt *pkt_open_complete(const tal_t *ctx, const struct state_data *sdata); Pkt *pkt_open_complete(const tal_t *ctx, const struct state_data *sdata);
Pkt *pkt_update(const tal_t *ctx, const struct state_data *sdata, void *data);
Pkt *pkt_htlc_update(const tal_t *ctx, const struct state_data *sdata, void *data); Pkt *pkt_htlc_update(const tal_t *ctx, const struct state_data *sdata, void *data);
Pkt *pkt_htlc_complete(const tal_t *ctx, const struct state_data *sdata, void *data); Pkt *pkt_htlc_complete(const tal_t *ctx, const struct state_data *sdata, void *data);
Pkt *pkt_htlc_timedout(const tal_t *ctx, const struct state_data *sdata, void *data); Pkt *pkt_htlc_timedout(const tal_t *ctx, const struct state_data *sdata, void *data);
@ -124,9 +122,6 @@ Pkt *accept_pkt_anchor(struct state_effect *effect,
Pkt *accept_pkt_open_commit_sig(struct state_effect *effect, Pkt *accept_pkt_open_commit_sig(struct state_effect *effect,
const struct state_data *sdata, const Pkt *pkt); const struct state_data *sdata, const Pkt *pkt);
Pkt *accept_pkt_update(struct state_effect *effect,
const struct state_data *sdata, const Pkt *pkt);
Pkt *accept_pkt_htlc_update(struct state_effect *effect, Pkt *accept_pkt_htlc_update(struct state_effect *effect,
const struct state_data *sdata, const Pkt *pkt, const struct state_data *sdata, const Pkt *pkt,
Pkt **decline); Pkt **decline);

5
state_types.h

@ -36,9 +36,6 @@ enum state {
STATE_WAIT_FOR_HTLC_ACCEPT_LOWPRIO, STATE_WAIT_FOR_HTLC_ACCEPT_LOWPRIO,
STATE_WAIT_FOR_HTLC_ACCEPT_HIGHPRIO, STATE_WAIT_FOR_HTLC_ACCEPT_HIGHPRIO,
STATE_WAIT_FOR_UPDATE_ACCEPT_LOWPRIO,
STATE_WAIT_FOR_UPDATE_ACCEPT_HIGHPRIO,
STATE_WAIT_FOR_UPDATE_COMPLETE_LOWPRIO, STATE_WAIT_FOR_UPDATE_COMPLETE_LOWPRIO,
STATE_WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO, STATE_WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO,
@ -142,7 +139,6 @@ enum state_input {
PKT_OPEN_ANCHOR = PKT__PKT_OPEN_ANCHOR, PKT_OPEN_ANCHOR = PKT__PKT_OPEN_ANCHOR,
PKT_OPEN_COMMIT_SIG = PKT__PKT_OPEN_COMMIT_SIG, PKT_OPEN_COMMIT_SIG = PKT__PKT_OPEN_COMMIT_SIG,
PKT_OPEN_COMPLETE = PKT__PKT_OPEN_COMPLETE, PKT_OPEN_COMPLETE = PKT__PKT_OPEN_COMPLETE,
PKT_UPDATE = PKT__PKT_UPDATE,
PKT_UPDATE_ADD_HTLC = PKT__PKT_UPDATE_ADD_HTLC, PKT_UPDATE_ADD_HTLC = PKT__PKT_UPDATE_ADD_HTLC,
PKT_UPDATE_ACCEPT = PKT__PKT_UPDATE_ACCEPT, PKT_UPDATE_ACCEPT = PKT__PKT_UPDATE_ACCEPT,
PKT_UPDATE_SIGNATURE = PKT__PKT_UPDATE_SIGNATURE, PKT_UPDATE_SIGNATURE = PKT__PKT_UPDATE_SIGNATURE,
@ -190,7 +186,6 @@ enum state_input {
INPUT_CLOSE_COMPLETE_TIMEOUT, INPUT_CLOSE_COMPLETE_TIMEOUT,
/* Commands */ /* Commands */
CMD_SEND_UPDATE,
CMD_SEND_HTLC_UPDATE, CMD_SEND_HTLC_UPDATE,
CMD_SEND_HTLC_COMPLETE, CMD_SEND_HTLC_COMPLETE,
CMD_SEND_HTLC_TIMEDOUT, CMD_SEND_HTLC_TIMEDOUT,

22
test/test_state_coverage.c

@ -227,11 +227,6 @@ Pkt *pkt_open_complete(const tal_t *ctx, const struct state_data *sdata)
return new_pkt(ctx, PKT_OPEN_COMPLETE); return new_pkt(ctx, PKT_OPEN_COMPLETE);
} }
Pkt *pkt_update(const tal_t *ctx, const struct state_data *sdata, void *data)
{
return new_pkt(ctx, PKT_UPDATE);
}
Pkt *pkt_htlc_update(const tal_t *ctx, const struct state_data *sdata, void *data) Pkt *pkt_htlc_update(const tal_t *ctx, const struct state_data *sdata, void *data)
{ {
return new_pkt(ctx, PKT_UPDATE_ADD_HTLC); return new_pkt(ctx, PKT_UPDATE_ADD_HTLC);
@ -307,11 +302,6 @@ Pkt *accept_pkt_open_commit_sig(struct state_effect *effect, const struct state_
return NULL; return NULL;
} }
Pkt *accept_pkt_update(struct state_effect *effect, const struct state_data *sdata, const Pkt *pkt)
{
return NULL;
}
Pkt *accept_pkt_htlc_update(struct state_effect *effect, Pkt *accept_pkt_htlc_update(struct state_effect *effect,
const struct state_data *sdata, const Pkt *pkt, const struct state_data *sdata, const Pkt *pkt,
Pkt **decline) Pkt **decline)
@ -642,8 +632,7 @@ static bool is_current_command(const struct state_data *sdata,
enum state_input cmd) enum state_input cmd)
{ {
if (cmd == CMD_SEND_UPDATE_ANY) { if (cmd == CMD_SEND_UPDATE_ANY) {
return is_current_command(sdata, CMD_SEND_UPDATE) return is_current_command(sdata, CMD_SEND_HTLC_UPDATE)
|| is_current_command(sdata, CMD_SEND_HTLC_UPDATE)
|| is_current_command(sdata, CMD_SEND_HTLC_COMPLETE) || is_current_command(sdata, CMD_SEND_HTLC_COMPLETE)
|| is_current_command(sdata, CMD_SEND_HTLC_TIMEDOUT) || is_current_command(sdata, CMD_SEND_HTLC_TIMEDOUT)
|| is_current_command(sdata, CMD_SEND_HTLC_ROUTEFAIL); || is_current_command(sdata, CMD_SEND_HTLC_ROUTEFAIL);
@ -838,7 +827,7 @@ static bool normal_path(enum state_input i, enum state src, enum state dst)
/* These clutter the graph, so only handle from normal state. */ /* These clutter the graph, so only handle from normal state. */
static bool too_cluttered(enum state_input i, enum state src) static bool too_cluttered(enum state_input i, enum state src)
{ {
if (i == CMD_CLOSE || i == PKT_CLOSE || i == PKT_UPDATE || i == PKT_UPDATE_ADD_HTLC || i == PKT_UPDATE_COMPLETE_HTLC) if (i == CMD_CLOSE || i == PKT_CLOSE || i == PKT_UPDATE_ADD_HTLC || i == PKT_UPDATE_COMPLETE_HTLC)
return src != STATE_NORMAL_LOWPRIO return src != STATE_NORMAL_LOWPRIO
&& src != STATE_NORMAL_HIGHPRIO; && src != STATE_NORMAL_HIGHPRIO;
return false; return false;
@ -885,10 +874,6 @@ static const char *simplify_state(enum state s)
case STATE_WAIT_FOR_HTLC_ACCEPT_HIGHPRIO: case STATE_WAIT_FOR_HTLC_ACCEPT_HIGHPRIO:
return "STATE_WAIT_FOR_HTLC_ACCEPT"; return "STATE_WAIT_FOR_HTLC_ACCEPT";
case STATE_WAIT_FOR_UPDATE_ACCEPT_LOWPRIO:
case STATE_WAIT_FOR_UPDATE_ACCEPT_HIGHPRIO:
return "STATE_WAIT_FOR_UPDATE_ACCEPT";
case STATE_WAIT_FOR_UPDATE_COMPLETE_LOWPRIO: case STATE_WAIT_FOR_UPDATE_COMPLETE_LOWPRIO:
case STATE_WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO: case STATE_WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO:
return "STATE_WAIT_FOR_UPDATE_COMPLETE"; return "STATE_WAIT_FOR_UPDATE_COMPLETE";
@ -1119,8 +1104,7 @@ static struct trail *run_peer(const struct state_data *sdata,
if (sdata->current_command == INPUT_NONE) { if (sdata->current_command == INPUT_NONE) {
size_t i; size_t i;
static const enum state_input cmds[] static const enum state_input cmds[]
= { CMD_SEND_UPDATE, = { CMD_SEND_HTLC_UPDATE,
CMD_SEND_HTLC_UPDATE,
CMD_SEND_HTLC_COMPLETE, CMD_SEND_HTLC_COMPLETE,
CMD_SEND_HTLC_TIMEDOUT, CMD_SEND_HTLC_TIMEDOUT,
CMD_SEND_HTLC_ROUTEFAIL, CMD_SEND_HTLC_ROUTEFAIL,

Loading…
Cancel
Save