Removing duplicated wscript generation for channel txs

This commit is contained in:
Dr. Maxim Orlovsky
2020-02-18 04:50:18 +01:00
committed by Rusty Russell
parent 72327f5cc2
commit fe85cf9a4f
7 changed files with 68 additions and 67 deletions

View File

@@ -259,7 +259,7 @@ int main(int argc, char *argv[])
struct bitcoin_tx **local_txs, **remote_txs;
enum side fee_payer;
u8 **witness;
const u8 **wscripts;
const u8 *funding_wscript;
struct channel *channel;
struct existing_htlc **htlcs = tal_arr(NULL, struct existing_htlc *, 0);
const struct htlc **htlcmap;
@@ -393,15 +393,11 @@ int main(int argc, char *argv[])
cast_const2(const struct existing_htlc **, htlcs)))
errx(1, "Cannot add HTLCs");
u8 *funding_wscript = bitcoin_redeem_2of2(NULL,
&funding_localkey,
&funding_remotekey);
/* Create the local commitment_tx */
if (!per_commit_point(&localseed, &local_per_commit_point, commitnum))
errx(1, "Bad deriving local per-commitment-point");
local_txs = channel_txs(NULL, &htlcmap, &wscripts, channel,
local_txs = channel_txs(NULL, &htlcmap, &funding_wscript, channel,
&local_per_commit_point, commitnum, LOCAL);
printf("## local_commitment\n"
@@ -477,14 +473,17 @@ int main(int argc, char *argv[])
local_txs[1+i]->input_amounts[0]
= tal_dup(local_txs[1+i], struct amount_sat, &amt);
printf("# wscript: %s\n", tal_hex(NULL, wscripts[1+i]));
printf("# wscript: %s\n", tal_hex(NULL, local_txs[1+i]->output_witscripts[1+i]->ptr));
bitcoin_tx_hash_for_sig(local_txs[1+i], 0, wscripts[1+i],
bitcoin_tx_hash_for_sig(local_txs[1+i], 0,
local_txs[1+i]->output_witscripts[1+i]->ptr,
SIGHASH_ALL, &hash);
sign_tx_input(local_txs[1+i], 0, NULL, wscripts[1+i],
sign_tx_input(local_txs[1+i], 0, NULL,
local_txs[1+i]->output_witscripts[1+i]->ptr,
&local_htlc_privkey, &local_htlc_pubkey,
SIGHASH_ALL, &local_htlc_sig);
sign_tx_input(local_txs[1+i], 0, NULL, wscripts[1+i],
sign_tx_input(local_txs[1+i], 0, NULL,
local_txs[1+i]->output_witscripts[1+i]->ptr,
&remote_htlc_privkey, &remote_htlc_pubkey,
SIGHASH_ALL, &remote_htlc_sig);
printf("localsig_on_local output %zu: %s\n",
@@ -496,13 +495,13 @@ int main(int argc, char *argv[])
witness = bitcoin_witness_htlc_timeout_tx(NULL,
&local_htlc_sig,
&remote_htlc_sig,
wscripts[1+i]);
local_txs[1+i]->output_witscripts[1+i]->ptr);
else
witness = bitcoin_witness_htlc_success_tx(NULL,
&local_htlc_sig,
&remote_htlc_sig,
preimage_of(&htlcmap[i]->rhash, cast_const2(const struct existing_htlc **, htlcs)),
wscripts[1+i]);
local_txs[1+i]->output_witscripts[1+i]->ptr);
bitcoin_tx_input_set_witness(local_txs[1+i], 0, witness);
printf("htlc tx for output %zu: %s\n",
i, tal_hex(NULL, linearize_tx(NULL, local_txs[1+i])));
@@ -512,7 +511,7 @@ int main(int argc, char *argv[])
/* Create the remote commitment tx */
if (!per_commit_point(&remoteseed, &remote_per_commit_point, commitnum))
errx(1, "Bad deriving remote per-commitment-point");
remote_txs = channel_txs(NULL, &htlcmap, &wscripts, channel,
remote_txs = channel_txs(NULL, &htlcmap, &funding_wscript, channel,
&remote_per_commit_point, commitnum, REMOTE);
remote_txs[0]->input_amounts[0]
= tal_dup(remote_txs[0], struct amount_sat, &funding_amount);
@@ -589,13 +588,16 @@ int main(int argc, char *argv[])
remote_txs[1+i]->input_amounts[0]
= tal_dup(remote_txs[1+i], struct amount_sat, &amt);
printf("# wscript: %s\n", tal_hex(NULL, wscripts[1+i]));
bitcoin_tx_hash_for_sig(remote_txs[1+i], 0, wscripts[1+i],
printf("# wscript: %s\n", tal_hex(NULL, remote_txs[1+i]->output_witscripts[1+i]->ptr));
bitcoin_tx_hash_for_sig(remote_txs[1+i], 0,
remote_txs[1+i]->output_witscripts[1+i]->ptr,
SIGHASH_ALL, &hash);
sign_tx_input(remote_txs[1+i], 0, NULL, wscripts[1+i],
sign_tx_input(remote_txs[1+i], 0, NULL,
remote_txs[1+i]->output_witscripts[1+i]->ptr,
&local_htlc_privkey, &local_htlc_pubkey,
SIGHASH_ALL, &local_htlc_sig);
sign_tx_input(remote_txs[1+i], 0, NULL, wscripts[1+i],
sign_tx_input(remote_txs[1+i], 0, NULL,
remote_txs[1+i]->output_witscripts[1+i]->ptr,
&remote_htlc_privkey, &remote_htlc_pubkey,
SIGHASH_ALL, &remote_htlc_sig);
printf("localsig_on_remote output %zu: %s\n",
@@ -607,13 +609,13 @@ int main(int argc, char *argv[])
witness = bitcoin_witness_htlc_timeout_tx(NULL,
&remote_htlc_sig,
&local_htlc_sig,
wscripts[1+i]);
remote_txs[1+i]->output_witscripts[1+i]->ptr);
else
witness = bitcoin_witness_htlc_success_tx(NULL,
&remote_htlc_sig,
&local_htlc_sig,
preimage_of(&htlcmap[i]->rhash, cast_const2(const struct existing_htlc **, htlcs)),
wscripts[1+i]);
remote_txs[1+i]->output_witscripts[1+i]->ptr);
bitcoin_tx_input_set_witness(remote_txs[1+i], 0, witness);
printf("htlc tx for output %zu: %s\n",
i, tal_hex(NULL, linearize_tx(NULL, remote_txs[1+i])));