-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Explicit sync API for downloading important, possibly orphaned, forks #3633
Changes from 1 commit
42fe308
97e18d9
3815130
7bcffcd
d687a54
19673f7
34a88eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -441,6 +441,53 @@ impl<B: BlockT> ChainSync<B> { | |
| }) | ||
| } | ||
|
|
||
| /// Request syncing for the given block from given set of peers. | ||
| // This is similar to on_block_announce with unknown parent hash. | ||
| pub fn sync_fork(&mut self, peers: Vec<PeerId>, hash: &B::Hash, number: NumberFor<B>) -> | ||
| Vec<(PeerId, BlockRequest<B>)> | ||
| { | ||
| debug!(target: "sync", "Explicit sync request for block {:?} with {:?}", hash, peers); | ||
| if self.is_known(&hash) || self.is_already_downloading(&hash) { | ||
|
||
| debug!(target: "sync", "Refusing to sync known hash {:?}", hash); | ||
| return Vec::default(); | ||
| } | ||
|
|
||
| let block_status = self.client.block_status(&BlockId::Number(number - One::one())) | ||
| .unwrap_or(BlockStatus::Unknown); | ||
| if block_status == BlockStatus::InChainPruned { | ||
|
Contributor
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. As a follow-up, there should be a special mode where we just download the headers for this chain if requested, but we don't have the state to process them.
Contributor
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. #3639 for a more detailed writeup of ^ |
||
| trace!(target: "sync", "Refusing to sync ancient block {:?}", hash); | ||
| return Vec::default(); | ||
| } | ||
|
|
||
| self.is_idle = false; | ||
| let mut requests = Vec::new(); | ||
| for peer_id in peers { | ||
| let peer = if let Some(peer) = self.peers.get_mut(&peer_id) { | ||
| peer | ||
| } else { | ||
| debug!(target: "sync", "Called sync_fork with a bad peer ID"); | ||
| continue; | ||
| }; | ||
| if let PeerSyncState::AncestorSearch(_, _) = peer.state { | ||
| continue; | ||
| } | ||
|
|
||
| if number > peer.best_number { | ||
| peer.best_number = number; | ||
| peer.best_hash = hash.clone(); | ||
|
||
| } | ||
|
|
||
| if number <= self.best_queued_number { | ||
| if let Some(request) = self.download_unknown_stale(&peer_id, &hash) { | ||
| requests.push((peer_id, request)); | ||
| } | ||
| } else if let Some((_, request)) = self.select_new_blocks(peer_id.clone()) { | ||
| requests.push((peer_id, request)); | ||
| } | ||
| } | ||
| requests | ||
| } | ||
|
|
||
| /// Get an iterator over all scheduled justification requests. | ||
| pub fn justification_requests(&mut self) -> impl Iterator<Item = (PeerId, BlockRequest<B>)> + '_ { | ||
| let peers = &mut self.peers; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -497,6 +497,13 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic | |||
| Ok(()) | ||||
| } | ||||
|
|
||||
| /// Adds a `PeerId` and its address as reserved. | ||||
|
||||
| /// Adds a `PeerId` and its address as reserved. |
This is a copy/paste error from above, right?
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.
I feel like this could be a doc comment as well, right?
Uh oh!
There was an error while loading. Please reload this page.
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 comment is about the implementation detail, not the interface.