From 9efdbbb21b367ee928d7c1a2f63eb21b84477402 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jan 2016 06:45:27 +1030 Subject: [PATCH] peer: use funding.h's struct channel_htlc. Instead of our own fields for the current htlc. Signed-off-by: Rusty Russell --- daemon/packets.c | 21 +++++++++++---------- daemon/peer.c | 15 ++++++++------- daemon/peer.h | 4 +--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/daemon/packets.c b/daemon/packets.c index e8eb03771..deb8dea43 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -139,9 +139,9 @@ Pkt *pkt_htlc_update(const tal_t *ctx, const struct peer *peer, update_add_htlc__init(u); u->revocation_hash = sha256_to_proto(u, &htlc_prog->our_revocation_hash); - u->amount_msat = htlc_prog->msatoshis; - u->r_hash = sha256_to_proto(u, &htlc_prog->rhash); - u->expiry = abs_locktime_to_proto(u, &htlc_prog->expiry); + u->amount_msat = htlc_prog->htlc->msatoshis; + u->r_hash = sha256_to_proto(u, &htlc_prog->htlc->rhash); + u->expiry = abs_locktime_to_proto(u, &htlc_prog->htlc->expiry); return make_pkt(ctx, PKT__PKT_UPDATE_ADD_HTLC, u); } @@ -381,25 +381,26 @@ Pkt *accept_pkt_htlc_update(const tal_t *ctx, struct htlc_progress *cur = tal(peer, struct htlc_progress); Pkt *err; - cur->msatoshis = u->amount_msat; - proto_to_sha256(u->r_hash, &cur->rhash); + cur->htlc = tal(cur, struct channel_htlc); + cur->htlc->msatoshis = u->amount_msat; + proto_to_sha256(u->r_hash, &cur->htlc->rhash); proto_to_sha256(u->revocation_hash, &cur->their_revocation_hash); - if (!proto_to_abs_locktime(u->expiry, &cur->expiry)) { + if (!proto_to_abs_locktime(u->expiry, &cur->htlc->expiry)) { err = pkt_err(ctx, "Invalid HTLC expiry"); goto fail; } cur->cstate = copy_funding(cur, peer->cstate); if (!funding_delta(peer->them.offer_anchor == CMD_OPEN_WITH_ANCHOR, peer->anchor.satoshis, - 0, cur->msatoshis, + 0, cur->htlc->msatoshis, &cur->cstate->b, &cur->cstate->a)) { err = pkt_err(ctx, "Cannot afford %"PRIu64" milli-satoshis", - cur->msatoshis); + cur->htlc->msatoshis); goto fail; } /* Add the htlc to their side of channel. */ - funding_add_htlc(&cur->cstate->b, cur->msatoshis, - &cur->expiry, &cur->rhash); + funding_add_htlc(&cur->cstate->b, cur->htlc->msatoshis, + &cur->htlc->expiry, &cur->htlc->rhash); peer_get_revocation_hash(peer, peer->num_htlcs+1, &cur->our_revocation_hash); diff --git a/daemon/peer.c b/daemon/peer.c index 4552b6ada..a30ed4525 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -968,7 +968,8 @@ static void json_newhtlc(struct command *cmd, /* Attach to cmd until it's complete. */ cur = tal(cmd, struct htlc_progress); - if (!json_tok_u64(buffer, msatoshistok, &cur->msatoshis)) { + cur->htlc = tal(cur, struct channel_htlc); + if (!json_tok_u64(buffer, msatoshistok, &cur->htlc->msatoshis)) { command_fail(cmd, "'%.*s' is not a valid number", (int)(msatoshistok->end - msatoshistok->start), buffer + msatoshistok->start); @@ -981,7 +982,7 @@ static void json_newhtlc(struct command *cmd, return; } - if (!seconds_to_abs_locktime(expiry, &cur->expiry)) { + if (!seconds_to_abs_locktime(expiry, &cur->htlc->expiry)) { command_fail(cmd, "'%.*s' is not a valid number", (int)(expirytok->end - expirytok->start), buffer + expirytok->start); @@ -989,7 +990,7 @@ static void json_newhtlc(struct command *cmd, } if (!hex_decode(buffer + rhashtok->start, rhashtok->end - rhashtok->start, - &cur->rhash, sizeof(cur->rhash))) { + &cur->htlc->rhash, sizeof(cur->htlc->rhash))) { command_fail(cmd, "'%.*s' is not a valid sha256 hash", (int)(rhashtok->end - rhashtok->start), buffer + rhashtok->start); @@ -1002,15 +1003,15 @@ static void json_newhtlc(struct command *cmd, cur->cstate = copy_funding(cur, peer->cstate); if (!funding_delta(peer->us.offer_anchor == CMD_OPEN_WITH_ANCHOR, peer->anchor.satoshis, - 0, cur->msatoshis, + 0, cur->htlc->msatoshis, &cur->cstate->a, &cur->cstate->b)) { command_fail(cmd, "Cannot afford %"PRIu64" milli-satoshis", - cur->msatoshis); + cur->htlc->msatoshis); return; } /* Add the htlc to our side of channel. */ - funding_add_htlc(&cur->cstate->a, cur->msatoshis, - &cur->expiry, &cur->rhash); + funding_add_htlc(&cur->cstate->a, cur->htlc->msatoshis, + &cur->htlc->expiry, &cur->htlc->rhash); peer->current_htlc = tal_steal(peer, cur); peer->jsoncmd = cmd; diff --git a/daemon/peer.h b/daemon/peer.h index cc520074a..6baebe8ce 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -32,9 +32,7 @@ struct peer_visible_state { struct htlc_progress { /* Channel funding state, after we've completed htlc. */ struct channel_state *cstate; - struct abs_locktime expiry; - u64 msatoshis; - struct sha256 rhash; + struct channel_htlc *htlc; struct sha256 our_revocation_hash, their_revocation_hash; struct bitcoin_tx *our_commit, *their_commit; struct bitcoin_signature their_sig;