From cbfa045f91e380ea1e7ae1ba75b0371d5b906773 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Mon, 16 Sep 2019 16:58:36 -0500 Subject: [PATCH] tx: remove input size assertion this is unnecessary, and actually severely limits the functionality of `wally_tx_add_input`, which will expand the allocated input length if there's not enough room for the additional input ```external/libwally-core/src/transaction.c if (tx->num_inputs >= tx->inputs_allocation_len) { /* Expand the inputs array */ struct wally_tx_input *p; p = realloc_array(tx->inputs, tx->inputs_allocation_len, tx->num_inputs + 1, sizeof(*tx->inputs)); ... tx->inputs = p; tx->inputs_allocation_len += 1; ``` --- bitcoin/tx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 3e11a2b55..0c27e89cf 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -127,11 +127,11 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, u32 outnum, u32 sequence, struct amount_sat amount, u8 *script) { - size_t i = tx->wtx->num_inputs; struct wally_tx_input *input; - assert(i < tx->wtx->inputs_allocation_len); + size_t i; assert(tx->wtx != NULL); + i = tx->wtx->num_inputs; wally_tx_input_init_alloc(txid->shad.sha.u.u8, sizeof(struct bitcoin_txid), outnum, sequence, script, tal_bytelen(script), @@ -141,6 +141,9 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, wally_tx_input_free(input); /* Now store the input amount if we know it, so we can sign later */ + if (tal_count(tx->input_amounts) < tx->wtx->num_inputs) + tal_resize(&tx->input_amounts, tx->wtx->num_inputs); + tx->input_amounts[i] = tal_free(tx->input_amounts[i]); tx->input_amounts[i] = tal_dup(tx, struct amount_sat, &amount);