mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 14:54:26 +01:00
txs: Move commit tx generation out of the signature computation
We need the txs around, so don't throw them away after generating them.
This commit is contained in:
committed by
Rusty Russell
parent
667a763659
commit
eb8eabcc3c
@@ -71,6 +71,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
||||
const struct channel *channel,
|
||||
const struct pubkey *per_commitment_point,
|
||||
enum side side,
|
||||
struct wally_tx_output *direct_outputs[NUM_SIDES],
|
||||
char** err_reason)
|
||||
{
|
||||
struct keyset keyset;
|
||||
@@ -105,6 +106,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
||||
channel->view[side].owed[!side],
|
||||
channel->config[!side].channel_reserve,
|
||||
0 ^ channel->commitment_number_obscurer,
|
||||
direct_outputs,
|
||||
side,
|
||||
err_reason);
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
||||
* @channel: The channel to evaluate
|
||||
* @per_commitment_point: Per-commitment point to determine keys
|
||||
* @side: which side to get the commitment transaction for
|
||||
* @direct_outputs: If non-NULL, fill with pointers to the direct (non-HTLC) outputs (or NULL if none).
|
||||
* @err_reason: When NULL is returned, this will point to a human readable reason.
|
||||
*
|
||||
* Returns the unsigned initial commitment transaction for @side, or NULL
|
||||
@@ -116,6 +117,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
||||
const struct channel *channel,
|
||||
const struct pubkey *per_commitment_point,
|
||||
enum side side,
|
||||
struct wally_tx_output *direct_outputs[NUM_SIDES],
|
||||
char** err_reason);
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,6 +71,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
struct amount_msat other_pay,
|
||||
struct amount_sat self_reserve,
|
||||
u64 obscured_commitment_number,
|
||||
struct wally_tx_output *direct_outputs[NUM_SIDES],
|
||||
enum side side,
|
||||
char** err_reason)
|
||||
{
|
||||
@@ -80,6 +81,8 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
struct amount_msat total_pay;
|
||||
struct amount_sat amount;
|
||||
u32 sequence;
|
||||
void *dummy_local = (void *)LOCAL, *dummy_remote = (void *)REMOTE;
|
||||
const void *output_order[NUM_SIDES];
|
||||
|
||||
if (!amount_msat_add(&total_pay, self_pay, other_pay))
|
||||
abort();
|
||||
@@ -180,6 +183,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
tx->output_witscripts[n]->ptr =
|
||||
tal_dup_arr(tx->output_witscripts[n], u8,
|
||||
wscript, tal_count(wscript), 0);
|
||||
output_order[n] = dummy_local;
|
||||
n++;
|
||||
}
|
||||
|
||||
@@ -202,6 +206,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
tx, scriptpubkey_p2wpkh(tx, &keyset->other_payment_key),
|
||||
amount);
|
||||
assert(pos == n);
|
||||
output_order[n] = dummy_remote;
|
||||
n++;
|
||||
}
|
||||
|
||||
@@ -212,7 +217,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
* 7. Sort the outputs into [BIP 69+CLTV
|
||||
* order](#transaction-input-and-output-ordering)
|
||||
*/
|
||||
permute_outputs(tx, NULL, NULL);
|
||||
permute_outputs(tx, NULL, output_order);
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
@@ -241,7 +246,19 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
sequence = (0x80000000 | ((obscured_commitment_number>>24) & 0xFFFFFF));
|
||||
bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, funding, NULL);
|
||||
|
||||
if (direct_outputs != NULL) {
|
||||
direct_outputs[LOCAL] = direct_outputs[REMOTE] = NULL;
|
||||
for (size_t i = 0; i < tx->wtx->num_outputs; i++) {
|
||||
if (output_order[i] == dummy_local)
|
||||
direct_outputs[LOCAL] = &tx->wtx->outputs[i];
|
||||
else if (output_order[i] == dummy_remote)
|
||||
direct_outputs[REMOTE] = &tx->wtx->outputs[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* This doesn't reorder outputs, so we can do this after mapping outputs. */
|
||||
bitcoin_tx_finalize(tx);
|
||||
|
||||
assert(bitcoin_tx_check(tx));
|
||||
|
||||
return tx;
|
||||
|
||||
@@ -84,6 +84,7 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
|
||||
* @other_pay: amount to pay directly to the other side
|
||||
* @self_reserve: reserve the other side insisted we have
|
||||
* @obscured_commitment_number: number to encode in commitment transaction
|
||||
* @direct_outputs: If non-NULL, fill with pointers to the direct (non-HTLC) outputs (or NULL if none).
|
||||
* @side: side to generate commitment transaction for.
|
||||
* @err_reason: When NULL is returned, this will point to a human readable reason.
|
||||
*
|
||||
@@ -104,6 +105,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
struct amount_msat other_pay,
|
||||
struct amount_sat self_reserve,
|
||||
u64 obscured_commitment_number,
|
||||
struct wally_tx_output *direct_outputs[NUM_SIDES],
|
||||
enum side side,
|
||||
char** err_reason);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user