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

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Aug 24, 2021

What type of PR is this?

Bug Fix

What does this PR do? Why is it needed?

  • If a block has been previously processed, we allow the processing to occur in the event our chain head is
    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

@nisdas nisdas added the Ready For Review A pull request ready for code review label Aug 24, 2021
@nisdas nisdas requested a review from a team as a code owner August 24, 2021 04:40
@nisdas nisdas requested review from kasey, jmozah and rauljordan and removed request for a team August 24, 2021 04:40
@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #9452 (f543979) into develop (a49c0f1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head f543979 differs from pull request most recent head 37911a5. Consider uploading reports for the commit 37911a5 to get more accurate results

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

Comment on lines 307 to 308
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.

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

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() {
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

@rauljordan rauljordan added this to In review in Prysm V2.0.0 Tracking Aug 24, 2021
@rauljordan rauljordan merged commit 114a14a into develop Aug 24, 2021
@rauljordan rauljordan deleted the fixInitialSync branch August 24, 2021 15:20
@prestonvanloon prestonvanloon linked an issue Aug 24, 2021 that may be closed by this pull request
@rauljordan rauljordan moved this from In review to Done in Prysm V2.0.0 Tracking Aug 24, 2021
prestonvanloon pushed a commit that referenced this pull request Aug 27, 2021
* fix for now

* off by 1

* preston's review

(cherry picked from commit 114a14a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Can not sync pyrmont testnet
4 participants