Browse Source

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 <rusty@rustcorp.com.au>
pull/2938/head
Rusty Russell 6 years ago
parent
commit
960bfb89f5
  1. 18
      lightningd/peer_control.c

18
lightningd/peer_control.c

@ -340,6 +340,18 @@ register_close_command(struct lightningd *ld,
&close_command_timeout, cc);
}
static bool invalid_last_tx(const struct bitcoin_tx *tx)
{
/* This problem goes back further, but was discovered just before the
* 0.7.1 release. */
#ifdef COMPAT_V070
/* Old bug had commitment txs with no outputs; bitcoin_txid asserts. */
return tx->wtx->num_outputs == 0;
#else
return false;
#endif
}
void drop_to_chain(struct lightningd *ld, struct channel *channel,
bool cooperative)
{
@ -355,6 +367,10 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel,
log_broken(channel->log,
"Cannot broadcast our commitment tx:"
" they have a future one");
} else if (invalid_last_tx(channel->last_tx)) {
log_broken(channel->log,
"Cannot broadcast our commitment tx:"
" it's invalid! (ancient channel?)");
} else {
sign_last_tx(channel);
bitcoin_txid(channel->last_tx, &txid);
@ -568,7 +584,7 @@ static void json_add_channel(struct lightningd *ld,
json_object_start(response, key);
json_add_string(response, "state", channel_state_name(channel));
if (channel->last_tx) {
if (channel->last_tx && !invalid_last_tx(channel->last_tx)) {
struct bitcoin_txid txid;
bitcoin_txid(channel->last_tx, &txid);

Loading…
Cancel
Save