From 3f59e31248cc871d266f402cb52e71102f799551 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 6 May 2019 15:02:35 -0700 Subject: [PATCH] routing/router: break rescans on router quit This commit reevaluates the router's quit channel between each block during the initial call to syncGraphWithChain, which, in the worst case, may have to scan several thousand blocks on startup if the node has not been active for some time. Without this, attempting to stop the daemon will not exit until the rescan has completed, which for certain backends could be several hours. --- routing/router.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/routing/router.go b/routing/router.go index de393212..96f503ab 100644 --- a/routing/router.go +++ b/routing/router.go @@ -584,6 +584,15 @@ func (r *ChannelRouter) syncGraphWithChain() error { // consumed by the channel graph. var numChansClosed uint32 for nextHeight := pruneHeight + 1; nextHeight <= uint32(bestHeight); nextHeight++ { + // Break out of the rescan early if a shutdown has been + // requested, otherwise long rescans will block the daemon from + // shutting down promptly. + select { + case <-r.quit: + return ErrRouterShuttingDown + default: + } + // Using the next height, request a manual block pruning from // the chainview for the particular block hash. nextHash, err := r.cfg.Chain.GetBlockHash(int64(nextHeight))