Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap sync without light state sync #2974

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ fn main() -> Result<(), Error> {

let partial_components = subspace_service::new_partial::<PosTable, RuntimeApi>(
&consensus_chain_config,
false,
&pot_external_entropy,
)
.map_err(|error| {
Expand Down
13 changes: 5 additions & 8 deletions crates/subspace-node/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use domain_runtime_primitives::opaque::Block as DomainBlock;
use futures::FutureExt;
use sc_cli::Signals;
use sc_consensus_slots::SlotProportion;
use sc_network::config::SyncMode;
use sc_service::{BlocksPruning, PruningMode};
use sc_storage_monitor::StorageMonitorService;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
Expand Down Expand Up @@ -149,6 +148,10 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {

let partial_components = match subspace_service::new_partial::<PosTable, RuntimeApi>(
&subspace_configuration,
match subspace_configuration.sync {
ChainSyncMode::Full => false,
ChainSyncMode::Snap => true,
},
&pot_external_entropy,
) {
Ok(partial_components) => partial_components,
Expand All @@ -164,15 +167,9 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
consensus_state_pruning = PruningMode::ArchiveCanonical;
subspace_configuration.base.state_pruning = Some(PruningMode::ArchiveCanonical);

// TODO: revisit SyncMode change after https://github.com/paritytech/polkadot-sdk/issues/4407
if subspace_configuration.base.network.sync_mode.light_state() {
// In case of archival pruning mode sync mode needs to be set to full or
// else Substrate network will fail to initialize
subspace_configuration.base.network.sync_mode = SyncMode::Full;
}

subspace_service::new_partial::<PosTable, RuntimeApi>(
&subspace_configuration,
false,
&pot_external_entropy,
)
.map_err(|error| {
Expand Down
7 changes: 7 additions & 0 deletions crates/subspace-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ fn main() -> Result<(), Error> {
..
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
&config,
false,
&derive_pot_external_entropy(&config, None)?,
)?;
Ok((
Expand All @@ -166,6 +167,7 @@ fn main() -> Result<(), Error> {
..
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
&config,
false,
&derive_pot_external_entropy(&config, None)?,
)?;
Ok((
Expand All @@ -185,6 +187,7 @@ fn main() -> Result<(), Error> {
..
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
&config,
false,
&derive_pot_external_entropy(&config, None)?,
)?;
Ok((
Expand All @@ -205,6 +208,7 @@ fn main() -> Result<(), Error> {
..
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
&config,
false,
&derive_pot_external_entropy(&config, None)?,
)?;
Ok((
Expand All @@ -227,6 +231,7 @@ fn main() -> Result<(), Error> {
..
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
&config,
false,
&derive_pot_external_entropy(&config, None)?,
)?;
Ok((
Expand Down Expand Up @@ -263,6 +268,7 @@ fn main() -> Result<(), Error> {
let PartialComponents { client, .. } =
subspace_service::new_partial::<PosTable, RuntimeApi>(
&config,
false,
&derive_pot_external_entropy(&config, None)?,
)?;

Expand All @@ -279,6 +285,7 @@ fn main() -> Result<(), Error> {
client, backend, ..
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
&config,
false,
&derive_pot_external_entropy(&config, None)?,
)?;
let db = backend.expose_db();
Expand Down
9 changes: 1 addition & 8 deletions crates/subspace-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,7 @@ impl From<SubstrateConfiguration> for Configuration {
max_parallel_downloads: 5,
// Substrate's default
max_blocks_per_request: 64,
sync_mode: match configuration.network.sync_mode {
ChainSyncMode::Full => SyncMode::Full,
// TODO: revisit SyncMode change after https://github.com/paritytech/polkadot-sdk/issues/4407
ChainSyncMode::Snap => SyncMode::LightState {
skip_proofs: false,
storage_chain_mode: false,
},
},
sync_mode: SyncMode::Full,
pause_sync: Arc::new(AtomicBool::new(false)),
// Substrate's default
enable_dht_random_walk: true,
Expand Down
20 changes: 18 additions & 2 deletions crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi;
use parking_lot::Mutex;
use prometheus_client::registry::Registry;
use sc_basic_authorship::ProposerFactory;
use sc_chain_spec::GenesisBlockBuilder;
use sc_client_api::execution_extensions::ExtensionsFactory;
use sc_client_api::{
AuxStore, Backend, BlockBackend, BlockchainEvents, ExecutorProvider, HeaderBackend,
Expand Down Expand Up @@ -459,9 +460,12 @@ type PartialComponents<RuntimeApi> = sc_service::PartialComponents<
>;

/// Creates `PartialComponents` for Subspace client.
#[allow(clippy::type_complexity)]
pub fn new_partial<PosTable, RuntimeApi>(
// TODO: Stop using `Configuration` once
// https://github.com/paritytech/polkadot-sdk/pull/5364 is in our fork
config: &Configuration,
// TODO: Replace with check for `ChainSyncMode` once we get rid of ^ `Configuration`
snap_sync: bool,
pot_external_entropy: &[u8],
) -> Result<PartialComponents<RuntimeApi>, ServiceError>
where
Expand Down Expand Up @@ -495,11 +499,23 @@ where
let executor = sc_service::new_wasm_executor(config);
let domains_executor = sc_service::new_wasm_executor(config);

let backend = sc_service::new_db_backend(config.db_config())?;

let genesis_block_builder = GenesisBlockBuilder::new(
config.chain_spec.as_storage_builder(),
!snap_sync,
backend.clone(),
executor.clone(),
)?;

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
sc_service::new_full_parts_with_genesis_builder::<Block, RuntimeApi, _, _>(
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor.clone(),
backend,
genesis_block_builder,
false,
)?;

let kzg = tokio::task::block_in_place(|| Kzg::new(embedded_kzg_settings()));
Expand Down
11 changes: 0 additions & 11 deletions crates/subspace-service/src/sync_from_dsn/snap_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use sc_consensus::{
};
use sc_consensus_subspace::archiver::{decode_block, SegmentHeadersStore};
use sc_network::{NetworkRequest, PeerId};
use sc_network_sync::service::syncing_service::SyncRestartArgs;
use sc_network_sync::SyncingService;
use sc_service::config::SyncMode;
use sc_service::{ClientExt, Error};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
Expand Down Expand Up @@ -90,15 +88,6 @@ pub(crate) async fn snap_sync<Backend, Block, AS, Client, PG, NR>(
} else {
debug!("Snap sync can only work with genesis state, skipping");
}

// Switch back to full sync mode
let info = client.info();
sync_service
.restart(SyncRestartArgs {
sync_mode: SyncMode::Full,
new_best_block: Some(info.best_number),
})
.await;
}

// Get blocks from the last segment or from the segment containing the target block.
Expand Down
Loading