-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
20b61be
polygon/sync: fix parent td missing when forking at the tip
taratorio a0545a0
Merge branch 'main' of github.com:ledgerwatch/erigon into astrid-pare…
taratorio caca460
rename
taratorio 9d9653b
correct comment
taratorio 671ad82
correction to comment and removing unnecessary call
taratorio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,9 +175,9 @@ func (s *Sync) applyNewBlockOnTip( | |
return nil | ||
} | ||
|
||
var newBlocks []*types.Block | ||
var blockChain []*types.Block | ||
if ccBuilder.ContainsHash(newBlockHeader.ParentHash) { | ||
newBlocks = []*types.Block{event.NewBlock} | ||
blockChain = []*types.Block{event.NewBlock} | ||
} else { | ||
blocks, err := s.p2pService.FetchBlocks(ctx, rootNum, newBlockHeaderNum+1, event.PeerId) | ||
if err != nil { | ||
|
@@ -195,10 +195,10 @@ func (s *Sync) applyNewBlockOnTip( | |
return err | ||
} | ||
|
||
newBlocks = blocks.Data | ||
blockChain = blocks.Data | ||
} | ||
|
||
if err := s.blocksVerifier(newBlocks); err != nil { | ||
if err := s.blocksVerifier(blockChain); err != nil { | ||
s.logger.Debug( | ||
syncLogPrefix("applyNewBlockOnTip: invalid new block event from peer, penalizing and ignoring"), | ||
"err", err, | ||
|
@@ -211,33 +211,38 @@ func (s *Sync) applyNewBlockOnTip( | |
return nil | ||
} | ||
|
||
newHeaders := make([]*types.Header, len(newBlocks)) | ||
for i, block := range newBlocks { | ||
newHeaders[i] = block.HeaderNoCopy() | ||
headerChain := make([]*types.Header, len(blockChain)) | ||
for i, block := range blockChain { | ||
block.Hash() | ||
headerChain[i] = block.HeaderNoCopy() | ||
} | ||
|
||
oldTip := ccBuilder.Tip() | ||
if err := ccBuilder.Connect(ctx, newHeaders); err != nil { | ||
newConnectedHeaders, err := ccBuilder.Connect(ctx, headerChain) | ||
if err != nil { | ||
s.logger.Debug( | ||
syncLogPrefix("applyNewBlockOnTip: couldn't connect a header to the local chain tip, ignoring"), | ||
"err", err, | ||
) | ||
|
||
return nil | ||
} | ||
if len(newConnectedHeaders) == 0 { | ||
return nil | ||
} | ||
|
||
newTip := ccBuilder.Tip() | ||
if newTip != oldTip { | ||
if err := s.store.InsertBlocks(ctx, newBlocks); err != nil { | ||
return err | ||
} | ||
// len(blockChain) is always <= len(newConnectedHeaders) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it the other way around? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, good catch, corrected |
||
newConnectedBlocks := blockChain[len(blockChain)-len(newConnectedHeaders):] | ||
if err := s.store.InsertBlocks(ctx, newConnectedBlocks); err != nil { | ||
return err | ||
} | ||
|
||
if err := s.commitExecution(ctx, newTip, ccBuilder.Root()); err != nil { | ||
return err | ||
} | ||
newTip := ccBuilder.Tip() | ||
if newTip == oldTip { | ||
return nil | ||
} | ||
|
||
return nil | ||
return s.commitExecution(ctx, newTip, ccBuilder.Root()) | ||
} | ||
|
||
func (s *Sync) applyNewBlockHashesOnTip( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is
block.Hash()
called here?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.
good catch, I accidentally left it over after debugging