-
Notifications
You must be signed in to change notification settings - Fork 962
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
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #9452 +/- ##
========================================
Coverage 60.93% 60.94%
========================================
Files 582 582
Lines 42928 42929 +1
========================================
+ Hits 26158 26161 +3
+ Misses 12813 12804 -9
- Partials 3957 3964 +7 |
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -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() { |
There was a problem hiding this comment.
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
@@ -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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
* fix for now * off by 1 * preston's review (cherry picked from commit 114a14a)
What type of PR is this?
Bug Fix
What does this PR do? Why is it needed?
behind. Validation of responses is done in the block fetcher, so it should be fine to filter it this way.
Which issues(s) does this PR fix?
N.A
Other notes for review