Browse Source

daemon: rename CMD_SEND_HTLC_UPDATE to CMD_SEND_HTLC_ADD

There are other updates than just adding an HTLC; make this explicit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
983000428f
  1. 4
      daemon/packets.c
  2. 2
      daemon/peer.c
  3. 13
      state.c
  4. 6
      state.h
  5. 2
      state_types.h
  6. 12
      test/test_state_coverage.c

4
daemon/packets.c

@ -134,7 +134,7 @@ Pkt *pkt_open_complete(const tal_t *ctx, const struct peer *peer)
return make_pkt(ctx, PKT__PKT_OPEN_COMPLETE, o); return make_pkt(ctx, PKT__PKT_OPEN_COMPLETE, o);
} }
Pkt *pkt_htlc_update(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_add(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog) const struct htlc_progress *htlc_prog)
{ {
UpdateAddHtlc *u = tal(ctx, UpdateAddHtlc); UpdateAddHtlc *u = tal(ctx, UpdateAddHtlc);
@ -423,7 +423,7 @@ static Pkt *decline_htlc(const tal_t *ctx, const char *why)
return make_pkt(ctx, PKT__PKT_UPDATE_DECLINE_HTLC, d); return make_pkt(ctx, PKT__PKT_UPDATE_DECLINE_HTLC, d);
} }
Pkt *accept_pkt_htlc_update(const tal_t *ctx, Pkt *accept_pkt_htlc_add(const tal_t *ctx,
struct peer *peer, const Pkt *pkt, struct peer *peer, const Pkt *pkt,
Pkt **decline) Pkt **decline)
{ {

2
daemon/peer.c

@ -1388,7 +1388,7 @@ static void do_newhtlc(struct peer *peer, struct newhtlc *newhtlc)
set_htlc_command(peer, cstate, newhtlc->jsoncmd, set_htlc_command(peer, cstate, newhtlc->jsoncmd,
&cstate->a.htlcs[tal_count(cstate->a.htlcs)-1], &cstate->a.htlcs[tal_count(cstate->a.htlcs)-1],
CMD_SEND_HTLC_UPDATE, NULL); CMD_SEND_HTLC_ADD, NULL);
} }
static void json_newhtlc(struct command *cmd, static void json_newhtlc(struct command *cmd,

13
state.c

@ -403,11 +403,10 @@ enum command_status state(const tal_t *ctx,
case STATE_NORMAL_LOWPRIO: case STATE_NORMAL_LOWPRIO:
case STATE_NORMAL_HIGHPRIO: case STATE_NORMAL_HIGHPRIO:
assert(peer->cond == PEER_CMD_OK); assert(peer->cond == PEER_CMD_OK);
if (input_is(input, CMD_SEND_HTLC_UPDATE)) { if (input_is(input, CMD_SEND_HTLC_ADD)) {
/* We are to send an HTLC update. */ /* We are to send an HTLC update. */
queue_pkt(out, queue_pkt(out,
pkt_htlc_update(ctx, peer, pkt_htlc_add(ctx, peer, idata->htlc_prog));
idata->htlc_prog));
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
return next_state(peer, cstatus, return next_state(peer, cstatus,
prio(peer->state, STATE_WAIT_FOR_HTLC_ACCEPT)); prio(peer->state, STATE_WAIT_FOR_HTLC_ACCEPT));
@ -439,7 +438,7 @@ enum command_status state(const tal_t *ctx,
goto start_closing; goto start_closing;
} else if (input_is(input, PKT_UPDATE_ADD_HTLC)) { } else if (input_is(input, PKT_UPDATE_ADD_HTLC)) {
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
goto accept_htlc_update; goto accept_htlc_add;
} else if (input_is(input, PKT_UPDATE_FULFILL_HTLC)) { } else if (input_is(input, PKT_UPDATE_FULFILL_HTLC)) {
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
goto accept_htlc_fulfill; goto accept_htlc_fulfill;
@ -484,7 +483,7 @@ enum command_status state(const tal_t *ctx,
complete_cmd(peer, &cstatus, CMD_REQUEUE); complete_cmd(peer, &cstatus, CMD_REQUEUE);
/* Stay busy, since we're processing theirs. */ /* Stay busy, since we're processing theirs. */
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
goto accept_htlc_update; goto accept_htlc_add;
} else if (input_is(input, PKT_UPDATE_FULFILL_HTLC)) { } else if (input_is(input, PKT_UPDATE_FULFILL_HTLC)) {
/* If we're high priority, ignore their packet */ /* If we're high priority, ignore their packet */
if (high_priority(peer->state)) if (high_priority(peer->state))
@ -1035,8 +1034,8 @@ them_unilateral:
return next_state(peer, cstatus, STATE_CLOSE_WAIT_SPENDTHEM); return next_state(peer, cstatus, STATE_CLOSE_WAIT_SPENDTHEM);
accept_htlc_update: accept_htlc_add:
err = accept_pkt_htlc_update(ctx, peer, idata->pkt, &decline); err = accept_pkt_htlc_add(ctx, peer, idata->pkt, &decline);
if (err) if (err)
goto err_start_unilateral_close; goto err_start_unilateral_close;
if (decline) { if (decline) {

6
state.h

@ -50,7 +50,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_HTLC_UPDATE) return input_is(a, CMD_SEND_HTLC_ADD)
| input_is(a, CMD_SEND_HTLC_FULFILL) | input_is(a, CMD_SEND_HTLC_FULFILL)
| input_is(a, CMD_SEND_HTLC_TIMEDOUT) | input_is(a, CMD_SEND_HTLC_TIMEDOUT)
| input_is(a, CMD_SEND_HTLC_FAIL); | input_is(a, CMD_SEND_HTLC_FAIL);
@ -103,7 +103,7 @@ Pkt *pkt_open(const tal_t *ctx, const struct peer *peer,
Pkt *pkt_anchor(const tal_t *ctx, const struct peer *peer); Pkt *pkt_anchor(const tal_t *ctx, const struct peer *peer);
Pkt *pkt_open_commit_sig(const tal_t *ctx, const struct peer *peer); Pkt *pkt_open_commit_sig(const tal_t *ctx, const struct peer *peer);
Pkt *pkt_open_complete(const tal_t *ctx, const struct peer *peer); Pkt *pkt_open_complete(const tal_t *ctx, const struct peer *peer);
Pkt *pkt_htlc_update(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_add(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog); const struct htlc_progress *htlc_prog);
Pkt *pkt_htlc_fulfill(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_fulfill(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog); const struct htlc_progress *htlc_prog);
@ -135,7 +135,7 @@ Pkt *accept_pkt_open_commit_sig(const tal_t *ctx,
Pkt *accept_pkt_open_complete(const tal_t *ctx, Pkt *accept_pkt_open_complete(const tal_t *ctx,
struct peer *peer, const Pkt *pkt); struct peer *peer, const Pkt *pkt);
Pkt *accept_pkt_htlc_update(const tal_t *ctx, Pkt *accept_pkt_htlc_add(const tal_t *ctx,
struct peer *peer, const Pkt *pkt, struct peer *peer, const Pkt *pkt,
Pkt **decline); Pkt **decline);

2
state_types.h

@ -274,7 +274,7 @@ enum state_input {
/* Commands */ /* Commands */
CMD_OPEN_WITH_ANCHOR, CMD_OPEN_WITH_ANCHOR,
CMD_OPEN_WITHOUT_ANCHOR, CMD_OPEN_WITHOUT_ANCHOR,
CMD_SEND_HTLC_UPDATE, CMD_SEND_HTLC_ADD,
CMD_SEND_HTLC_FULFILL, CMD_SEND_HTLC_FULFILL,
CMD_SEND_HTLC_TIMEDOUT, CMD_SEND_HTLC_TIMEDOUT,
CMD_SEND_HTLC_FAIL, CMD_SEND_HTLC_FAIL,

12
test/test_state_coverage.c

@ -36,7 +36,7 @@ enum failure {
FAIL_ACCEPT_ANCHOR, FAIL_ACCEPT_ANCHOR,
FAIL_ACCEPT_OPEN_COMMIT_SIG, FAIL_ACCEPT_OPEN_COMMIT_SIG,
FAIL_ACCEPT_OPEN_COMPLETE, FAIL_ACCEPT_OPEN_COMPLETE,
FAIL_ACCEPT_HTLC_UPDATE, FAIL_ACCEPT_HTLC_ADD,
FAIL_ACCEPT_HTLC_FAIL, FAIL_ACCEPT_HTLC_FAIL,
FAIL_ACCEPT_HTLC_TIMEDOUT, FAIL_ACCEPT_HTLC_TIMEDOUT,
FAIL_ACCEPT_HTLC_FULFILL, FAIL_ACCEPT_HTLC_FULFILL,
@ -416,7 +416,7 @@ static const union input dup_idata(const tal_t *ctx,
if (input_is_pkt(input)) if (input_is_pkt(input))
i.pkt = (Pkt *)tal_strdup(ctx, (const char *)idata->pkt); i.pkt = (Pkt *)tal_strdup(ctx, (const char *)idata->pkt);
else if (input == CMD_SEND_HTLC_UPDATE else if (input == CMD_SEND_HTLC_ADD
|| input == CMD_SEND_HTLC_FULFILL || input == CMD_SEND_HTLC_FULFILL
|| input == CMD_SEND_HTLC_FAIL || input == CMD_SEND_HTLC_FAIL
|| input == CMD_SEND_HTLC_TIMEDOUT) { || input == CMD_SEND_HTLC_TIMEDOUT) {
@ -618,7 +618,7 @@ Pkt *pkt_open_complete(const tal_t *ctx, const struct peer *peer)
return new_pkt(ctx, PKT_OPEN_COMPLETE); return new_pkt(ctx, PKT_OPEN_COMPLETE);
} }
Pkt *pkt_htlc_update(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_add(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog) const struct htlc_progress *htlc_prog)
{ {
return htlc_pkt(ctx, "PKT_UPDATE_ADD_HTLC", htlc_prog->htlc.id); return htlc_pkt(ctx, "PKT_UPDATE_ADD_HTLC", htlc_prog->htlc.id);
@ -726,11 +726,11 @@ Pkt *accept_pkt_open_complete(const tal_t *ctx,
return NULL; return NULL;
} }
Pkt *accept_pkt_htlc_update(const tal_t *ctx, Pkt *accept_pkt_htlc_add(const tal_t *ctx,
struct peer *peer, const Pkt *pkt, struct peer *peer, const Pkt *pkt,
Pkt **decline) Pkt **decline)
{ {
if (fail(peer, FAIL_ACCEPT_HTLC_UPDATE)) if (fail(peer, FAIL_ACCEPT_HTLC_ADD))
return pkt_err(ctx, "Error inject"); return pkt_err(ctx, "Error inject");
/* This is the current htlc: If they propose it, it's to us. */ /* This is the current htlc: If they propose it, it's to us. */
@ -2110,7 +2110,7 @@ static void run_peer(const struct peer *peer,
/* Add a new HTLC if not at max. */ /* Add a new HTLC if not at max. */
if (copy.num_htlcs_to_them < MAX_HTLCS) { if (copy.num_htlcs_to_them < MAX_HTLCS) {
copy.core.current_command = CMD_SEND_HTLC_UPDATE; copy.core.current_command = CMD_SEND_HTLC_ADD;
idata->htlc_prog = tal(idata, struct htlc_progress); idata->htlc_prog = tal(idata, struct htlc_progress);
idata->htlc_prog->adding = true; idata->htlc_prog->adding = true;
idata->htlc_prog->htlc.to_them = true; idata->htlc_prog->htlc.to_them = true;

Loading…
Cancel
Save