From 8000307c0e4a1233a323e7b60368a8464d629291 Mon Sep 17 00:00:00 2001 From: gop Date: Wed, 6 Sep 2023 12:00:32 -0500 Subject: [PATCH] bugfix: Fixed the deadlock and crash on append because of chainHeadSub done in Region/Prime Region and Prime subscribes to the chain head feed and never consumes it in the worker, it is solely meant to be consumed by the asyncPendingHeaderLoop --- core/slice.go | 4 +++- core/worker.go | 10 ++++------ eth/backend.go | 12 +++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/slice.go b/core/slice.go index 98e8bdd652..cbfb763803 100644 --- a/core/slice.go +++ b/core/slice.go @@ -1070,7 +1070,9 @@ func (sl *Slice) loadLastState() error { } rawdb.DeletePhCache(sl.sliceDb) sl.bestPhKey = rawdb.ReadBestPhKey(sl.sliceDb) - sl.miner.worker.LoadPendingBlockBody() + if sl.ProcessingState() { + sl.miner.worker.LoadPendingBlockBody() + } return nil } diff --git a/core/worker.go b/core/worker.go index 490f78a315..d58a4fe0a1 100644 --- a/core/worker.go +++ b/core/worker.go @@ -277,10 +277,6 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, db ethdb.Databas phBodyCache, _ := lru.New(pendingBlockBodyLimit) worker.pendingBlockBody = phBodyCache - if headerchain.ProcessingState() { - worker.chainHeadSub = worker.hc.SubscribeChainHeadEvent(worker.chainHeadCh) - } - // Sanitize recommit interval if the user-specified one is too short. recommit := worker.config.Recommit if recommit < minRecommitInterval { @@ -288,7 +284,9 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, db ethdb.Databas recommit = minRecommitInterval } - if processingState { + nodeCtx := common.NodeLocation.Context() + if headerchain.ProcessingState() && nodeCtx == common.ZONE_CTX { + worker.chainHeadSub = worker.hc.SubscribeChainHeadEvent(worker.chainHeadCh) worker.wg.Add(1) go worker.asyncStateLoop() } @@ -366,7 +364,7 @@ func (w *worker) start() { // stop sets the running status as 0. func (w *worker) stop() { - if w.hc.ProcessingState() { + if w.hc.ProcessingState() && common.NodeLocation.Context() == common.ZONE_CTX { w.chainHeadSub.Unsubscribe() } atomic.StoreInt32(&w.running, 0) diff --git a/eth/backend.go b/eth/backend.go index 50d8c2f2b1..4601b49be4 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -190,8 +190,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Quai, error) { } // Only index bloom if processing state - if eth.core.ProcessingState() { - eth.bloomIndexer = core.NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms) + if eth.core.ProcessingState() && nodeCtx == common.ZONE_CTX { + eth.bloomIndexer = core.NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms) eth.bloomIndexer.Start(eth.Core().Slice().HeaderChain()) } @@ -399,9 +399,11 @@ func (s *Quai) Stop() error { s.ethDialCandidates.Close() s.handler.Stop() - // Then stop everything else. - s.bloomIndexer.Close() - close(s.closeBloomHandler) + if s.core.ProcessingState() && common.NodeLocation.Context() == common.ZONE_CTX { + // Then stop everything else. + s.bloomIndexer.Close() + close(s.closeBloomHandler) + } s.core.Stop() s.engine.Close() rawdb.PopUncleanShutdownMarker(s.chainDb)