mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
bitcoin/tx.c: don't free witness implicitly.
This causes a crash in mkfunding, which didn't expect it: $ devtools/mkfunding 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b 1 0.01btc 253 76edf0c303b9e692da9cb491abedef46ca5b81d32f102eb4648461b239cb0f99 0000000000000000000000000000000000000000000000000000000000000010 0000000000000000000000000000000000000000000000000000000000000020 # funding sig: 798d96d5a057b5b7797988a855217f41af05ece3ba8278366e2f69763c72e78565d5dd7eeddc0766ddf65557c92b9c52c301f23f94d2cf681860d32153e6ae1e # funding witnesses: [ Aborted (core dumped) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
e4d0ef6e11
commit
39b34a35c8
@ -117,7 +117,8 @@ void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
|
|||||||
wally_tx_set_input_witness(tx->wtx, innum, stack);
|
wally_tx_set_input_witness(tx->wtx, innum, stack);
|
||||||
if (stack)
|
if (stack)
|
||||||
wally_tx_witness_stack_free(stack);
|
wally_tx_witness_stack_free(stack);
|
||||||
tal_free(witness);
|
if (taken(witness))
|
||||||
|
tal_free(witness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitcoin_tx_input_set_script(struct bitcoin_tx *tx, int innum, u8 *script)
|
void bitcoin_tx_input_set_script(struct bitcoin_tx *tx, int innum, u8 *script)
|
||||||
|
@ -116,7 +116,7 @@ struct amount_sat bitcoin_tx_output_get_amount(const struct bitcoin_tx *tx,
|
|||||||
* itself, we need a way to attach a witness to an existing input.
|
* itself, we need a way to attach a witness to an existing input.
|
||||||
*/
|
*/
|
||||||
void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
|
void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
|
||||||
u8 **witness);
|
u8 **witness TAKES);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the input script on the given input.
|
* Set the input script on the given input.
|
||||||
|
@ -350,7 +350,7 @@ static void report(struct bitcoin_tx *tx,
|
|||||||
witness =
|
witness =
|
||||||
bitcoin_witness_2of2(tx, &localsig, &remotesig,
|
bitcoin_witness_2of2(tx, &localsig, &remotesig,
|
||||||
local_funding_pubkey, remote_funding_pubkey);
|
local_funding_pubkey, remote_funding_pubkey);
|
||||||
bitcoin_tx_input_set_witness(tx, 0, witness);
|
bitcoin_tx_input_set_witness(tx, 0, take(witness));
|
||||||
txhex = tal_hex(tmpctx, linearize_tx(tx, tx));
|
txhex = tal_hex(tmpctx, linearize_tx(tx, tx));
|
||||||
printf("output commit_tx: %s\n", txhex);
|
printf("output commit_tx: %s\n", txhex);
|
||||||
|
|
||||||
@ -993,6 +993,7 @@ int main(void)
|
|||||||
|
|
||||||
/* No memory leaks please */
|
/* No memory leaks please */
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
|
take_cleanup();
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
|
|
||||||
/* FIXME: Do BOLT comparison! */
|
/* FIXME: Do BOLT comparison! */
|
||||||
|
@ -109,7 +109,7 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
|
|||||||
witness = bitcoin_witness_htlc_success_tx(htlc_success,
|
witness = bitcoin_witness_htlc_success_tx(htlc_success,
|
||||||
localhtlcsig, remotehtlcsig,
|
localhtlcsig, remotehtlcsig,
|
||||||
payment_preimage, wscript);
|
payment_preimage, wscript);
|
||||||
bitcoin_tx_input_set_witness(htlc_success, 0, witness);
|
bitcoin_tx_input_set_witness(htlc_success, 0, take(witness));
|
||||||
tal_free(wscript);
|
tal_free(wscript);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout,
|
|||||||
|
|
||||||
witness = bitcoin_witness_htlc_timeout_tx(htlc_timeout, localhtlcsig,
|
witness = bitcoin_witness_htlc_timeout_tx(htlc_timeout, localhtlcsig,
|
||||||
remotehtlcsig, wscript);
|
remotehtlcsig, wscript);
|
||||||
bitcoin_tx_input_set_witness(htlc_timeout, 0, witness);
|
bitcoin_tx_input_set_witness(htlc_timeout, 0, take(witness));
|
||||||
tal_free(wscript);
|
tal_free(wscript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ int main(int argc, char *argv[])
|
|||||||
witness =
|
witness =
|
||||||
bitcoin_witness_2of2(NULL, &local_sig, &remote_sig,
|
bitcoin_witness_2of2(NULL, &local_sig, &remote_sig,
|
||||||
&funding_localkey, &funding_remotekey);
|
&funding_localkey, &funding_remotekey);
|
||||||
bitcoin_tx_input_set_witness(local_txs[0], 0, witness);
|
bitcoin_tx_input_set_witness(local_txs[0], 0, take(witness));
|
||||||
|
|
||||||
printf("# signed local commitment: %s\n",
|
printf("# signed local commitment: %s\n",
|
||||||
tal_hex(NULL, linearize_tx(NULL, local_txs[0])));
|
tal_hex(NULL, linearize_tx(NULL, local_txs[0])));
|
||||||
|
@ -1457,7 +1457,7 @@ static void sign_all_inputs(struct bitcoin_tx *tx, struct utxo **utxos)
|
|||||||
|
|
||||||
/* The witness is [sig] [key] */
|
/* The witness is [sig] [key] */
|
||||||
bitcoin_tx_input_set_witness(
|
bitcoin_tx_input_set_witness(
|
||||||
tx, i, bitcoin_witness_p2wpkh(tx, &sig, &inkey));
|
tx, i, take(bitcoin_witness_p2wpkh(tx, &sig, &inkey)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ static void sign_last_tx(struct channel *channel)
|
|||||||
&sig, &channel->channel_info.remote_fundingkey,
|
&sig, &channel->channel_info.remote_fundingkey,
|
||||||
&channel->local_funding_pubkey);
|
&channel->local_funding_pubkey);
|
||||||
|
|
||||||
bitcoin_tx_input_set_witness(channel->last_tx, 0, witness);
|
bitcoin_tx_input_set_witness(channel->last_tx, 0, take(witness));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remove_sig(struct bitcoin_tx *signed_tx)
|
static void remove_sig(struct bitcoin_tx *signed_tx)
|
||||||
|
@ -368,7 +368,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
|
|||||||
|
|
||||||
witness = bitcoin_witness_sig_and_element(tx, &sig, elem,
|
witness = bitcoin_witness_sig_and_element(tx, &sig, elem,
|
||||||
elemsize, wscript);
|
elemsize, wscript);
|
||||||
bitcoin_tx_input_set_witness(tx, 0, witness);
|
bitcoin_tx_input_set_witness(tx, 0, take(witness));
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1277,7 +1277,7 @@ static void handle_preimage(const struct chainparams *chainparams,
|
|||||||
witness = bitcoin_witness_htlc_success_tx(
|
witness = bitcoin_witness_htlc_success_tx(
|
||||||
tx, &sig, outs[i]->remote_htlc_sig, preimage,
|
tx, &sig, outs[i]->remote_htlc_sig, preimage,
|
||||||
outs[i]->wscript);
|
outs[i]->wscript);
|
||||||
bitcoin_tx_input_set_witness(tx, 0, witness);
|
bitcoin_tx_input_set_witness(tx, 0, take(witness));
|
||||||
propose_resolution(outs[i], tx, 0, OUR_HTLC_SUCCESS_TX);
|
propose_resolution(outs[i], tx, 0, OUR_HTLC_SUCCESS_TX);
|
||||||
} else {
|
} else {
|
||||||
enum tx_type tx_type = THEIR_HTLC_FULFILL_TO_US;
|
enum tx_type tx_type = THEIR_HTLC_FULFILL_TO_US;
|
||||||
@ -1530,7 +1530,7 @@ static size_t resolve_our_htlc_ourcommit(const struct chainparams *chainparams,
|
|||||||
out->remote_htlc_sig,
|
out->remote_htlc_sig,
|
||||||
htlc_scripts[matches[i]]);
|
htlc_scripts[matches[i]]);
|
||||||
|
|
||||||
bitcoin_tx_input_set_witness(tx, 0, witness);
|
bitcoin_tx_input_set_witness(tx, 0, take(witness));
|
||||||
|
|
||||||
/* Steals tx onto out */
|
/* Steals tx onto out */
|
||||||
propose_resolution_at_block(out, tx, htlcs[matches[i]].cltv_expiry,
|
propose_resolution_at_block(out, tx, htlcs[matches[i]].cltv_expiry,
|
||||||
|
Loading…
Reference in New Issue
Block a user