Browse Source

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>
pull/2938/head
Rusty Russell 5 years ago
parent
commit
39b34a35c8
  1. 3
      bitcoin/tx.c
  2. 2
      bitcoin/tx.h
  3. 3
      channeld/test/run-commit_tx.c
  4. 4
      common/htlc_tx.c
  5. 2
      devtools/mkcommit.c
  6. 2
      hsmd/hsmd.c
  7. 2
      lightningd/peer_control.c
  8. 6
      onchaind/onchaind.c

3
bitcoin/tx.c

@ -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);
if (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)

2
bitcoin/tx.h

@ -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.
*/
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.

3
channeld/test/run-commit_tx.c

@ -350,7 +350,7 @@ static void report(struct bitcoin_tx *tx,
witness =
bitcoin_witness_2of2(tx, &localsig, &remotesig,
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));
printf("output commit_tx: %s\n", txhex);
@ -993,6 +993,7 @@ int main(void)
/* No memory leaks please */
secp256k1_context_destroy(secp256k1_ctx);
take_cleanup();
tal_free(tmpctx);
/* FIXME: Do BOLT comparison! */

4
common/htlc_tx.c

@ -109,7 +109,7 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
witness = bitcoin_witness_htlc_success_tx(htlc_success,
localhtlcsig, remotehtlcsig,
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);
}
@ -149,7 +149,7 @@ void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout,
witness = bitcoin_witness_htlc_timeout_tx(htlc_timeout, localhtlcsig,
remotehtlcsig, wscript);
bitcoin_tx_input_set_witness(htlc_timeout, 0, witness);
bitcoin_tx_input_set_witness(htlc_timeout, 0, take(witness));
tal_free(wscript);
}

2
devtools/mkcommit.c

@ -396,7 +396,7 @@ int main(int argc, char *argv[])
witness =
bitcoin_witness_2of2(NULL, &local_sig, &remote_sig,
&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",
tal_hex(NULL, linearize_tx(NULL, local_txs[0])));

2
hsmd/hsmd.c

@ -1457,7 +1457,7 @@ static void sign_all_inputs(struct bitcoin_tx *tx, struct utxo **utxos)
/* The witness is [sig] [key] */
bitcoin_tx_input_set_witness(
tx, i, bitcoin_witness_p2wpkh(tx, &sig, &inkey));
tx, i, take(bitcoin_witness_p2wpkh(tx, &sig, &inkey)));
}
}

2
lightningd/peer_control.c

@ -224,7 +224,7 @@ static void sign_last_tx(struct channel *channel)
&sig, &channel->channel_info.remote_fundingkey,
&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)

6
onchaind/onchaind.c

@ -368,7 +368,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
witness = bitcoin_witness_sig_and_element(tx, &sig, elem,
elemsize, wscript);
bitcoin_tx_input_set_witness(tx, 0, witness);
bitcoin_tx_input_set_witness(tx, 0, take(witness));
return tx;
}
@ -1277,7 +1277,7 @@ static void handle_preimage(const struct chainparams *chainparams,
witness = bitcoin_witness_htlc_success_tx(
tx, &sig, outs[i]->remote_htlc_sig, preimage,
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);
} else {
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,
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 */
propose_resolution_at_block(out, tx, htlcs[matches[i]].cltv_expiry,

Loading…
Cancel
Save