diff --git a/lightningd/commit_tx.c b/lightningd/commit_tx.c index 7f8358466..5cf5dde2c 100644 --- a/lightningd/commit_tx.c +++ b/lightningd/commit_tx.c @@ -232,7 +232,9 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, tx = bitcoin_tx(ctx, 1, untrimmed + 2); /* We keep track of which outputs have which HTLCs */ - *htlcmap = tal_arr(tx, const struct htlc *, tal_count(tx->output)); + if (htlcmap) + *htlcmap = tal_arr(tx, const struct htlc *, + tal_count(tx->output)); /* This could be done in a single loop, but we follow the BOLT * literally to make comments in test vectors clearer. */ @@ -249,7 +251,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, if (trim(htlcs[i], feerate_per_kw, dust_limit_satoshis, side)) continue; add_offered_htlc_out(tx, n, htlcs[i], selfkey, otherkey); - (*htlcmap)[n++] = htlcs[i]; + if (htlcmap) + (*htlcmap)[n++] = htlcs[i]; } /* BOLT #3: @@ -263,7 +266,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, if (trim(htlcs[i], feerate_per_kw, dust_limit_satoshis, side)) continue; add_received_htlc_out(tx, n, htlcs[i],selfkey, otherkey); - (*htlcmap)[n++] = htlcs[i]; + if (htlcmap) + (*htlcmap)[n++] = htlcs[i]; } /* BOLT #3: @@ -279,7 +283,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, self_delayedkey); tx->output[n].amount = self_pay_msat / 1000; tx->output[n].script = scriptpubkey_p2wsh(tx, wscript); - (*htlcmap)[n] = NULL; + if (htlcmap) + (*htlcmap)[n] = NULL; SUPERVERBOSE("# to-local amount %"PRIu64" wscript %s\n", tx->output[n].amount, tal_hex(tmpctx, wscript)); @@ -302,7 +307,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, */ tx->output[n].amount = other_pay_msat / 1000; tx->output[n].script = scriptpubkey_p2wpkh(tx, otherkey); - (*htlcmap)[n] = NULL; + if (htlcmap) + (*htlcmap)[n] = NULL; SUPERVERBOSE("# to-remote amount %"PRIu64" P2WPKH(%s)\n", tx->output[n].amount, type_to_string(tmpctx, struct pubkey, otherkey)); @@ -311,7 +317,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, assert(n <= tal_count(tx->output)); tal_resize(&tx->output, n); - tal_resize(htlcmap, n); + if (htlcmap) + tal_resize(htlcmap, n); /* BOLT #3: * @@ -319,7 +326,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * order](#transaction-input-and-output-ordering) */ permute_outputs(tx->output, tal_count(tx->output), - (const void **)*htlcmap); + htlcmap ? (const void **)*htlcmap : NULL); /* BOLT #3: * diff --git a/lightningd/commit_tx.h b/lightningd/commit_tx.h index 2473c1db8..1e874264e 100644 --- a/lightningd/commit_tx.h +++ b/lightningd/commit_tx.h @@ -51,7 +51,7 @@ u64 commit_tx_base_fee(u64 feerate_per_kw, size_t num_untrimmed_htlcs); * @self_pay_msat: amount to pay directly to self * @other_pay_msat: amount to pay directly to the other side * @htlcs: tal_arr of htlcs committed by transaction (some may be trimmed) - * @htlc_map: outputed map of outnum->HTLC (NULL for direct outputs). + * @htlc_map: outputed map of outnum->HTLC (NULL for direct outputs), or NULL. * @obscured_commitment_number: number to encode in commitment transaction * @side: side to generate commitment transaction for. *