mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
commit_tx: take raw funding keys instead of wscript.
It now needs the keys for anchor outputs, so have it calculate the 2 of 2 wscript internally. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -80,7 +80,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
const struct bitcoin_txid *funding_txid,
|
const struct bitcoin_txid *funding_txid,
|
||||||
unsigned int funding_txout,
|
unsigned int funding_txout,
|
||||||
struct amount_sat funding,
|
struct amount_sat funding,
|
||||||
const u8 *funding_wscript,
|
const struct pubkey *local_funding_key,
|
||||||
|
const struct pubkey *remote_funding_key,
|
||||||
enum side opener,
|
enum side opener,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct keyset *keyset,
|
const struct keyset *keyset,
|
||||||
@@ -101,6 +102,10 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
u32 *cltvs;
|
u32 *cltvs;
|
||||||
struct htlc *dummy_to_local = (struct htlc *)0x01,
|
struct htlc *dummy_to_local = (struct htlc *)0x01,
|
||||||
*dummy_to_remote = (struct htlc *)0x02;
|
*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))
|
if (!amount_msat_add(&total_pay, self_pay, other_pay))
|
||||||
abort();
|
abort();
|
||||||
assert(!amount_msat_greater_sat(total_pay, funding));
|
assert(!amount_msat_greater_sat(total_pay, funding));
|
||||||
|
|||||||
@@ -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
|
* commit_tx: create (unsigned) commitment tx to spend the funding tx output
|
||||||
* @ctx: context to allocate transaction and @htlc_map from.
|
* @ctx: context to allocate transaction and @htlc_map from.
|
||||||
* @funding_txid, @funding_out, @funding: funding outpoint.
|
* @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?
|
* @opener: is the LOCAL or REMOTE paying the fee?
|
||||||
* @keyset: keys derived for this commit tx.
|
* @keyset: keys derived for this commit tx.
|
||||||
* @feerate_per_kw: feerate to use
|
* @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,
|
const struct bitcoin_txid *funding_txid,
|
||||||
unsigned int funding_txout,
|
unsigned int funding_txout,
|
||||||
struct amount_sat funding,
|
struct amount_sat funding,
|
||||||
const u8 *funding_wscript,
|
const struct pubkey *local_funding_key,
|
||||||
|
const struct pubkey *remote_funding_key,
|
||||||
enum side opener,
|
enum side opener,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct keyset *keyset,
|
const struct keyset *keyset,
|
||||||
|
|||||||
@@ -304,7 +304,10 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
|
|||||||
txs = tal_arr(ctx, struct bitcoin_tx *, 1);
|
txs = tal_arr(ctx, struct bitcoin_tx *, 1);
|
||||||
txs[0] = commit_tx(
|
txs[0] = commit_tx(
|
||||||
ctx, &channel->funding_txid, channel->funding_txout,
|
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->config[!side].to_self_delay, &keyset,
|
||||||
channel_feerate(channel, side),
|
channel_feerate(channel, side),
|
||||||
channel->config[side].dust_limit, channel->view[side].owed[side],
|
channel->config[side].dust_limit, channel->view[side].owed[side],
|
||||||
|
|||||||
@@ -746,7 +746,9 @@ int main(int argc, const char *argv[])
|
|||||||
print_superverbose = true;
|
print_superverbose = true;
|
||||||
tx = commit_tx(tmpctx,
|
tx = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
LOCAL, to_self_delay,
|
LOCAL, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
@@ -758,7 +760,9 @@ int main(int argc, const char *argv[])
|
|||||||
print_superverbose = false;
|
print_superverbose = false;
|
||||||
tx2 = commit_tx(tmpctx,
|
tx2 = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
REMOTE, to_self_delay,
|
REMOTE, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
@@ -803,7 +807,9 @@ int main(int argc, const char *argv[])
|
|||||||
print_superverbose = true;
|
print_superverbose = true;
|
||||||
tx = commit_tx(tmpctx,
|
tx = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
LOCAL, to_self_delay,
|
LOCAL, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
@@ -815,7 +821,9 @@ int main(int argc, const char *argv[])
|
|||||||
print_superverbose = false;
|
print_superverbose = false;
|
||||||
tx2 = commit_tx(tmpctx,
|
tx2 = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
REMOTE, to_self_delay,
|
REMOTE, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
@@ -848,7 +856,9 @@ int main(int argc, const char *argv[])
|
|||||||
print_superverbose = false;
|
print_superverbose = false;
|
||||||
newtx = commit_tx(tmpctx,
|
newtx = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
LOCAL, to_self_delay,
|
LOCAL, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
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! */
|
/* This is what it would look like for peer generating it! */
|
||||||
tx2 = commit_tx(tmpctx,
|
tx2 = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
REMOTE, to_self_delay,
|
REMOTE, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
@@ -893,7 +905,9 @@ int main(int argc, const char *argv[])
|
|||||||
print_superverbose = true;
|
print_superverbose = true;
|
||||||
tx = commit_tx(tmpctx,
|
tx = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
LOCAL, to_self_delay,
|
LOCAL, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw-1,
|
feerate_per_kw-1,
|
||||||
@@ -931,7 +945,9 @@ int main(int argc, const char *argv[])
|
|||||||
print_superverbose = true;
|
print_superverbose = true;
|
||||||
newtx = commit_tx(tmpctx,
|
newtx = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
LOCAL, to_self_delay,
|
LOCAL, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
@@ -992,7 +1008,9 @@ int main(int argc, const char *argv[])
|
|||||||
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw);
|
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw);
|
||||||
tx = commit_tx(tmpctx,
|
tx = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
LOCAL, to_self_delay,
|
LOCAL, to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
|
|||||||
@@ -524,7 +524,9 @@ int main(int argc, const char *argv[])
|
|||||||
|
|
||||||
raw_tx = commit_tx(tmpctx,
|
raw_tx = commit_tx(tmpctx,
|
||||||
&funding_txid, funding_output_index,
|
&funding_txid, funding_output_index,
|
||||||
funding_amount, funding_wscript,
|
funding_amount,
|
||||||
|
&local_funding_pubkey,
|
||||||
|
&remote_funding_pubkey,
|
||||||
LOCAL, remote_config->to_self_delay,
|
LOCAL, remote_config->to_self_delay,
|
||||||
&keyset,
|
&keyset,
|
||||||
feerate_per_kw[LOCAL],
|
feerate_per_kw[LOCAL],
|
||||||
@@ -651,7 +653,10 @@ int main(int argc, const char *argv[])
|
|||||||
|
|
||||||
raw_tx = commit_tx(
|
raw_tx = commit_tx(
|
||||||
tmpctx, &funding_txid, funding_output_index,
|
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,
|
&keyset, feerate_per_kw[LOCAL], local_config->dust_limit,
|
||||||
to_local, to_remote, htlcs, &htlc_map, NULL,
|
to_local, to_remote, htlcs, &htlc_map, NULL,
|
||||||
0x2bb038521914 ^ 42, LOCAL);
|
0x2bb038521914 ^ 42, LOCAL);
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
|||||||
init_tx = initial_commit_tx(ctx, &channel->funding_txid,
|
init_tx = initial_commit_tx(ctx, &channel->funding_txid,
|
||||||
channel->funding_txout,
|
channel->funding_txout,
|
||||||
channel->funding,
|
channel->funding,
|
||||||
cast_const(u8 *, *wscript),
|
channel->funding_pubkey,
|
||||||
channel->opener,
|
channel->opener,
|
||||||
/* They specify our to_self_delay and v.v. */
|
/* They specify our to_self_delay and v.v. */
|
||||||
channel->config[!side].to_self_delay,
|
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[LOCAL]),
|
||||||
fmt_channel_view(ctx, &channel->view[REMOTE]));
|
fmt_channel_view(ctx, &channel->view[REMOTE]));
|
||||||
}
|
}
|
||||||
|
/* Magic comment. */
|
||||||
REGISTER_TYPE_TO_STRING(channel, fmt_channel);
|
REGISTER_TYPE_TO_STRING(channel, fmt_channel);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
const struct bitcoin_txid *funding_txid,
|
const struct bitcoin_txid *funding_txid,
|
||||||
unsigned int funding_txout,
|
unsigned int funding_txout,
|
||||||
struct amount_sat funding,
|
struct amount_sat funding,
|
||||||
u8 *funding_wscript,
|
const struct pubkey funding_key[NUM_SIDES],
|
||||||
enum side opener,
|
enum side opener,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct keyset *keyset,
|
const struct keyset *keyset,
|
||||||
@@ -85,6 +85,9 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
u32 sequence;
|
u32 sequence;
|
||||||
void *dummy_local = (void *)LOCAL, *dummy_remote = (void *)REMOTE;
|
void *dummy_local = (void *)LOCAL, *dummy_remote = (void *)REMOTE;
|
||||||
const void *output_order[NUM_SIDES];
|
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))
|
if (!amount_msat_add(&total_pay, self_pay, other_pay))
|
||||||
abort();
|
abort();
|
||||||
|
|||||||
@@ -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.
|
* @ctx: context to allocate transaction and @htlc_map from.
|
||||||
* @funding_txid, @funding_out, @funding: funding outpoint.
|
* @funding_txid, @funding_out, @funding: funding outpoint.
|
||||||
* @funding_wscript: scriptPubkey of the funding output
|
* @funding_wscript: scriptPubkey of the funding output
|
||||||
|
* @funding_keys: funding bitcoin keys
|
||||||
* @opener: is the LOCAL or REMOTE paying the fee?
|
* @opener: is the LOCAL or REMOTE paying the fee?
|
||||||
* @keyset: keys derived for this commit tx.
|
* @keyset: keys derived for this commit tx.
|
||||||
* @feerate_per_kw: feerate to use
|
* @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,
|
const struct bitcoin_txid *funding_txid,
|
||||||
unsigned int funding_txout,
|
unsigned int funding_txout,
|
||||||
struct amount_sat funding,
|
struct amount_sat funding,
|
||||||
u8 *funding_wscript,
|
const struct pubkey funding_key[NUM_SIDES],
|
||||||
enum side opener,
|
enum side opener,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct keyset *keyset,
|
const struct keyset *keyset,
|
||||||
|
|||||||
Reference in New Issue
Block a user