Skip to content

Commit 0c28c7b

Browse files
rustyrussellcdecker
authored andcommitted
channeld: htlcmap is never NULL.
I audited the callers. So remove the code which tested this. Signed-off-by: Rusty Russell <[email protected]>
1 parent ad2519a commit 0c28c7b

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

channeld/commit_tx.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
158158
tx = bitcoin_tx(ctx, 1, untrimmed + 2);
159159

160160
/* We keep track of which outputs have which HTLCs */
161-
if (htlcmap)
162-
*htlcmap = tal_arr(tx, const struct htlc *,
163-
tal_count(tx->output));
161+
*htlcmap = tal_arr(tx, const struct htlc *, tal_count(tx->output));
164162

165163
/* This could be done in a single loop, but we follow the BOLT
166164
* literally to make comments in test vectors clearer. */
@@ -177,8 +175,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
177175
if (trim(htlcs[i], feerate_per_kw, dust_limit_satoshis, side))
178176
continue;
179177
add_offered_htlc_out(tx, n, htlcs[i], keyset);
180-
if (htlcmap)
181-
(*htlcmap)[n++] = htlcs[i];
178+
(*htlcmap)[n] = htlcs[i];
179+
n++;
182180
}
183181

184182
/* BOLT #3:
@@ -192,8 +190,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
192190
if (trim(htlcs[i], feerate_per_kw, dust_limit_satoshis, side))
193191
continue;
194192
add_received_htlc_out(tx, n, htlcs[i], keyset);
195-
if (htlcmap)
196-
(*htlcmap)[n++] = htlcs[i];
193+
(*htlcmap)[n] = htlcs[i];
194+
n++;
197195
}
198196

199197
/* BOLT #3:
@@ -206,8 +204,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
206204
u8 *wscript = to_self_wscript(tmpctx, to_self_delay,keyset);
207205
tx->output[n].amount = self_pay_msat / 1000;
208206
tx->output[n].script = scriptpubkey_p2wsh(tx, wscript);
209-
if (htlcmap)
210-
(*htlcmap)[n] = NULL;
207+
(*htlcmap)[n] = NULL;
211208
SUPERVERBOSE("# to-local amount %"PRIu64" wscript %s\n",
212209
tx->output[n].amount,
213210
tal_hex(tmpctx, wscript));
@@ -231,8 +228,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
231228
tx->output[n].amount = other_pay_msat / 1000;
232229
tx->output[n].script = scriptpubkey_p2wpkh(tx,
233230
&keyset->other_payment_key);
234-
if (htlcmap)
235-
(*htlcmap)[n] = NULL;
231+
(*htlcmap)[n] = NULL;
236232
SUPERVERBOSE("# to-remote amount %"PRIu64" P2WPKH(%s)\n",
237233
tx->output[n].amount,
238234
type_to_string(tmpctx, struct pubkey,
@@ -242,16 +238,15 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
242238

243239
assert(n <= tal_count(tx->output));
244240
tal_resize(&tx->output, n);
245-
if (htlcmap)
246-
tal_resize(htlcmap, n);
241+
tal_resize(htlcmap, n);
247242

248243
/* BOLT #3:
249244
*
250245
* 7. Sort the outputs into [BIP 69
251246
* order](#transaction-input-and-output-ordering)
252247
*/
253248
permute_outputs(tx->output, tal_count(tx->output),
254-
htlcmap ? (const void **)*htlcmap : NULL);
249+
(const void **)*htlcmap);
255250

256251
/* BOLT #3:
257252
*

channeld/commit_tx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
3333
* @self_pay_msat: amount to pay directly to self
3434
* @other_pay_msat: amount to pay directly to the other side
3535
* @htlcs: tal_arr of htlcs committed by transaction (some may be trimmed)
36-
* @htlc_map: outputed map of outnum->HTLC (NULL for direct outputs), or NULL.
36+
* @htlc_map: outputed map of outnum->HTLC (NULL for direct outputs).
3737
* @obscured_commitment_number: number to encode in commitment transaction
3838
* @side: side to generate commitment transaction for.
3939
*

0 commit comments

Comments
 (0)