Account for Bad Blocks in Gossip (#6726)

* add bad block cache

* terence's review

* terence's review

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Nishant Das
2020-07-27 19:57:19 +08:00
committed by GitHub
parent 3a852bc032
commit 664349e553
11 changed files with 342 additions and 10 deletions

View File

@@ -64,8 +64,31 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
span.End()
continue
}
s.pendingQueueLock.RUnlock()
inPendingQueue := s.seenPendingBlocks[bytesutil.ToBytes32(b.Block.ParentRoot)]
s.pendingQueueLock.RUnlock()
blkRoot, err := stateutil.BlockRoot(b.Block)
if err != nil {
traceutil.AnnotateError(span, err)
span.End()
return err
}
parentIsBad := s.hasBadBlock(bytesutil.ToBytes32(b.Block.ParentRoot))
blockIsBad := s.hasBadBlock(blkRoot)
// Check if parent is a bad block.
if parentIsBad || blockIsBad {
// Set block as bad if its parent block is bad too.
if parentIsBad {
s.setBadBlock(blkRoot)
}
// Remove block from queue.
s.pendingQueueLock.Lock()
delete(s.slotToPendingBlocks, slot)
delete(s.seenPendingBlocks, blkRoot)
s.pendingQueueLock.Unlock()
span.End()
continue
}
inDB := s.db.HasBlock(ctx, bytesutil.ToBytes32(b.Block.ParentRoot))
hasPeer := len(pids) != 0
@@ -108,15 +131,9 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
continue
}
blkRoot, err := stateutil.BlockRoot(b.Block)
if err != nil {
traceutil.AnnotateError(span, err)
span.End()
return err
}
if err := s.chain.ReceiveBlock(ctx, b, blkRoot); err != nil {
log.Errorf("Could not process block from slot %d: %v", b.Block.Slot, err)
s.setBadBlock(blkRoot)
traceutil.AnnotateError(span, err)
}