Skip to content

Commit 92a51c1

Browse files
authored
Merge pull request #2974 from autonomys/snap-sync-without-light-state-sync
Snap sync without light state sync
2 parents 124c045 + 40b02ca commit 92a51c1

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ fn main() -> Result<(), Error> {
215215

216216
let partial_components = subspace_service::new_partial::<PosTable, RuntimeApi>(
217217
&consensus_chain_config,
218+
false,
218219
&pot_external_entropy,
219220
)
220221
.map_err(|error| {

crates/subspace-node/src/commands/run.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use domain_runtime_primitives::opaque::Block as DomainBlock;
1717
use futures::FutureExt;
1818
use sc_cli::Signals;
1919
use sc_consensus_slots::SlotProportion;
20-
use sc_network::config::SyncMode;
2120
use sc_service::{BlocksPruning, PruningMode};
2221
use sc_storage_monitor::StorageMonitorService;
2322
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
@@ -149,6 +148,10 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
149148

150149
let partial_components = match subspace_service::new_partial::<PosTable, RuntimeApi>(
151150
&subspace_configuration,
151+
match subspace_configuration.sync {
152+
ChainSyncMode::Full => false,
153+
ChainSyncMode::Snap => true,
154+
},
152155
&pot_external_entropy,
153156
) {
154157
Ok(partial_components) => partial_components,
@@ -164,15 +167,9 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
164167
consensus_state_pruning = PruningMode::ArchiveCanonical;
165168
subspace_configuration.base.state_pruning = Some(PruningMode::ArchiveCanonical);
166169

167-
// TODO: revisit SyncMode change after https://github.com/paritytech/polkadot-sdk/issues/4407
168-
if subspace_configuration.base.network.sync_mode.light_state() {
169-
// In case of archival pruning mode sync mode needs to be set to full or
170-
// else Substrate network will fail to initialize
171-
subspace_configuration.base.network.sync_mode = SyncMode::Full;
172-
}
173-
174170
subspace_service::new_partial::<PosTable, RuntimeApi>(
175171
&subspace_configuration,
172+
false,
176173
&pot_external_entropy,
177174
)
178175
.map_err(|error| {

crates/subspace-node/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ fn main() -> Result<(), Error> {
148148
..
149149
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
150150
&config,
151+
false,
151152
&derive_pot_external_entropy(&config, None)?,
152153
)?;
153154
Ok((
@@ -166,6 +167,7 @@ fn main() -> Result<(), Error> {
166167
..
167168
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
168169
&config,
170+
false,
169171
&derive_pot_external_entropy(&config, None)?,
170172
)?;
171173
Ok((
@@ -185,6 +187,7 @@ fn main() -> Result<(), Error> {
185187
..
186188
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
187189
&config,
190+
false,
188191
&derive_pot_external_entropy(&config, None)?,
189192
)?;
190193
Ok((
@@ -205,6 +208,7 @@ fn main() -> Result<(), Error> {
205208
..
206209
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
207210
&config,
211+
false,
208212
&derive_pot_external_entropy(&config, None)?,
209213
)?;
210214
Ok((
@@ -227,6 +231,7 @@ fn main() -> Result<(), Error> {
227231
..
228232
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
229233
&config,
234+
false,
230235
&derive_pot_external_entropy(&config, None)?,
231236
)?;
232237
Ok((
@@ -263,6 +268,7 @@ fn main() -> Result<(), Error> {
263268
let PartialComponents { client, .. } =
264269
subspace_service::new_partial::<PosTable, RuntimeApi>(
265270
&config,
271+
false,
266272
&derive_pot_external_entropy(&config, None)?,
267273
)?;
268274

@@ -279,6 +285,7 @@ fn main() -> Result<(), Error> {
279285
client, backend, ..
280286
} = subspace_service::new_partial::<PosTable, RuntimeApi>(
281287
&config,
288+
false,
282289
&derive_pot_external_entropy(&config, None)?,
283290
)?;
284291
let db = backend.expose_db();

crates/subspace-service/src/config.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,7 @@ impl From<SubstrateConfiguration> for Configuration {
154154
max_parallel_downloads: 5,
155155
// Substrate's default
156156
max_blocks_per_request: 64,
157-
sync_mode: match configuration.network.sync_mode {
158-
ChainSyncMode::Full => SyncMode::Full,
159-
// TODO: revisit SyncMode change after https://github.com/paritytech/polkadot-sdk/issues/4407
160-
ChainSyncMode::Snap => SyncMode::LightState {
161-
skip_proofs: false,
162-
storage_chain_mode: false,
163-
},
164-
},
157+
sync_mode: SyncMode::Full,
165158
pause_sync: Arc::new(AtomicBool::new(false)),
166159
// Substrate's default
167160
enable_dht_random_walk: true,

crates/subspace-service/src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi;
5252
use parking_lot::Mutex;
5353
use prometheus_client::registry::Registry;
5454
use sc_basic_authorship::ProposerFactory;
55+
use sc_chain_spec::GenesisBlockBuilder;
5556
use sc_client_api::execution_extensions::ExtensionsFactory;
5657
use sc_client_api::{
5758
AuxStore, Backend, BlockBackend, BlockchainEvents, ExecutorProvider, HeaderBackend,
@@ -459,9 +460,12 @@ type PartialComponents<RuntimeApi> = sc_service::PartialComponents<
459460
>;
460461

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

502+
let backend = sc_service::new_db_backend(config.db_config())?;
503+
504+
let genesis_block_builder = GenesisBlockBuilder::new(
505+
config.chain_spec.as_storage_builder(),
506+
!snap_sync,
507+
backend.clone(),
508+
executor.clone(),
509+
)?;
510+
498511
let (client, backend, keystore_container, task_manager) =
499-
sc_service::new_full_parts::<Block, RuntimeApi, _>(
512+
sc_service::new_full_parts_with_genesis_builder::<Block, RuntimeApi, _, _>(
500513
config,
501514
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
502515
executor.clone(),
516+
backend,
517+
genesis_block_builder,
518+
false,
503519
)?;
504520

505521
let kzg = tokio::task::block_in_place(|| Kzg::new(embedded_kzg_settings()));

crates/subspace-service/src/sync_from_dsn/snap_sync.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use sc_consensus::{
1010
};
1111
use sc_consensus_subspace::archiver::{decode_block, SegmentHeadersStore};
1212
use sc_network::{NetworkRequest, PeerId};
13-
use sc_network_sync::service::syncing_service::SyncRestartArgs;
1413
use sc_network_sync::SyncingService;
15-
use sc_service::config::SyncMode;
1614
use sc_service::{ClientExt, Error};
1715
use sp_api::ProvideRuntimeApi;
1816
use sp_blockchain::HeaderBackend;
@@ -90,15 +88,6 @@ pub(crate) async fn snap_sync<Backend, Block, AS, Client, PG, NR>(
9088
} else {
9189
debug!("Snap sync can only work with genesis state, skipping");
9290
}
93-
94-
// Switch back to full sync mode
95-
let info = client.info();
96-
sync_service
97-
.restart(SyncRestartArgs {
98-
sync_mode: SyncMode::Full,
99-
new_best_block: Some(info.best_number),
100-
})
101-
.await;
10291
}
10392

10493
// Get blocks from the last segment or from the segment containing the target block.

0 commit comments

Comments
 (0)