diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index fdb14c3cb..dd989bff9 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -80,7 +80,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, - const u8 *funding_wscript, + const struct pubkey *local_funding_key, + const struct pubkey *remote_funding_key, enum side opener, u16 to_self_delay, const struct keyset *keyset, @@ -101,6 +102,10 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, u32 *cltvs; struct htlc *dummy_to_local = (struct htlc *)0x01, *dummy_to_remote = (struct htlc *)0x02; + const u8 *funding_wscript = bitcoin_redeem_2of2(tmpctx, + local_funding_key, + remote_funding_key); + if (!amount_msat_add(&total_pay, self_pay, other_pay)) abort(); assert(!amount_msat_greater_sat(total_pay, funding)); diff --git a/channeld/commit_tx.h b/channeld/commit_tx.h index 471d82ed5..b80359fbd 100644 --- a/channeld/commit_tx.h +++ b/channeld/commit_tx.h @@ -28,6 +28,7 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs, * commit_tx: create (unsigned) commitment tx to spend the funding tx output * @ctx: context to allocate transaction and @htlc_map from. * @funding_txid, @funding_out, @funding: funding outpoint. + * @local_funding_key, @remote_funding_key: keys for funding input. * @opener: is the LOCAL or REMOTE paying the fee? * @keyset: keys derived for this commit tx. * @feerate_per_kw: feerate to use @@ -48,7 +49,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, - const u8 *funding_wscript, + const struct pubkey *local_funding_key, + const struct pubkey *remote_funding_key, enum side opener, u16 to_self_delay, const struct keyset *keyset, diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 03cd51da0..b48fdd10e 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -304,7 +304,10 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, txs = tal_arr(ctx, struct bitcoin_tx *, 1); txs[0] = commit_tx( ctx, &channel->funding_txid, channel->funding_txout, - channel->funding, cast_const(u8 *, *funding_wscript), channel->opener, + channel->funding, + &channel->funding_pubkey[side], + &channel->funding_pubkey[!side], + channel->opener, channel->config[!side].to_self_delay, &keyset, channel_feerate(channel, side), channel->config[side].dust_limit, channel->view[side].owed[side], diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index e88e07cf0..972291015 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -746,7 +746,9 @@ int main(int argc, const char *argv[]) print_superverbose = true; tx = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, LOCAL, to_self_delay, &keyset, feerate_per_kw, @@ -758,7 +760,9 @@ int main(int argc, const char *argv[]) print_superverbose = false; tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, REMOTE, to_self_delay, &keyset, feerate_per_kw, @@ -803,7 +807,9 @@ int main(int argc, const char *argv[]) print_superverbose = true; tx = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, LOCAL, to_self_delay, &keyset, feerate_per_kw, @@ -815,7 +821,9 @@ int main(int argc, const char *argv[]) print_superverbose = false; tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, REMOTE, to_self_delay, &keyset, feerate_per_kw, @@ -848,7 +856,9 @@ int main(int argc, const char *argv[]) print_superverbose = false; newtx = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, LOCAL, to_self_delay, &keyset, feerate_per_kw, @@ -861,7 +871,9 @@ int main(int argc, const char *argv[]) /* This is what it would look like for peer generating it! */ tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, REMOTE, to_self_delay, &keyset, feerate_per_kw, @@ -893,7 +905,9 @@ int main(int argc, const char *argv[]) print_superverbose = true; tx = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, LOCAL, to_self_delay, &keyset, feerate_per_kw-1, @@ -931,7 +945,9 @@ int main(int argc, const char *argv[]) print_superverbose = true; newtx = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, LOCAL, to_self_delay, &keyset, feerate_per_kw, @@ -992,7 +1008,9 @@ int main(int argc, const char *argv[]) to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw); tx = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, LOCAL, to_self_delay, &keyset, feerate_per_kw, diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 21cfa1bc5..99ffeea2f 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -524,7 +524,9 @@ int main(int argc, const char *argv[]) raw_tx = commit_tx(tmpctx, &funding_txid, funding_output_index, - funding_amount, funding_wscript, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, LOCAL, remote_config->to_self_delay, &keyset, feerate_per_kw[LOCAL], @@ -651,7 +653,10 @@ int main(int argc, const char *argv[]) raw_tx = commit_tx( tmpctx, &funding_txid, funding_output_index, - funding_amount, funding_wscript, LOCAL, remote_config->to_self_delay, + funding_amount, + &local_funding_pubkey, + &remote_funding_pubkey, + LOCAL, remote_config->to_self_delay, &keyset, feerate_per_kw[LOCAL], local_config->dust_limit, to_local, to_remote, htlcs, &htlc_map, NULL, 0x2bb038521914 ^ 42, LOCAL); diff --git a/common/initial_channel.c b/common/initial_channel.c index 00d51c16f..9f4988d46 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -98,7 +98,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, init_tx = initial_commit_tx(ctx, &channel->funding_txid, channel->funding_txout, channel->funding, - cast_const(u8 *, *wscript), + channel->funding_pubkey, channel->opener, /* They specify our to_self_delay and v.v. */ channel->config[!side].to_self_delay, @@ -152,4 +152,5 @@ static char *fmt_channel(const tal_t *ctx, const struct channel *channel) fmt_channel_view(ctx, &channel->view[LOCAL]), fmt_channel_view(ctx, &channel->view[REMOTE])); } +/* Magic comment. */ REGISTER_TYPE_TO_STRING(channel, fmt_channel); diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 01ae95728..82d45f6ed 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -62,7 +62,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, - u8 *funding_wscript, + const struct pubkey funding_key[NUM_SIDES], enum side opener, u16 to_self_delay, const struct keyset *keyset, @@ -85,6 +85,9 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, u32 sequence; void *dummy_local = (void *)LOCAL, *dummy_remote = (void *)REMOTE; const void *output_order[NUM_SIDES]; + const u8 *funding_wscript = bitcoin_redeem_2of2(tmpctx, + &funding_key[LOCAL], + &funding_key[REMOTE]); if (!amount_msat_add(&total_pay, self_pay, other_pay)) abort(); diff --git a/common/initial_commit_tx.h b/common/initial_commit_tx.h index de97401e5..f689df780 100644 --- a/common/initial_commit_tx.h +++ b/common/initial_commit_tx.h @@ -81,6 +81,7 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw, * @ctx: context to allocate transaction and @htlc_map from. * @funding_txid, @funding_out, @funding: funding outpoint. * @funding_wscript: scriptPubkey of the funding output + * @funding_keys: funding bitcoin keys * @opener: is the LOCAL or REMOTE paying the fee? * @keyset: keys derived for this commit tx. * @feerate_per_kw: feerate to use @@ -102,7 +103,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, - u8 *funding_wscript, + const struct pubkey funding_key[NUM_SIDES], enum side opener, u16 to_self_delay, const struct keyset *keyset,