Browse Source

peer: use funding.h's struct channel_htlc.

Instead of our own fields for the current htlc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
9efdbbb21b
  1. 21
      daemon/packets.c
  2. 15
      daemon/peer.c
  3. 4
      daemon/peer.h

21
daemon/packets.c

@ -139,9 +139,9 @@ Pkt *pkt_htlc_update(const tal_t *ctx, const struct peer *peer,
update_add_htlc__init(u); update_add_htlc__init(u);
u->revocation_hash = sha256_to_proto(u, &htlc_prog->our_revocation_hash); u->revocation_hash = sha256_to_proto(u, &htlc_prog->our_revocation_hash);
u->amount_msat = htlc_prog->msatoshis; u->amount_msat = htlc_prog->htlc->msatoshis;
u->r_hash = sha256_to_proto(u, &htlc_prog->rhash); u->r_hash = sha256_to_proto(u, &htlc_prog->htlc->rhash);
u->expiry = abs_locktime_to_proto(u, &htlc_prog->expiry); u->expiry = abs_locktime_to_proto(u, &htlc_prog->htlc->expiry);
return make_pkt(ctx, PKT__PKT_UPDATE_ADD_HTLC, u); 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); struct htlc_progress *cur = tal(peer, struct htlc_progress);
Pkt *err; Pkt *err;
cur->msatoshis = u->amount_msat; cur->htlc = tal(cur, struct channel_htlc);
proto_to_sha256(u->r_hash, &cur->rhash); 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); 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"); err = pkt_err(ctx, "Invalid HTLC expiry");
goto fail; goto fail;
} }
cur->cstate = copy_funding(cur, peer->cstate); cur->cstate = copy_funding(cur, peer->cstate);
if (!funding_delta(peer->them.offer_anchor == CMD_OPEN_WITH_ANCHOR, if (!funding_delta(peer->them.offer_anchor == CMD_OPEN_WITH_ANCHOR,
peer->anchor.satoshis, peer->anchor.satoshis,
0, cur->msatoshis, 0, cur->htlc->msatoshis,
&cur->cstate->b, &cur->cstate->a)) { &cur->cstate->b, &cur->cstate->a)) {
err = pkt_err(ctx, "Cannot afford %"PRIu64" milli-satoshis", err = pkt_err(ctx, "Cannot afford %"PRIu64" milli-satoshis",
cur->msatoshis); cur->htlc->msatoshis);
goto fail; goto fail;
} }
/* Add the htlc to their side of channel. */ /* Add the htlc to their side of channel. */
funding_add_htlc(&cur->cstate->b, cur->msatoshis, funding_add_htlc(&cur->cstate->b, cur->htlc->msatoshis,
&cur->expiry, &cur->rhash); &cur->htlc->expiry, &cur->htlc->rhash);
peer_get_revocation_hash(peer, peer->num_htlcs+1, peer_get_revocation_hash(peer, peer->num_htlcs+1,
&cur->our_revocation_hash); &cur->our_revocation_hash);

15
daemon/peer.c

@ -968,7 +968,8 @@ static void json_newhtlc(struct command *cmd,
/* Attach to cmd until it's complete. */ /* Attach to cmd until it's complete. */
cur = tal(cmd, struct htlc_progress); 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", command_fail(cmd, "'%.*s' is not a valid number",
(int)(msatoshistok->end - msatoshistok->start), (int)(msatoshistok->end - msatoshistok->start),
buffer + msatoshistok->start); buffer + msatoshistok->start);
@ -981,7 +982,7 @@ static void json_newhtlc(struct command *cmd,
return; 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", command_fail(cmd, "'%.*s' is not a valid number",
(int)(expirytok->end - expirytok->start), (int)(expirytok->end - expirytok->start),
buffer + expirytok->start); buffer + expirytok->start);
@ -989,7 +990,7 @@ static void json_newhtlc(struct command *cmd,
} }
if (!hex_decode(buffer + rhashtok->start, if (!hex_decode(buffer + rhashtok->start,
rhashtok->end - 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", command_fail(cmd, "'%.*s' is not a valid sha256 hash",
(int)(rhashtok->end - rhashtok->start), (int)(rhashtok->end - rhashtok->start),
buffer + rhashtok->start); buffer + rhashtok->start);
@ -1002,15 +1003,15 @@ static void json_newhtlc(struct command *cmd,
cur->cstate = copy_funding(cur, peer->cstate); cur->cstate = copy_funding(cur, peer->cstate);
if (!funding_delta(peer->us.offer_anchor == CMD_OPEN_WITH_ANCHOR, if (!funding_delta(peer->us.offer_anchor == CMD_OPEN_WITH_ANCHOR,
peer->anchor.satoshis, peer->anchor.satoshis,
0, cur->msatoshis, 0, cur->htlc->msatoshis,
&cur->cstate->a, &cur->cstate->b)) { &cur->cstate->a, &cur->cstate->b)) {
command_fail(cmd, "Cannot afford %"PRIu64" milli-satoshis", command_fail(cmd, "Cannot afford %"PRIu64" milli-satoshis",
cur->msatoshis); cur->htlc->msatoshis);
return; return;
} }
/* Add the htlc to our side of channel. */ /* Add the htlc to our side of channel. */
funding_add_htlc(&cur->cstate->a, cur->msatoshis, funding_add_htlc(&cur->cstate->a, cur->htlc->msatoshis,
&cur->expiry, &cur->rhash); &cur->htlc->expiry, &cur->htlc->rhash);
peer->current_htlc = tal_steal(peer, cur); peer->current_htlc = tal_steal(peer, cur);
peer->jsoncmd = cmd; peer->jsoncmd = cmd;

4
daemon/peer.h

@ -32,9 +32,7 @@ struct peer_visible_state {
struct htlc_progress { struct htlc_progress {
/* Channel funding state, after we've completed htlc. */ /* Channel funding state, after we've completed htlc. */
struct channel_state *cstate; struct channel_state *cstate;
struct abs_locktime expiry; struct channel_htlc *htlc;
u64 msatoshis;
struct sha256 rhash;
struct sha256 our_revocation_hash, their_revocation_hash; struct sha256 our_revocation_hash, their_revocation_hash;
struct bitcoin_tx *our_commit, *their_commit; struct bitcoin_tx *our_commit, *their_commit;
struct bitcoin_signature their_sig; struct bitcoin_signature their_sig;

Loading…
Cancel
Save