diff --git a/daemon/packets.c b/daemon/packets.c index d7dc13a13..06675d60d 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -167,18 +167,17 @@ void queue_pkt_open_complete(struct peer *peer) queue_pkt(peer, PKT__PKT_OPEN_COMPLETE, o); } -void queue_pkt_htlc_add(struct peer *peer, - const struct htlc_progress *htlc_prog) +void queue_pkt_htlc_add(struct peer *peer, const struct channel_htlc *htlc) { UpdateAddHtlc *u = tal(peer, UpdateAddHtlc); + union htlc_staging stage; update_add_htlc__init(u); - assert(htlc_prog->stage.type == HTLC_ADD); - u->id = htlc_prog->stage.add.htlc.id; - u->amount_msat = htlc_prog->stage.add.htlc.msatoshis; - u->r_hash = sha256_to_proto(u, &htlc_prog->stage.add.htlc.rhash); - u->expiry = abs_locktime_to_proto(u, &htlc_prog->stage.add.htlc.expiry); + u->id = htlc->id; + u->amount_msat = htlc->msatoshis; + u->r_hash = sha256_to_proto(u, &htlc->rhash); + u->expiry = abs_locktime_to_proto(u, &htlc->expiry); /* FIXME: routing! */ u->route = tal(u, Routing); routing__init(u->route); @@ -189,16 +188,19 @@ void queue_pkt_htlc_add(struct peer *peer, * changeset for its remote commitment */ if (!funding_add_htlc(peer->remote.staging_cstate, - htlc_prog->stage.add.htlc.msatoshis, - &htlc_prog->stage.add.htlc.expiry, - &htlc_prog->stage.add.htlc.rhash, - htlc_prog->stage.add.htlc.id, OURS)) + htlc->msatoshis, + &htlc->expiry, + &htlc->rhash, + htlc->id, OURS)) 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); - 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); } diff --git a/daemon/peer.c b/daemon/peer.c index 9eb917c04..dfa00443f 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -497,12 +497,11 @@ static bool command_htlc_fail(struct peer *peer, u64 id) queue_pkt_htlc_fail(peer, id); } else { union input idata; - struct htlc_progress prog; + union htlc_staging stage; - prog.stage.fail.fail = HTLC_FAIL; - prog.stage.fail.id = id; - /* FIXME: get rid of htlc_progress, just use htlc_staging. */ - idata.htlc_prog = &prog; + stage.fail.fail = HTLC_FAIL; + stage.fail.id = id; + idata.stage = &stage; state_event(peer, CMD_SEND_HTLC_FAIL, &idata); } return true; @@ -522,13 +521,12 @@ static bool command_htlc_fulfill(struct peer *peer, queue_pkt_htlc_fulfill(peer, id, r); } else { union input idata; - struct htlc_progress prog; + union htlc_staging stage; - prog.stage.fulfill.fulfill = HTLC_FULFILL; - prog.stage.fulfill.r = *r; - prog.stage.fulfill.id = id; - /* FIXME: get rid of htlc_progress, just use htlc_staging. */ - idata.htlc_prog = &prog; + stage.fulfill.fulfill = HTLC_FULFILL; + stage.fulfill.r = *r; + stage.fulfill.id = id; + idata.stage = &stage; state_event(peer, CMD_SEND_HTLC_FULFILL, &idata); } return true; @@ -2324,12 +2322,12 @@ static void do_newhtlc(struct peer *peer, { struct channel_state *cstate; union input idata; - struct htlc_progress prog; + union htlc_staging stage; /* Now we can assign counter and guarantee uniqueness. */ - prog.stage.add.add = HTLC_ADD; - prog.stage.add.htlc = *htlc; - prog.stage.add.htlc.id = peer->htlc_id_counter; + stage.add.add = HTLC_ADD; + stage.add.htlc = *htlc; + stage.add.htlc.id = peer->htlc_id_counter; /* BOLT #2: * @@ -2379,7 +2377,7 @@ static void do_newhtlc(struct peer *peer, peer->htlc_id_counter++; /* FIXME: Never propose duplicate rvalues? */ - idata.htlc_prog = &prog; + idata.stage = &stage; state_event(peer, CMD_SEND_HTLC_ADD, &idata); command_success(jsoncmd, null_response(jsoncmd)); } diff --git a/daemon/peer.h b/daemon/peer.h index 97c2f5058..2690e4674 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -94,11 +94,6 @@ struct peer_visible_state { struct channel_state *staging_cstate; }; -struct htlc_progress { - /* The HTLC we're working on. */ - union htlc_staging stage; -}; - struct out_pkt { Pkt *pkt; void (*ack_cb)(struct peer *peer, void *arg); diff --git a/state.c b/state.c index 5ae0ff6be..c7929ea27 100644 --- a/state.c +++ b/state.c @@ -251,19 +251,20 @@ enum state state(struct peer *peer, case STATE_NORMAL_COMMITTING: if (input_is(input, CMD_SEND_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); } 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. */ queue_pkt_htlc_fulfill(peer, - idata->htlc_prog->stage.fulfill.id, - &idata->htlc_prog->stage.fulfill.r); + idata->stage->fulfill.id, + &idata->stage->fulfill.r); return unchanged_state(peer, input); } 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. */ - 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); } /* Only expect revocation in STATE_NORMAL_COMMITTING */ diff --git a/state.h b/state.h index efe2ca734..97122a145 100644 --- a/state.h +++ b/state.h @@ -80,19 +80,10 @@ static inline bool input_is_pkt(enum state_input input) } union input { + /* For PKT_* */ Pkt *pkt; - struct command *cmd; - struct bitcoin_tx *tx; - 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; + /* For CMD_SEND_HTLC_ADD, CMD_SEND_HTLC_FULFILL, CMD_SEND_HTLC_FAIL */ + union htlc_staging *stage; }; enum state state(struct peer *peer, @@ -125,17 +116,13 @@ struct signature; /* Inform peer have an unexpected packet. */ 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 */ void queue_pkt_open(struct peer *peer, OpenChannel__AnchorOffer anchor); void queue_pkt_anchor(struct peer *peer); void queue_pkt_open_commit_sig(struct peer *peer); void queue_pkt_open_complete(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_fail(struct peer *peer, u64 id); void queue_pkt_commit(struct peer *peer);