daemon: use htlc pointers everywhere.

No more copies!

I tried changing the cstate->side[].htlcs to htlc_map rather than a
simple pointer array, but we rely on those array indices heavily for
permutation mapping, and it turned into a major rewrite (especially
for the steal case).

Eventually, we're going to want to reconstruct the commit info for
older commit txs rather than keeping all the permutation and
per-commit-info HTLC information in memory, so we can do the work
then.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-06-30 09:08:11 +09:30
parent 67ac2d2081
commit cc4fc4b668
7 changed files with 240 additions and 251 deletions

View File

@@ -11,7 +11,7 @@
#include <assert.h>
static bool add_htlc(struct bitcoin_tx *tx, size_t n,
const struct channel_htlc *h,
const struct htlc *h,
const struct pubkey *ourkey,
const struct pubkey *theirkey,
const struct sha256 *rhash,
@@ -96,7 +96,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
/* HTLCs this side sent. */
for (i = 0; i < tal_count(cstate->side[side].htlcs); i++) {
if (!add_htlc(tx, num, &cstate->side[side].htlcs[i],
if (!add_htlc(tx, num, cstate->side[side].htlcs[i],
self, other, rhash, locktime,
bitcoin_redeem_htlc_send))
return tal_free(tx);
@@ -104,7 +104,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
}
/* HTLCs this side has received. */
for (i = 0; i < tal_count(cstate->side[!side].htlcs); i++) {
if (!add_htlc(tx, num, &cstate->side[!side].htlcs[i],
if (!add_htlc(tx, num, cstate->side[!side].htlcs[i],
self, other, rhash, locktime,
bitcoin_redeem_htlc_recv))
return tal_free(tx);