mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
state: remove unused fields from union input
And make the add/fail/fulfill arg a pointer to a union htlc_staging directly, removing struct htlc_progress. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -167,18 +167,17 @@ void queue_pkt_open_complete(struct peer *peer)
|
|||||||
queue_pkt(peer, PKT__PKT_OPEN_COMPLETE, o);
|
queue_pkt(peer, PKT__PKT_OPEN_COMPLETE, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
void queue_pkt_htlc_add(struct peer *peer,
|
void queue_pkt_htlc_add(struct peer *peer, const struct channel_htlc *htlc)
|
||||||
const struct htlc_progress *htlc_prog)
|
|
||||||
{
|
{
|
||||||
UpdateAddHtlc *u = tal(peer, UpdateAddHtlc);
|
UpdateAddHtlc *u = tal(peer, UpdateAddHtlc);
|
||||||
|
union htlc_staging stage;
|
||||||
|
|
||||||
update_add_htlc__init(u);
|
update_add_htlc__init(u);
|
||||||
assert(htlc_prog->stage.type == HTLC_ADD);
|
|
||||||
|
|
||||||
u->id = htlc_prog->stage.add.htlc.id;
|
u->id = htlc->id;
|
||||||
u->amount_msat = htlc_prog->stage.add.htlc.msatoshis;
|
u->amount_msat = htlc->msatoshis;
|
||||||
u->r_hash = sha256_to_proto(u, &htlc_prog->stage.add.htlc.rhash);
|
u->r_hash = sha256_to_proto(u, &htlc->rhash);
|
||||||
u->expiry = abs_locktime_to_proto(u, &htlc_prog->stage.add.htlc.expiry);
|
u->expiry = abs_locktime_to_proto(u, &htlc->expiry);
|
||||||
/* FIXME: routing! */
|
/* FIXME: routing! */
|
||||||
u->route = tal(u, Routing);
|
u->route = tal(u, Routing);
|
||||||
routing__init(u->route);
|
routing__init(u->route);
|
||||||
@@ -189,16 +188,19 @@ void queue_pkt_htlc_add(struct peer *peer,
|
|||||||
* changeset for its remote commitment
|
* changeset for its remote commitment
|
||||||
*/
|
*/
|
||||||
if (!funding_add_htlc(peer->remote.staging_cstate,
|
if (!funding_add_htlc(peer->remote.staging_cstate,
|
||||||
htlc_prog->stage.add.htlc.msatoshis,
|
htlc->msatoshis,
|
||||||
&htlc_prog->stage.add.htlc.expiry,
|
&htlc->expiry,
|
||||||
&htlc_prog->stage.add.htlc.rhash,
|
&htlc->rhash,
|
||||||
htlc_prog->stage.add.htlc.id, OURS))
|
htlc->id, OURS))
|
||||||
fatal("Could not add HTLC?");
|
fatal("Could not add HTLC?");
|
||||||
add_unacked(&peer->remote, &htlc_prog->stage);
|
|
||||||
|
stage.add.add = HTLC_ADD;
|
||||||
|
stage.add.htlc = *htlc;
|
||||||
|
add_unacked(&peer->remote, &stage);
|
||||||
|
|
||||||
remote_changes_pending(peer);
|
remote_changes_pending(peer);
|
||||||
|
|
||||||
peer_add_htlc_expiry(peer, &htlc_prog->stage.add.htlc.expiry);
|
peer_add_htlc_expiry(peer, &htlc->expiry);
|
||||||
|
|
||||||
queue_pkt(peer, PKT__PKT_UPDATE_ADD_HTLC, u);
|
queue_pkt(peer, PKT__PKT_UPDATE_ADD_HTLC, u);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,12 +497,11 @@ static bool command_htlc_fail(struct peer *peer, u64 id)
|
|||||||
queue_pkt_htlc_fail(peer, id);
|
queue_pkt_htlc_fail(peer, id);
|
||||||
} else {
|
} else {
|
||||||
union input idata;
|
union input idata;
|
||||||
struct htlc_progress prog;
|
union htlc_staging stage;
|
||||||
|
|
||||||
prog.stage.fail.fail = HTLC_FAIL;
|
stage.fail.fail = HTLC_FAIL;
|
||||||
prog.stage.fail.id = id;
|
stage.fail.id = id;
|
||||||
/* FIXME: get rid of htlc_progress, just use htlc_staging. */
|
idata.stage = &stage;
|
||||||
idata.htlc_prog = &prog;
|
|
||||||
state_event(peer, CMD_SEND_HTLC_FAIL, &idata);
|
state_event(peer, CMD_SEND_HTLC_FAIL, &idata);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -522,13 +521,12 @@ static bool command_htlc_fulfill(struct peer *peer,
|
|||||||
queue_pkt_htlc_fulfill(peer, id, r);
|
queue_pkt_htlc_fulfill(peer, id, r);
|
||||||
} else {
|
} else {
|
||||||
union input idata;
|
union input idata;
|
||||||
struct htlc_progress prog;
|
union htlc_staging stage;
|
||||||
|
|
||||||
prog.stage.fulfill.fulfill = HTLC_FULFILL;
|
stage.fulfill.fulfill = HTLC_FULFILL;
|
||||||
prog.stage.fulfill.r = *r;
|
stage.fulfill.r = *r;
|
||||||
prog.stage.fulfill.id = id;
|
stage.fulfill.id = id;
|
||||||
/* FIXME: get rid of htlc_progress, just use htlc_staging. */
|
idata.stage = &stage;
|
||||||
idata.htlc_prog = &prog;
|
|
||||||
state_event(peer, CMD_SEND_HTLC_FULFILL, &idata);
|
state_event(peer, CMD_SEND_HTLC_FULFILL, &idata);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -2324,12 +2322,12 @@ static void do_newhtlc(struct peer *peer,
|
|||||||
{
|
{
|
||||||
struct channel_state *cstate;
|
struct channel_state *cstate;
|
||||||
union input idata;
|
union input idata;
|
||||||
struct htlc_progress prog;
|
union htlc_staging stage;
|
||||||
|
|
||||||
/* Now we can assign counter and guarantee uniqueness. */
|
/* Now we can assign counter and guarantee uniqueness. */
|
||||||
prog.stage.add.add = HTLC_ADD;
|
stage.add.add = HTLC_ADD;
|
||||||
prog.stage.add.htlc = *htlc;
|
stage.add.htlc = *htlc;
|
||||||
prog.stage.add.htlc.id = peer->htlc_id_counter;
|
stage.add.htlc.id = peer->htlc_id_counter;
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
*
|
*
|
||||||
@@ -2379,7 +2377,7 @@ static void do_newhtlc(struct peer *peer,
|
|||||||
peer->htlc_id_counter++;
|
peer->htlc_id_counter++;
|
||||||
|
|
||||||
/* FIXME: Never propose duplicate rvalues? */
|
/* FIXME: Never propose duplicate rvalues? */
|
||||||
idata.htlc_prog = &prog;
|
idata.stage = &stage;
|
||||||
state_event(peer, CMD_SEND_HTLC_ADD, &idata);
|
state_event(peer, CMD_SEND_HTLC_ADD, &idata);
|
||||||
command_success(jsoncmd, null_response(jsoncmd));
|
command_success(jsoncmd, null_response(jsoncmd));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,11 +94,6 @@ struct peer_visible_state {
|
|||||||
struct channel_state *staging_cstate;
|
struct channel_state *staging_cstate;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct htlc_progress {
|
|
||||||
/* The HTLC we're working on. */
|
|
||||||
union htlc_staging stage;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct out_pkt {
|
struct out_pkt {
|
||||||
Pkt *pkt;
|
Pkt *pkt;
|
||||||
void (*ack_cb)(struct peer *peer, void *arg);
|
void (*ack_cb)(struct peer *peer, void *arg);
|
||||||
|
|||||||
13
state.c
13
state.c
@@ -251,19 +251,20 @@ enum state state(struct peer *peer,
|
|||||||
case STATE_NORMAL_COMMITTING:
|
case STATE_NORMAL_COMMITTING:
|
||||||
if (input_is(input, CMD_SEND_HTLC_ADD)) {
|
if (input_is(input, CMD_SEND_HTLC_ADD)) {
|
||||||
/* We are to send an HTLC add. */
|
/* We are to send an HTLC add. */
|
||||||
queue_pkt_htlc_add(peer, idata->htlc_prog);
|
assert(idata->stage->type == HTLC_ADD);
|
||||||
|
queue_pkt_htlc_add(peer, &idata->stage->add.htlc);
|
||||||
return unchanged_state(peer, input);
|
return unchanged_state(peer, input);
|
||||||
} else if (input_is(input, CMD_SEND_HTLC_FULFILL)) {
|
} else if (input_is(input, CMD_SEND_HTLC_FULFILL)) {
|
||||||
assert(idata->htlc_prog->stage.type == HTLC_FULFILL);
|
assert(idata->stage->type == HTLC_FULFILL);
|
||||||
/* We are to send an HTLC fulfill. */
|
/* We are to send an HTLC fulfill. */
|
||||||
queue_pkt_htlc_fulfill(peer,
|
queue_pkt_htlc_fulfill(peer,
|
||||||
idata->htlc_prog->stage.fulfill.id,
|
idata->stage->fulfill.id,
|
||||||
&idata->htlc_prog->stage.fulfill.r);
|
&idata->stage->fulfill.r);
|
||||||
return unchanged_state(peer, input);
|
return unchanged_state(peer, input);
|
||||||
} else if (input_is(input, CMD_SEND_HTLC_FAIL)) {
|
} else if (input_is(input, CMD_SEND_HTLC_FAIL)) {
|
||||||
assert(idata->htlc_prog->stage.type == HTLC_FAIL);
|
assert(idata->stage->type == HTLC_FAIL);
|
||||||
/* We are to send an HTLC fail. */
|
/* We are to send an HTLC fail. */
|
||||||
queue_pkt_htlc_fail(peer, idata->htlc_prog->stage.fail.id);
|
queue_pkt_htlc_fail(peer, idata->stage->fail.id);
|
||||||
return unchanged_state(peer, input);
|
return unchanged_state(peer, input);
|
||||||
}
|
}
|
||||||
/* Only expect revocation in STATE_NORMAL_COMMITTING */
|
/* Only expect revocation in STATE_NORMAL_COMMITTING */
|
||||||
|
|||||||
21
state.h
21
state.h
@@ -80,19 +80,10 @@ static inline bool input_is_pkt(enum state_input input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
union input {
|
union input {
|
||||||
|
/* For PKT_* */
|
||||||
Pkt *pkt;
|
Pkt *pkt;
|
||||||
struct command *cmd;
|
/* For CMD_SEND_HTLC_ADD, CMD_SEND_HTLC_FULFILL, CMD_SEND_HTLC_FAIL */
|
||||||
struct bitcoin_tx *tx;
|
union htlc_staging *stage;
|
||||||
struct htlc_progress *htlc_prog;
|
|
||||||
struct commit_info *ci;
|
|
||||||
struct htlc_onchain {
|
|
||||||
/* Which commitment we using. */
|
|
||||||
struct commit_info *ci;
|
|
||||||
/* Which HTLC. */
|
|
||||||
size_t i;
|
|
||||||
/* The rvalue (or NULL). */
|
|
||||||
u8 *r;
|
|
||||||
} *htlc_onchain;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum state state(struct peer *peer,
|
enum state state(struct peer *peer,
|
||||||
@@ -125,17 +116,13 @@ struct signature;
|
|||||||
/* Inform peer have an unexpected packet. */
|
/* Inform peer have an unexpected packet. */
|
||||||
void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt);
|
void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt);
|
||||||
|
|
||||||
/* An on-chain transaction revealed an R value. */
|
|
||||||
void peer_tx_revealed_r_value(struct peer *peer,
|
|
||||||
const struct htlc_onchain *htlc_onchain);
|
|
||||||
|
|
||||||
/* Send various kinds of packets */
|
/* Send various kinds of packets */
|
||||||
void queue_pkt_open(struct peer *peer, OpenChannel__AnchorOffer anchor);
|
void queue_pkt_open(struct peer *peer, OpenChannel__AnchorOffer anchor);
|
||||||
void queue_pkt_anchor(struct peer *peer);
|
void queue_pkt_anchor(struct peer *peer);
|
||||||
void queue_pkt_open_commit_sig(struct peer *peer);
|
void queue_pkt_open_commit_sig(struct peer *peer);
|
||||||
void queue_pkt_open_complete(struct peer *peer);
|
void queue_pkt_open_complete(struct peer *peer);
|
||||||
void queue_pkt_htlc_add(struct peer *peer,
|
void queue_pkt_htlc_add(struct peer *peer,
|
||||||
const struct htlc_progress *htlc_prog);
|
const struct channel_htlc *htlc);
|
||||||
void queue_pkt_htlc_fulfill(struct peer *peer, u64 id, const struct sha256 *r);
|
void queue_pkt_htlc_fulfill(struct peer *peer, u64 id, const struct sha256 *r);
|
||||||
void queue_pkt_htlc_fail(struct peer *peer, u64 id);
|
void queue_pkt_htlc_fail(struct peer *peer, u64 id);
|
||||||
void queue_pkt_commit(struct peer *peer);
|
void queue_pkt_commit(struct peer *peer);
|
||||||
|
|||||||
Reference in New Issue
Block a user