mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-10 01:24:30 +01:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user