Skip to content

Commit 960bfb8

Browse files
committed
lightningd: don't crash on old zero-output commitment_txs.
We used to produce these, but they're invalid. When we switched to libwally it (correctly) refuses to get a txid for them. Fixes: #2772 Fixes: #2759 Signed-off-by: Rusty Russell <[email protected]>
1 parent c1328b3 commit 960bfb8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lightningd/peer_control.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,18 @@ register_close_command(struct lightningd *ld,
340340
&close_command_timeout, cc);
341341
}
342342

343+
static bool invalid_last_tx(const struct bitcoin_tx *tx)
344+
{
345+
/* This problem goes back further, but was discovered just before the
346+
* 0.7.1 release. */
347+
#ifdef COMPAT_V070
348+
/* Old bug had commitment txs with no outputs; bitcoin_txid asserts. */
349+
return tx->wtx->num_outputs == 0;
350+
#else
351+
return false;
352+
#endif
353+
}
354+
343355
void drop_to_chain(struct lightningd *ld, struct channel *channel,
344356
bool cooperative)
345357
{
@@ -355,6 +367,10 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel,
355367
log_broken(channel->log,
356368
"Cannot broadcast our commitment tx:"
357369
" they have a future one");
370+
} else if (invalid_last_tx(channel->last_tx)) {
371+
log_broken(channel->log,
372+
"Cannot broadcast our commitment tx:"
373+
" it's invalid! (ancient channel?)");
358374
} else {
359375
sign_last_tx(channel);
360376
bitcoin_txid(channel->last_tx, &txid);
@@ -568,7 +584,7 @@ static void json_add_channel(struct lightningd *ld,
568584

569585
json_object_start(response, key);
570586
json_add_string(response, "state", channel_state_name(channel));
571-
if (channel->last_tx) {
587+
if (channel->last_tx && !invalid_last_tx(channel->last_tx)) {
572588
struct bitcoin_txid txid;
573589
bitcoin_txid(channel->last_tx, &txid);
574590

0 commit comments

Comments
 (0)