diff --git a/substrate/client/network/src/protocol.rs b/substrate/client/network/src/protocol.rs index 23fd944678df78b90a69163e6494977e1877cace..895624f08de6ae56d57615604388d52708f4c200 100644 --- a/substrate/client/network/src/protocol.rs +++ b/substrate/client/network/src/protocol.rs @@ -751,7 +751,7 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> { None }; let block_data = message::generic::BlockData { - hash: hash, + hash, header: if get_header { Some(header) } else { None }, body: if get_body { self.context_data @@ -783,7 +783,7 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> { } let response = message::generic::BlockResponse { id: request.id, - blocks: blocks, + blocks, }; trace!(target: "sync", "Sending BlockResponse with {} blocks", response.blocks.len()); self.send_message(&peer, None, GenericMessage::BlockResponse(response)) diff --git a/substrate/client/network/src/protocol/sync.rs b/substrate/client/network/src/protocol/sync.rs index 4e9347001d9b3fcc920a50d0f71838a8a403d4c7..37af47011d548076854ba992457b52ae3bb104da 100644 --- a/substrate/client/network/src/protocol/sync.rs +++ b/substrate/client/network/src/protocol/sync.rs @@ -536,20 +536,25 @@ impl<B: BlockT> ChainSync<B> { /// Request syncing for the given block from given set of peers. // The implementation is similar to on_block_announce with unknown parent hash. - pub fn set_sync_fork_request(&mut self, mut peers: Vec<PeerId>, hash: &B::Hash, number: NumberFor<B>) { + pub fn set_sync_fork_request( + &mut self, + mut peers: Vec<PeerId>, + hash: &B::Hash, + number: NumberFor<B>, + ) { if peers.is_empty() { - debug!( - target: "sync", - "Explicit sync request for block {:?} with no peers specified. \ - Syncing from all connected peers {:?} instead.", - hash, peers, - ); - peers = self.peers.iter() // Only request blocks from peers who are ahead or on a par. .filter(|(_, peer)| peer.best_number >= number) .map(|(id, _)| id.clone()) .collect(); + + debug!( + target: "sync", + "Explicit sync request for block {:?} with no peers specified. \ + Syncing from these peers {:?} instead.", + hash, peers, + ); } else { debug!(target: "sync", "Explicit sync request for block {:?} with {:?}", hash, peers); } @@ -653,12 +658,10 @@ impl<B: BlockT> ChainSync<B> { let pending_requests = self.pending_requests.take(); let max_parallel = if major_sync { 1 } else { self.max_parallel_downloads }; let iter = self.peers.iter_mut().filter_map(move |(id, peer)| { - if !peer.state.is_available() { - return None - } - if !pending_requests.contains(id) { + if !peer.state.is_available() || !pending_requests.contains(id) { return None } + if let Some((range, req)) = peer_block_request( id, peer,