elements: Fix missing witness script entry for fee outputs

Fixes #3487
This commit is contained in:
Christian Decker 2020-02-07 14:55:46 +01:00
parent de5eaf2238
commit 9521549c49
3 changed files with 7 additions and 3 deletions

View file

@ -102,6 +102,7 @@ int elements_tx_add_fee_output(struct bitcoin_tx *tx)
{
struct amount_sat fee = bitcoin_tx_compute_fee(tx);
int pos = -1;
struct witscript *w;
/* If we aren't using elements, we don't add explicit fee outputs */
if (!chainparams->is_elements || amount_sat_eq(fee, AMOUNT_SAT(0)))
@ -116,6 +117,9 @@ int elements_tx_add_fee_output(struct bitcoin_tx *tx)
}
if (pos == -1) {
w = tal(tx->output_witscripts, struct witscript);
w->ptr = tal_arr(w, u8, 0);
tx->output_witscripts[tx->wtx->num_outputs] = w;
return bitcoin_tx_add_output(tx, NULL, fee);
} else {
bitcoin_tx_output_set_amount(tx, pos, fee);

View file

@ -269,7 +269,6 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
assert(n <= tx->wtx->outputs_allocation_len);
tal_resize(htlcmap, n);
tal_resize(&(tx->output_witscripts), n);
/* BOLT #3:
*
@ -307,6 +306,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, funding, NULL);
elements_tx_add_fee_output(tx);
tal_resize(&(tx->output_witscripts), tx->wtx->num_outputs);
return tx;
}

View file

@ -207,8 +207,6 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
assert(n <= tx->wtx->num_outputs);
tal_resize(&(tx->output_witscripts), n);
/* BOLT #3:
*
* 7. Sort the outputs into [BIP 69+CLTV
@ -244,6 +242,8 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, funding, NULL);
elements_tx_add_fee_output(tx);
tal_resize(&(tx->output_witscripts), tx->wtx->num_outputs);
assert(bitcoin_tx_check(tx));
return tx;