This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fixed sync skipping some block announcements #8459
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -505,9 +505,10 @@ impl<B: BlockT> ChainSync<B> { | |
| } | ||
| } | ||
|
|
||
| /// Number of active sync requests. | ||
| /// Number of active forks requests. This includes | ||
| /// requests that are pending or could be issued right away. | ||
| pub fn num_sync_requests(&self) -> usize { | ||
| self.fork_targets.len() | ||
| self.fork_targets.values().filter(|f| f.number <= self.best_queued_number).count() | ||
| } | ||
|
|
||
| /// Number of downloaded blocks. | ||
|
|
@@ -1421,23 +1422,36 @@ impl<B: BlockT> ChainSync<B> { | |
| &mut self, | ||
| pre_validation_result: PreValidateBlockAnnounce<B::Header>, | ||
| ) -> PollBlockAnnounceValidation<B::Header> { | ||
| trace!( | ||
| target: "sync", | ||
| "Finished block announce validation: {:?}", | ||
| pre_validation_result, | ||
| ); | ||
|
|
||
| let (announce, is_best, who) = match pre_validation_result { | ||
| PreValidateBlockAnnounce::Failure { who, disconnect } => { | ||
| debug!( | ||
| target: "sync", | ||
| "Failed announce validation: {:?}, disconnect: {}", | ||
| who, | ||
| disconnect, | ||
| ); | ||
| return PollBlockAnnounceValidation::Failure { who, disconnect } | ||
| }, | ||
| PreValidateBlockAnnounce::Process { announce, is_new_best, who } => { | ||
| (announce, is_new_best, who) | ||
| }, | ||
| PreValidateBlockAnnounce::Error { .. } | PreValidateBlockAnnounce::Skip => | ||
| return PollBlockAnnounceValidation::Skip, | ||
| PreValidateBlockAnnounce::Error { .. } | PreValidateBlockAnnounce::Skip => { | ||
| debug!( | ||
| target: "sync", | ||
| "Ignored announce validation", | ||
| ); | ||
| return PollBlockAnnounceValidation::Skip | ||
| }, | ||
| }; | ||
|
|
||
| trace!( | ||
| target: "sync", | ||
| "Finished block announce validation: from {:?}: {:?}. local_best={}", | ||
| who, | ||
| announce.summary(), | ||
| is_best, | ||
| ); | ||
|
|
||
| let number = *announce.header.number(); | ||
| let hash = announce.header.hash(); | ||
| let parent_status = self.block_status(announce.header.parent_hash()).unwrap_or(BlockStatus::Unknown); | ||
|
|
@@ -1508,25 +1522,22 @@ impl<B: BlockT> ChainSync<B> { | |
| return PollBlockAnnounceValidation::ImportHeader { is_best, announce, who } | ||
| } | ||
|
|
||
| if number <= self.best_queued_number { | ||
| trace!( | ||
| target: "sync", | ||
| "Added sync target for block announced from {}: {} {:?}", | ||
| who, | ||
| hash, | ||
| announce.header, | ||
| ); | ||
| self.fork_targets | ||
| .entry(hash.clone()) | ||
| .or_insert_with(|| ForkTarget { | ||
| number, | ||
| parent_hash: Some(*announce.header.parent_hash()), | ||
| peers: Default::default(), | ||
| }) | ||
| .peers.insert(who.clone()); | ||
| } | ||
| trace!( | ||
| target: "sync", | ||
| "Added sync target for block announced from {}: {} {:?}", | ||
| who, | ||
| hash, | ||
| announce.summary(), | ||
| ); | ||
| self.fork_targets | ||
|
Member
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. So, the problem was that we only synced forks if the block number was below our best number?
Member
Author
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. If the block was below best, sync assumed it will be downloaded by simply advancing from peers common number. |
||
| .entry(hash.clone()) | ||
| .or_insert_with(|| ForkTarget { | ||
| number, | ||
| parent_hash: Some(*announce.header.parent_hash()), | ||
| peers: Default::default(), | ||
| }) | ||
| .peers.insert(who.clone()); | ||
|
|
||
| trace!(target: "sync", "Announce validation result is nothing"); | ||
| PollBlockAnnounceValidation::Nothing { is_best, who, announce } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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
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 do we need to filter 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.
This function is used in tests to detect when there's no activity (
block_unti_idle). Since nowfork_targetsmight contain some future blocks, that are not requested until we reach that block number it will stall tests. Basically only forks that can be requested are considered as active.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.
Ahh okay, ty. Maybe we should add some comment to the function to explain this :D