lightningd: don't try to delete peer from db on shutdown if it's opening.

Fortunately, we hit the assert in wallet_peer_delete() if this happens,
since there are still active channels.

This latent bug becomes far more likely in followup patches, where
openingd is used for idle peers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-08-02 16:19:55 +09:30
parent 8bffd2b604
commit c05bc7c8ab
2 changed files with 14 additions and 5 deletions

View file

@ -224,11 +224,16 @@ static void shutdown_subdaemons(struct lightningd *ld)
}
/* Freeing uncommitted channel will free peer. */
if (p->uncommitted_channel)
tal_free(p->uncommitted_channel);
else
/* Removes itself from list as we free it */
tal_free(p);
if (p->uncommitted_channel) {
struct uncommitted_channel *uc = p->uncommitted_channel;
/* Setting to NULL stops destroy_uncommitted_channel
* from trying to remove peer from db! */
p->uncommitted_channel = NULL;
tal_free(uc);
}
/* Removes itself from list as we free it */
tal_free(p);
}
db_commit_transaction(ld->wallet->db);
}

View file

@ -584,6 +584,10 @@ static void destroy_uncommitted_channel(struct uncommitted_channel *uc)
subd_release_channel(openingd, uc);
}
/* This is how shutdown_subdaemons tells us not to delete from db! */
if (!uc->peer->uncommitted_channel)
return;
uc->peer->uncommitted_channel = NULL;
maybe_delete_peer(uc->peer);