From f9c696ed54af3ca5df8ca24044701e5b5f69e09a Mon Sep 17 00:00:00 2001 From: Shay Zluf Date: Wed, 2 Dec 2020 11:50:37 +0200 Subject: [PATCH] Pending block queue lock fixes (#8002) * Unlock in case of error * fix comment * fix comment * revert one defer Co-authored-by: terence tsao Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Nishant Das --- beacon-chain/sync/pending_blocks_queue.go | 3 ++- beacon-chain/sync/validate_beacon_blocks.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/beacon-chain/sync/pending_blocks_queue.go b/beacon-chain/sync/pending_blocks_queue.go index d61d16673..3d90882f0 100644 --- a/beacon-chain/sync/pending_blocks_queue.go +++ b/beacon-chain/sync/pending_blocks_queue.go @@ -102,6 +102,7 @@ func (s *Service) processPendingBlocks(ctx context.Context) error { // Remove block from queue. s.pendingQueueLock.Lock() if err := s.deleteBlockFromPendingQueue(slot, b, blkRoot); err != nil { + s.pendingQueueLock.Unlock() return err } s.pendingQueueLock.Unlock() @@ -311,7 +312,7 @@ func (s *Service) deleteBlockFromPendingQueue(slot uint64, b *ethpb.SignedBeacon return nil } - // Decrease exp itme in proportion to how many blocks are still in the cache for slot key. + // Decrease exp time in proportion to how many blocks are still in the cache for slot key. d := pendingBlockExpTime / time.Duration(len(newBlks)) if err := s.slotToPendingBlocks.Replace(slotToCacheKey(slot), newBlks, d); err != nil { return err diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index a78d169fb..ecf06e592 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -123,6 +123,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms if !s.db.HasBlock(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot)) { s.pendingQueueLock.Lock() if err := s.insertBlockToPendingQueue(blk.Block.Slot, blk, blockRoot); err != nil { + s.pendingQueueLock.Unlock() log.WithError(err).WithField("blockSlot", blk.Block.Slot).Debug("Ignored block") return pubsub.ValidationIgnore }