Skip to content

polygon/sync: Fix onMilestoneEvent crash - #11568

Merged
taratorio merged 2 commits into
mainfrom
shohamc1/fix-milestone-verify-crash
Aug 12, 2024
Merged

polygon/sync: Fix onMilestoneEvent crash#11568
taratorio merged 2 commits into
mainfrom
shohamc1/fix-milestone-verify-crash

Conversation

@shohamc1

Copy link
Copy Markdown
Contributor

Crash was due to a missing early return.

@taratorio

Copy link
Copy Markdown
Member

@shohamc1 please attach more info to the PR - ie the error message in this case. This is good if we have to retrospectively go back via PRs to figure out why some changes were made etc.

Comment thread polygon/sync/sync.go Outdated
Comment thread polygon/sync/sync.go Outdated
@taratorio
taratorio enabled auto-merge (squash) August 12, 2024 11:38
@taratorio
taratorio merged commit 25da9ed into main Aug 12, 2024
@taratorio
taratorio deleted the shohamc1/fix-milestone-verify-crash branch August 12, 2024 12:14
Comment thread polygon/sync/sync.go
}
if newTip == nil {
return errors.New("sync.Sync.onMilestoneEvent: unexpected to have no milestone headers since the last milestone after receiving a new milestone event")
return errors.New("sync.Sync.handleMilestoneMismatch: unexpected to have no milestone headers since the last milestone after receiving a new milestone event")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe it would make sense to log the new milestone event here for debugging purposes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree, does not hurt to log, or wrap the error in a new error with extra info using fmt.Errorf("%w: id=%d, start=%d, end=%d", errors.New("...existing err..."), milestone.Id, milestone.Start, milestone.End, ....other info....). Happy with either if you want to do it in a follow up.

Comment thread polygon/sync/sync.go
return nil
}

func (s *Sync) onMilestoneEvent(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The function name onMilestoneEvent does not give any description about what the function does, nor does it seem to accept any function handler. Maybe it's better to rename it something like checkMilestoneEvent or verifyMilestoneEvent .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree. I'm also not a fan of the onXYZ naming here. Some suggestions:

  • applyMilestone - it verifies milestone matches tip & prunes canonical chain builder root if we match the milestone or it unwinds our tip if we don't match the milestone
  • applyNewBlock - tries to connect blocks, fill gaps, update fork choice if tip changed
  • applyNewBlockHashes - same as above but using block hashes event

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably a good follow up to do if you want @antonis19

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

applyMilestoneOnTip, applyNewBlockOnTip, applyNewBlockHashesOnTip - if we want to be extra verbose (maybe not needed as it is clear? I don't mind either)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(feel free to think of better names based on the descriptions above)

taratorio added a commit that referenced this pull request Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants