From c05bc7c8abca2975b8e7dfd0051b67102d3c2c7b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 2 Aug 2018 16:19:55 +0930 Subject: [PATCH] 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 --- lightningd/lightningd.c | 15 ++++++++++----- lightningd/opening_control.c | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 3128fb6a5..1c2a981a7 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -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); } diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index d59e7cb95..85c0d9db9 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -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);