Skip to content

Commit

Permalink
state: remove non-HTLC updates.
Browse files Browse the repository at this point in the history
They're still in the base protocol (good for testing), just not here.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Sep 25, 2015
1 parent 0f4ad94 commit ca68c5c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 58 deletions.
28 changes: 1 addition & 27 deletions state.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,7 @@ enum state state(const enum state state, const struct state_data *sdata,
*/
case STATE_NORMAL_LOWPRIO:
case STATE_NORMAL_HIGHPRIO:
if (input_is(input, CMD_SEND_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)) {
if (input_is(input, CMD_SEND_HTLC_UPDATE)) {
/* We are to send an HTLC update. */
set_effect(effect, send,
pkt_htlc_update(effect, sdata, idata->cmd));
Expand All @@ -335,8 +330,6 @@ enum state state(const enum state state, const struct state_data *sdata,
return prio(state, STATE_WAIT_FOR_HTLC_ACCEPT);
} else if (input_is(input, CMD_CLOSE)) {
goto start_closing;
} else if (input_is(input, PKT_UPDATE)) {
goto accept_update;
} else if (input_is(input, PKT_UPDATE_ADD_HTLC)) {
goto accept_htlc_update;
} else if (input_is(input, PKT_UPDATE_COMPLETE_HTLC)) {
Expand Down Expand Up @@ -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);
/* Toggle between high and low priority states. */
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)) {
/* If we're high priority, ignore their packet */
if (high_priority(state))
Expand Down Expand Up @@ -736,13 +717,6 @@ enum state state(const enum state state, const struct state_data *sdata,
BITCOIN_SPEND_THEIRS_DONE));
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:
err = accept_pkt_htlc_update(effect, sdata, idata->pkt, &decline);
if (err)
Expand Down
9 changes: 2 additions & 7 deletions state.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ enum state state(const enum state state, const struct state_data *sdata,
const enum state_input input, const union input *idata,
struct state_effect *effect);

/* Either CMD_SEND_UPDATE or CMD_SEND_HTLC_UPDATE */
/* Any CMD_SEND_HTLC_* */
#define CMD_SEND_UPDATE_ANY INPUT_MAX

/* a == b? (or one of several for CMD_SEND_UPDATE_ANY) */
static inline bool input_is(enum state_input a, enum state_input b)
{
if (b == CMD_SEND_UPDATE_ANY) {
/* Single | here, we want to record all. */
return input_is(a, CMD_SEND_UPDATE)
| input_is(a, CMD_SEND_HTLC_UPDATE)
return input_is(a, CMD_SEND_HTLC_UPDATE)
| input_is(a, CMD_SEND_HTLC_COMPLETE)
| input_is(a, CMD_SEND_HTLC_TIMEDOUT)
| input_is(a, CMD_SEND_HTLC_ROUTEFAIL);
Expand All @@ -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_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_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_timedout(const tal_t *ctx, const struct state_data *sdata, void *data);
Expand All @@ -124,9 +122,6 @@ Pkt *accept_pkt_anchor(struct state_effect *effect,
Pkt *accept_pkt_open_commit_sig(struct state_effect *effect,
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,
const struct state_data *sdata, const Pkt *pkt,
Pkt **decline);
Expand Down
5 changes: 0 additions & 5 deletions state_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ enum state {
STATE_WAIT_FOR_HTLC_ACCEPT_LOWPRIO,
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_HIGHPRIO,

Expand Down Expand Up @@ -142,7 +139,6 @@ enum state_input {
PKT_OPEN_ANCHOR = PKT__PKT_OPEN_ANCHOR,
PKT_OPEN_COMMIT_SIG = PKT__PKT_OPEN_COMMIT_SIG,
PKT_OPEN_COMPLETE = PKT__PKT_OPEN_COMPLETE,
PKT_UPDATE = PKT__PKT_UPDATE,
PKT_UPDATE_ADD_HTLC = PKT__PKT_UPDATE_ADD_HTLC,
PKT_UPDATE_ACCEPT = PKT__PKT_UPDATE_ACCEPT,
PKT_UPDATE_SIGNATURE = PKT__PKT_UPDATE_SIGNATURE,
Expand Down Expand Up @@ -190,7 +186,6 @@ enum state_input {
INPUT_CLOSE_COMPLETE_TIMEOUT,

/* Commands */
CMD_SEND_UPDATE,
CMD_SEND_HTLC_UPDATE,
CMD_SEND_HTLC_COMPLETE,
CMD_SEND_HTLC_TIMEDOUT,
Expand Down
22 changes: 3 additions & 19 deletions test/test_state_coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,6 @@ Pkt *pkt_open_complete(const tal_t *ctx, const struct state_data *sdata)
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)
{
return new_pkt(ctx, PKT_UPDATE_ADD_HTLC);
Expand Down Expand Up @@ -307,11 +302,6 @@ Pkt *accept_pkt_open_commit_sig(struct state_effect *effect, const struct state_
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,
const struct state_data *sdata, const Pkt *pkt,
Pkt **decline)
Expand Down Expand Up @@ -642,8 +632,7 @@ static bool is_current_command(const struct state_data *sdata,
enum state_input cmd)
{
if (cmd == CMD_SEND_UPDATE_ANY) {
return is_current_command(sdata, CMD_SEND_UPDATE)
|| is_current_command(sdata, CMD_SEND_HTLC_UPDATE)
return is_current_command(sdata, CMD_SEND_HTLC_UPDATE)
|| is_current_command(sdata, CMD_SEND_HTLC_COMPLETE)
|| is_current_command(sdata, CMD_SEND_HTLC_TIMEDOUT)
|| is_current_command(sdata, CMD_SEND_HTLC_ROUTEFAIL);
Expand Down Expand Up @@ -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. */
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
&& src != STATE_NORMAL_HIGHPRIO;
return false;
Expand Down Expand Up @@ -885,10 +874,6 @@ static const char *simplify_state(enum state s)
case STATE_WAIT_FOR_HTLC_ACCEPT_HIGHPRIO:
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_HIGHPRIO:
return "STATE_WAIT_FOR_UPDATE_COMPLETE";
Expand Down Expand Up @@ -1119,8 +1104,7 @@ static struct trail *run_peer(const struct state_data *sdata,
if (sdata->current_command == INPUT_NONE) {
size_t i;
static const enum state_input cmds[]
= { CMD_SEND_UPDATE,
CMD_SEND_HTLC_UPDATE,
= { CMD_SEND_HTLC_UPDATE,
CMD_SEND_HTLC_COMPLETE,
CMD_SEND_HTLC_TIMEDOUT,
CMD_SEND_HTLC_ROUTEFAIL,
Expand Down

0 comments on commit ca68c5c

Please sign in to comment.