Pending block queue lock fixes (#8002)

* Unlock in case of error

* fix comment

* fix comment

* revert one defer

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
Shay Zluf 2020-12-02 11:50:37 +02:00 committed by GitHub
parent 3bd5e58a5c
commit f9c696ed54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -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

View File

@ -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
}