Increase number of requested block bodies in chain sync (#10247)
* Increase the number of block bodies requested during Sync. * Increase the number of block bodies requested during Sync. * Check if our peer is an older parity client with the bug of not handling large requests properly * Add a ClientVersion struct and a ClientCapabilites trait * Make ClientVersion its own module * Refactor and extend use of ClientVersion * Replace strings with ClientVersion in PeerInfo * Group further functionality in ClientCapabilities * Move parity client version data from tuple to its own struct. * Implement accessor methods for ParityClientData and remove them from ClientVersion. * Minor fixes * Make functions specific to parity return types specific to parity. * Test for shorter ID strings * Fix formatting and remove unneeded dependencies. * Roll back Cargo.lock * Commit last Cargo.lock * Convert from string to ClientVersion * * When checking if peer accepts service transactions just check if it's parity, remove version check. * Remove dependency on semver in ethcore-sync * Remove unnecessary String instantiation * Rename peer_info to peer_version * Update RPC test helpers * Simplify From<String> * Parse static version string only once * Update RPC tests to new ClientVersion struct * Document public members * More robust parsing of ID string * Minor changes. * Update version in which large block bodies requests appear. * Update ethcore/sync/src/block_sync.rs Co-Authored-By: elferdo <elferdo@gmail.com> * Update util/network/src/client_version.rs Co-Authored-By: elferdo <elferdo@gmail.com> * Update util/network/src/client_version.rs Co-Authored-By: elferdo <elferdo@gmail.com> * Update tests. * Minor fixes.
This commit is contained in:
@@ -29,10 +29,13 @@ use ethcore::error::{ImportErrorKind, QueueErrorKind, BlockError, Error as Ethco
|
||||
use sync_io::SyncIo;
|
||||
use blocks::{BlockCollection, SyncBody, SyncHeader};
|
||||
use chain::BlockSet;
|
||||
use network::PeerId;
|
||||
use network::client_version::ClientCapabilities;
|
||||
|
||||
const MAX_HEADERS_TO_REQUEST: usize = 128;
|
||||
const MAX_BODIES_TO_REQUEST: usize = 32;
|
||||
const MAX_RECEPITS_TO_REQUEST: usize = 128;
|
||||
const MAX_BODIES_TO_REQUEST_LARGE: usize = 128;
|
||||
const MAX_BODIES_TO_REQUEST_SMALL: usize = 32; // Size request for parity clients prior to 2.4.0
|
||||
const MAX_RECEPITS_TO_REQUEST: usize = 256;
|
||||
const SUBCHAIN_SIZE: u64 = 256;
|
||||
const MAX_ROUND_PARENTS: usize = 16;
|
||||
const MAX_PARALLEL_SUBCHAIN_DOWNLOAD: usize = 5;
|
||||
@@ -464,12 +467,12 @@ impl BlockDownloader {
|
||||
}
|
||||
|
||||
/// Find some headers or blocks to download for a peer.
|
||||
pub fn request_blocks(&mut self, io: &mut SyncIo, num_active_peers: usize) -> Option<BlockRequest> {
|
||||
pub fn request_blocks(&mut self, peer_id: PeerId, io: &mut SyncIo, num_active_peers: usize) -> Option<BlockRequest> {
|
||||
match self.state {
|
||||
State::Idle => {
|
||||
self.start_sync_round(io);
|
||||
if self.state == State::ChainHead {
|
||||
return self.request_blocks(io, num_active_peers);
|
||||
return self.request_blocks(peer_id, io, num_active_peers);
|
||||
}
|
||||
},
|
||||
State::ChainHead => {
|
||||
@@ -487,7 +490,15 @@ impl BlockDownloader {
|
||||
},
|
||||
State::Blocks => {
|
||||
// check to see if we need to download any block bodies first
|
||||
let needed_bodies = self.blocks.needed_bodies(MAX_BODIES_TO_REQUEST, false);
|
||||
let client_version = io.peer_version(peer_id);
|
||||
|
||||
let number_of_bodies_to_request = if client_version.can_handle_large_requests() {
|
||||
MAX_BODIES_TO_REQUEST_LARGE
|
||||
} else {
|
||||
MAX_BODIES_TO_REQUEST_SMALL
|
||||
};
|
||||
|
||||
let needed_bodies = self.blocks.needed_bodies(number_of_bodies_to_request, false);
|
||||
if !needed_bodies.is_empty() {
|
||||
return Some(BlockRequest::Bodies {
|
||||
hashes: needed_bodies,
|
||||
|
||||
Reference in New Issue
Block a user