From a58809597e49b12750491dbee45bb27b6c87664f Mon Sep 17 00:00:00 2001 From: terencechain Date: Thu, 9 Jun 2022 22:02:47 -0700 Subject: [PATCH] Sync: don't process pending blocks w/o genesis time (#10750) * Sync: don't process pending blocks w/o genesis time * Update pending_blocks_queue.go Co-authored-by: Raul Jordan --- beacon-chain/sync/pending_blocks_queue.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/beacon-chain/sync/pending_blocks_queue.go b/beacon-chain/sync/pending_blocks_queue.go index f6d1e18a9..a70dcea26 100644 --- a/beacon-chain/sync/pending_blocks_queue.go +++ b/beacon-chain/sync/pending_blocks_queue.go @@ -36,6 +36,10 @@ func (s *Service) processPendingBlocksQueue() { // Prevents multiple queue processing goroutines (invoked by RunEvery) from contending for data. locker := new(sync.Mutex) async.RunEvery(s.ctx, processPendingBlocksPeriod, func() { + // Don't process the pending blocks if genesis time has not been set. The chain is not ready. + if !s.isGenesisTimeSet() { + return + } locker.Lock() if err := s.processPendingBlocks(s.ctx); err != nil { log.WithError(err).Debug("Could not process pending blocks") @@ -410,6 +414,12 @@ func (s *Service) addPendingBlockToCache(b interfaces.SignedBeaconBlock) error { return nil } +// Returns true if the genesis time has been set in chain service. +// Without the genesis time, the chain does not start. +func (s *Service) isGenesisTimeSet() bool { + return s.cfg.chain.GenesisTime().Unix() != 0 +} + // This converts input string to slot. func cacheKeyToSlot(s string) types.Slot { b := []byte(s)