From bc70f76586df96cbd6c8ae69fbdfa45f92139dfc Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Mon, 4 Sep 2023 19:04:12 +0700 Subject: [PATCH 1/2] networking: Tune piece retrieval parameters. - default outgoing connection parameters - retry parameters --- crates/subspace-farmer/src/bin/subspace-farmer/main.rs | 4 ++-- crates/subspace-networking/src/constructor.rs | 4 ++-- crates/subspace-networking/src/utils/piece_provider.rs | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/subspace-farmer/src/bin/subspace-farmer/main.rs b/crates/subspace-farmer/src/bin/subspace-farmer/main.rs index 5a7cec3691..af56017038 100644 --- a/crates/subspace-farmer/src/bin/subspace-farmer/main.rs +++ b/crates/subspace-farmer/src/bin/subspace-farmer/main.rs @@ -113,13 +113,13 @@ struct DsnArgs { #[arg(long, default_value_t = 50)] in_connections: u32, /// Defines max established outgoing swarm connection limit. - #[arg(long, default_value_t = 50)] + #[arg(long, default_value_t = 100)] out_connections: u32, /// Defines max pending incoming connection limit. #[arg(long, default_value_t = 50)] pending_in_connections: u32, /// Defines max pending outgoing swarm connection limit. - #[arg(long, default_value_t = 50)] + #[arg(long, default_value_t = 100)] pending_out_connections: u32, /// Defines target total (in and out) connection number that should be maintained. #[arg(long, default_value_t = 50)] diff --git a/crates/subspace-networking/src/constructor.rs b/crates/subspace-networking/src/constructor.rs index 45e101f9a4..1c2e21f119 100644 --- a/crates/subspace-networking/src/constructor.rs +++ b/crates/subspace-networking/src/constructor.rs @@ -62,9 +62,9 @@ const SPECIAL_CONNECTED_PEERS_PROTOCOL_LOG_TARGET: &str = "special-connected-pee // It must be set for large plots. const SWARM_MAX_NEGOTIATING_INBOUND_STREAMS: usize = 100000; /// The default maximum established incoming connection number for the swarm. -const SWARM_MAX_ESTABLISHED_INCOMING_CONNECTIONS: u32 = 80; +const SWARM_MAX_ESTABLISHED_INCOMING_CONNECTIONS: u32 = 100; /// The default maximum established incoming connection number for the swarm. -const SWARM_MAX_ESTABLISHED_OUTGOING_CONNECTIONS: u32 = 80; +const SWARM_MAX_ESTABLISHED_OUTGOING_CONNECTIONS: u32 = 100; /// The default maximum pending incoming connection number for the swarm. const SWARM_MAX_PENDING_INCOMING_CONNECTIONS: u32 = 80; /// The default maximum pending incoming connection number for the swarm. diff --git a/crates/subspace-networking/src/utils/piece_provider.rs b/crates/subspace-networking/src/utils/piece_provider.rs index 56a854b5af..653e781f96 100644 --- a/crates/subspace-networking/src/utils/piece_provider.rs +++ b/crates/subspace-networking/src/utils/piece_provider.rs @@ -14,7 +14,7 @@ use subspace_core_primitives::{Piece, PieceIndex}; use tracing::{debug, trace, warn}; /// Defines initial duration between get_piece calls. -const GET_PIECE_INITIAL_INTERVAL: Duration = Duration::from_secs(3); +const GET_PIECE_INITIAL_INTERVAL: Duration = Duration::from_secs(5); /// Defines max duration between get_piece calls. const GET_PIECE_MAX_INTERVAL: Duration = Duration::from_secs(40); @@ -132,6 +132,7 @@ where max_interval: GET_PIECE_MAX_INTERVAL, // Try until we get a valid piece max_elapsed_time: None, + multiplier: 1.75, ..ExponentialBackoff::default() }; From 56afb1b4aaf3c64b26084a0219b5d9b79c0d96b3 Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Mon, 4 Sep 2023 19:10:35 +0700 Subject: [PATCH 2/2] networking: Add retries for block importing. --- crates/subspace-service/src/lib.rs | 1 + .../subspace-service/src/sync_from_dsn/import_blocks.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index 0260517cea..4a9e32e43a 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -16,6 +16,7 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. #![feature( + const_option, impl_trait_in_assoc_type, int_roundings, type_alias_impl_trait, diff --git a/crates/subspace-service/src/sync_from_dsn/import_blocks.rs b/crates/subspace-service/src/sync_from_dsn/import_blocks.rs index 0159511a44..dfb5affcb6 100644 --- a/crates/subspace-service/src/sync_from_dsn/import_blocks.rs +++ b/crates/subspace-service/src/sync_from_dsn/import_blocks.rs @@ -25,6 +25,7 @@ use sc_tracing::tracing::{debug, trace}; use sp_consensus::BlockOrigin; use sp_runtime::traits::{Block as BlockT, Header, NumberFor, One}; use sp_runtime::Saturating; +use std::num::NonZeroU16; use std::time::Duration; use subspace_archiving::reconstructor::Reconstructor; use subspace_core_primitives::{ @@ -34,6 +35,9 @@ use subspace_networking::utils::piece_provider::{PieceProvider, PieceValidator, use tokio::sync::Semaphore; use tracing::warn; +/// Get piece retry attempts number. +const PIECE_GETTER_RETRY_NUMBER: NonZeroU16 = NonZeroU16::new(3).expect("Not zero; qed"); + /// How many blocks to queue before pausing and waiting for blocks to be imported, this is /// essentially used to ensure we use a bounded amount of RAM during sync process. const QUEUED_BLOCKS_LIMIT: BlockNumber = 500; @@ -269,7 +273,10 @@ where } }; let maybe_piece = match piece_provider - .get_piece(piece_index, RetryPolicy::Limited(0)) + .get_piece( + piece_index, + RetryPolicy::Limited(PIECE_GETTER_RETRY_NUMBER.get()), + ) .await { Ok(maybe_piece) => maybe_piece,