diff --git a/commit_tx.c b/commit_tx.c index e0dda433f..a8a6208a6 100644 --- a/commit_tx.c +++ b/commit_tx.c @@ -42,7 +42,8 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx, unsigned int anchor_index, u64 anchor_satoshis, const struct sha256 *rhash, - const struct channel_state *cstate) + const struct channel_state *cstate, + int **map) { struct bitcoin_tx *tx; const u8 *redeemscript; @@ -94,7 +95,8 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx, } assert(num == tx->output_count); assert(total <= anchor_satoshis); - - permute_outputs(tx->output, tx->output_count, NULL); + + *map = tal_arr(ctx, int, tx->output_count); + permute_outputs(tx->output, tx->output_count, *map); return tx; } diff --git a/commit_tx.h b/commit_tx.h index fabd8889b..a6dea8d35 100644 --- a/commit_tx.h +++ b/commit_tx.h @@ -20,5 +20,6 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx, unsigned int anchor_index, u64 anchor_satoshis, const struct sha256 *rhash, - const struct channel_state *cstate); + const struct channel_state *cstate, + int **map); #endif diff --git a/daemon/packets.c b/daemon/packets.c index 1583c81b3..a2e7b09b7 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -304,7 +304,8 @@ void queue_pkt_commit(struct peer *peer) peer->anchor.index, peer->anchor.satoshis, &ci->revocation_hash, - ci->cstate); + ci->cstate, + &ci->map); log_debug(peer->log, "Signing tx for %u/%u msatoshis, %zu/%zu htlcs", ci->cstate->a.pay_msat, @@ -693,7 +694,8 @@ Pkt *accept_pkt_commit(struct peer *peer, const Pkt *pkt) peer->anchor.index, peer->anchor.satoshis, &ci->revocation_hash, - ci->cstate); + ci->cstate, + &ci->map); /* BOLT #2: * diff --git a/daemon/peer.c b/daemon/peer.c index 8dde400b3..70f452cc7 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -1330,7 +1330,8 @@ bool setup_first_commit(struct peer *peer) peer->anchor.index, peer->anchor.satoshis, &peer->us.commit->revocation_hash, - peer->us.commit->cstate); + peer->us.commit->cstate, + &peer->us.commit->map); peer->them.commit->tx = create_commit_tx(peer->them.commit, &peer->them.finalkey, @@ -1340,7 +1341,8 @@ bool setup_first_commit(struct peer *peer) peer->anchor.index, peer->anchor.satoshis, &peer->them.commit->revocation_hash, - peer->them.commit->cstate); + peer->them.commit->cstate, + &peer->them.commit->map); peer->us.staging_cstate = copy_funding(peer, peer->us.commit->cstate); peer->them.staging_cstate = copy_funding(peer, peer->them.commit->cstate); diff --git a/daemon/peer.h b/daemon/peer.h index 0eb10db25..6539e043f 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -63,6 +63,8 @@ struct commit_info { struct channel_state *cstate; /* Other side's signature for this commit tx. */ struct bitcoin_signature sig; + /* Map for permutation: see commit_tx.c */ + int *map; /* Revocation preimage (if known). */ struct sha256 *revocation_preimage; }; diff --git a/permute_tx.c b/permute_tx.c index 7c1a5934a..a80af7805 100644 --- a/permute_tx.c +++ b/permute_tx.c @@ -2,7 +2,7 @@ #include #include -static void init_map(size_t *map, size_t len) +static void init_map(int *map, size_t len) { size_t i; @@ -15,10 +15,10 @@ static void init_map(size_t *map, size_t len) /* This map says where things ended up, eg. 0 might be in slot 3. we * want to change it so map[0] = 3. */ -static void invert_map(size_t *map, size_t len) +static void invert_map(int *map, size_t len) { if (map) { - size_t i, newmap[len]; + int i, newmap[len]; memset(newmap, 0, sizeof(newmap)); for (i = 0; i < len; i++) { @@ -59,7 +59,7 @@ static size_t find_best_in(struct bitcoin_tx_input *inputs, size_t num) return best; } -static void swap_inputs(struct bitcoin_tx_input *inputs, size_t *map, +static void swap_inputs(struct bitcoin_tx_input *inputs, int *map, size_t i1, size_t i2) { struct bitcoin_tx_input tmpinput; @@ -78,7 +78,7 @@ static void swap_inputs(struct bitcoin_tx_input *inputs, size_t *map, void permute_inputs(struct bitcoin_tx_input *inputs, size_t num_inputs, - size_t *map) + int *map) { size_t i; @@ -94,7 +94,7 @@ void permute_inputs(struct bitcoin_tx_input *inputs, invert_map(map, num_inputs); } -static void swap_outputs(struct bitcoin_tx_output *outputs, size_t *map, +static void swap_outputs(struct bitcoin_tx_output *outputs, int *map, size_t i1, size_t i2) { struct bitcoin_tx_output tmpoutput; @@ -146,7 +146,7 @@ static size_t find_best_out(struct bitcoin_tx_output *outputs, size_t num) void permute_outputs(struct bitcoin_tx_output *outputs, size_t num_outputs, - size_t *map) + int *map) { size_t i; diff --git a/permute_tx.h b/permute_tx.h index a2fa94d37..32633f517 100644 --- a/permute_tx.h +++ b/permute_tx.h @@ -8,9 +8,9 @@ */ void permute_inputs(struct bitcoin_tx_input *inputs, size_t num_inputs, - size_t *map); + int *map); void permute_outputs(struct bitcoin_tx_output *outputs, size_t num_outputs, - size_t *map); + int *map); #endif /* LIGHTNING_PERMUTE_TX_H */