Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch Initial Sync For Non Finalized Blocks #9452

Merged
merged 6 commits into from
Aug 24, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion beacon-chain/sync/initial-sync/round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ func (s *Service) isProcessedBlock(ctx context.Context, blk block.SignedBeaconBl
if err != nil {
return false
}
if blk.Block().Slot() <= finalizedSlot || (s.cfg.DB.HasBlock(ctx, blkRoot) || s.cfg.Chain.HasInitSyncBlock(blkRoot)) {
blockExistsInDB := s.cfg.DB.HasBlock(ctx, blkRoot) || s.cfg.Chain.HasInitSyncBlock(blkRoot)
if blk.Block().Slot() <= finalizedSlot || blockExistsInDB && s.cfg.Chain.HeadSlot() >= blk.Block().Slot() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
blockExistsInDB := s.cfg.DB.HasBlock(ctx, blkRoot) || s.cfg.Chain.HasInitSyncBlock(blkRoot)
if blk.Block().Slot() <= finalizedSlot || blockExistsInDB && s.cfg.Chain.HeadSlot() >= blk.Block().Slot() {
if blk.Block().Slot() <= finalizedSlot || (s.cfg.DB.HasBlock(ctx, blkRoot) || s.cfg.Chain.HasInitSyncBlock(blkRoot)) && s.cfg.Chain.HeadSlot() >= blk.Block().Slot() {

This is kind of a nasty long line, but blk.Block().Slot() <= finalizedSlot is true for most of initial sync. Putting this boolean first in the statement could reduce the number of db lookups.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a good candidate for a one liner comment so readers can quickly understand what this does

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious on whether we have unit test for this as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do have a unit test, which correctly failed when I had an off by 1 :) 09c3bee

return true
}
return false
Expand Down