Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make blocks per request configurable #13824

Merged
merged 5 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ pub struct NetworkParams {
verbatim_doc_comment
)]
pub sync: SyncMode,

/// Maximum number of blocks per request.
altonen marked this conversation as resolved.
Show resolved Hide resolved
#[arg(long, value_name = "COUNT", default_value_t = 64)]
pub max_blocks_per_request: u32,
altonen marked this conversation as resolved.
Show resolved Hide resolved
}

impl NetworkParams {
Expand Down Expand Up @@ -235,6 +239,7 @@ impl NetworkParams {
allow_private_ip,
},
max_parallel_downloads: self.max_parallel_downloads,
max_blocks_per_request: self.max_blocks_per_request,
enable_dht_random_walk: !self.reserved_only,
allow_non_globals_in_dht,
kademlia_disjoint_query_paths: self.kademlia_disjoint_query_paths,
Expand Down
5 changes: 5 additions & 0 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ pub struct NetworkConfiguration {

/// List of request-response protocols that the node supports.
pub request_response_protocols: Vec<RequestResponseConfig>,

/// Configuration for the default set of nodes used for block syncing and transactions.
pub default_peers_set: SetConfig,

Expand All @@ -590,6 +591,9 @@ pub struct NetworkConfiguration {
/// Maximum number of peers to ask the same blocks in parallel.
pub max_parallel_downloads: u32,

/// Maximum number of blocks per request.
pub max_blocks_per_request: u32,

/// Initial syncing mode.
pub sync_mode: SyncMode,

Expand Down Expand Up @@ -653,6 +657,7 @@ impl NetworkConfiguration {
node_name: node_name.into(),
transport: TransportConfig::Normal { enable_mdns: false, allow_private_ip: true },
max_parallel_downloads: 5,
max_blocks_per_request: 64,
sync_mode: SyncMode::Full,
enable_dht_random_walk: true,
allow_non_globals_in_dht: false,
Expand Down
6 changes: 4 additions & 2 deletions client/network/sync/src/block_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
//! Helper for handling (i.e. answering) block requests from a remote peer via the
//! `crate::request_responses::RequestResponsesBehaviour`.

use crate::schema::v1::{block_request::FromBlock, BlockResponse, Direction};
use crate::{
schema::v1::{block_request::FromBlock, BlockResponse, Direction},
MAX_BLOCKS_IN_RESPONSE,
};

use codec::{Decode, Encode};
use futures::{
Expand Down Expand Up @@ -50,7 +53,6 @@ use std::{
};

const LOG_TARGET: &str = "sync";
const MAX_BLOCKS_IN_RESPONSE: usize = 128;
const MAX_BODY_BYTES: usize = 8 * 1024 * 1024;
const MAX_NUMBER_OF_SAME_REQUESTS_PER_PEER: usize = 2;

Expand Down
2 changes: 1 addition & 1 deletion client/network/sync/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<B: BlockT> BlockCollection<B> {
pub fn needed_blocks(
&mut self,
who: PeerId,
count: usize,
count: u32,
peer_best: NumberFor<B>,
common: NumberFor<B>,
max_parallel: u32,
Expand Down
9 changes: 9 additions & 0 deletions client/network/sync/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ where
SyncOperationMode::Warp => SyncMode::Warp,
};
let max_parallel_downloads = network_config.max_parallel_downloads;
let max_blocks_per_request = if network_config.max_blocks_per_request >
crate::MAX_BLOCKS_IN_RESPONSE as u32
{
log::info!(target: "sync", "clamping maximum blocks per request to {}", crate::MAX_BLOCKS_IN_RESPONSE);
crate::MAX_BLOCKS_IN_RESPONSE as u32
} else {
network_config.max_blocks_per_request
};
let cache_capacity = NonZeroUsize::new(
(network_config.default_peers_set.in_peers as usize +
network_config.default_peers_set.out_peers as usize)
Expand Down Expand Up @@ -318,6 +326,7 @@ where
roles,
block_announce_validator,
max_parallel_downloads,
max_blocks_per_request,
warp_sync_params,
metrics_registry,
network_service.clone(),
Expand Down
Loading