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

polygon/sync: fix parent td missing when forking at the tip #11867

Merged
merged 5 commits into from
Sep 4, 2024

Conversation

taratorio
Copy link
Member

@taratorio taratorio commented Sep 4, 2024

fixes #11818

issue was:

  • when at tip we receive new block hashes and new block events
  • we had an if statement which checked if the canonical chain builder tip changed after connecting new headers to the tree
  • that if statement was used to determine whether we should call InsertBlocks for the blocks we've just connected and also to commitExecution (call UpdateForkChoice)
  • this meant that when at the tip, we would not insert new blocks which would not change the tip of the canonical chain builder
  • this is wrong because we should be inserting these blocks as they may end up being on the canonical path several blocks later in case the forks change in their favour based on the connected ancestors

fix is:

  • augment canonicalChainBuilder.Connect to return the newly connected headers to the tree
  • always insert newly connected headers (upon successful connection to the root)

@taratorio taratorio enabled auto-merge (squash) September 4, 2024 15:15
newHeaders[i] = block.HeaderNoCopy()
headerChain := make([]*types.Header, len(blockChain))
for i, block := range blockChain {
block.Hash()
Copy link
Member

Choose a reason for hiding this comment

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

Why is block.Hash() called here?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, I accidentally left it over after debugging

if err := s.store.InsertBlocks(ctx, newBlocks); err != nil {
return err
}
// len(blockChain) is always <= len(newConnectedHeaders)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it the other way around?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, good catch, corrected

@taratorio taratorio disabled auto-merge September 4, 2024 15:20
@taratorio taratorio enabled auto-merge (squash) September 4, 2024 15:22
@taratorio taratorio merged commit ed2f5f8 into main Sep 4, 2024
10 checks passed
@taratorio taratorio deleted the astrid-parent-td-err-fix branch September 4, 2024 15:49
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.

astrid stage - parent's total difficulty not found
3 participants