Skip to content

Commit

Permalink
Merge pull request #1979 from subspace/gemini-3f-backport-improve-syn…
Browse files Browse the repository at this point in the history
…c-start-speed

Gemini 3f backport: Improve sync start speed on restart
  • Loading branch information
nazar-pc authored Sep 20, 2023
2 parents 303e99e + 9077e40 commit d1da404
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
28 changes: 25 additions & 3 deletions crates/subspace-service/src/sync_from_dsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ use sc_consensus::import_queue::ImportQueueService;
use sc_consensus_subspace::archiver::SegmentHeadersStore;
use sc_network::config::SyncMode;
use sc_network::{NetworkPeers, NetworkService};
use sp_api::BlockT;
use sp_api::{BlockT, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_consensus_subspace::{FarmerPublicKey, SubspaceApi};
use sp_runtime::Saturating;
use std::future::Future;
use std::sync::atomic::Ordering;
use std::sync::Arc;
Expand Down Expand Up @@ -61,9 +63,11 @@ where
Client: HeaderBackend<Block>
+ BlockBackend<Block>
+ BlockchainEvents<Block>
+ ProvideRuntimeApi<Block>
+ Send
+ Sync
+ 'static,
Client::Api: SubspaceApi<Block, FarmerPublicKey>,
{
let (tx, rx) = mpsc::channel(0);
let observer_fut = {
Expand Down Expand Up @@ -217,13 +221,31 @@ async fn create_worker<Block, AS, IQS, Client>(
where
Block: BlockT,
AS: AuxStore + Send + Sync + 'static,
Client: HeaderBackend<Block> + BlockBackend<Block> + Send + Sync + 'static,
Client: HeaderBackend<Block>
+ BlockBackend<Block>
+ ProvideRuntimeApi<Block>
+ Send
+ Sync
+ 'static,
Client::Api: SubspaceApi<Block, FarmerPublicKey>,
IQS: ImportQueueService<Block> + ?Sized,
{
// Corresponds to contents of block one, everyone has it, so we consider it being processed
// right away
let mut last_processed_segment_index = SegmentIndex::ZERO;
let mut last_processed_block_number = client.info().finalized_number;
// TODO: We'll be able to just take finalized block once we are able to decouple pruning from
// finality: https://github.com/paritytech/polkadot-sdk/issues/1570
let mut last_processed_block_number = {
let info = client.info();
info.best_number.saturating_sub(
client
.runtime_api()
.chain_constants(info.best_hash)
.map_err(|error| error.to_string())?
.confirmation_depth_k()
.into(),
)
};
let segment_header_downloader = SegmentHeaderDownloader::new(node);
let piece_provider = PieceProvider::new(
node.clone(),
Expand Down
5 changes: 2 additions & 3 deletions crates/subspace-service/src/sync_from_dsn/import_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ where
.is_some();

let info = client.info();
// We already have this block imported and it is finalized, so can't change
if last_archived_block <= info.finalized_number {
// We have already processed this block, it can't change
if last_archived_block <= *last_processed_block_number {
*last_processed_segment_index = segment_index;
*last_processed_block_number = last_archived_block;
// Reset reconstructor instance
reconstructor = Reconstructor::new().map_err(|error| error.to_string())?;
continue;
Expand Down

0 comments on commit d1da404

Please sign in to comment.