Skip to content

Commit 40b02ca

Browse files
committed
Snap sync without lite state sync
1 parent 8454324 commit 40b02ca

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,12 @@ type PartialComponents<RuntimeApi> = sc_service::PartialComponents<
460460
>;
461461

462462
/// Creates `PartialComponents` for Subspace client.
463-
#[allow(clippy::type_complexity)]
464463
pub fn new_partial<PosTable, RuntimeApi>(
465464
// TODO: Stop using `Configuration` once
466465
// https://github.com/paritytech/polkadot-sdk/pull/5364 is in our fork
467466
config: &Configuration,
467+
// TODO: Replace with check for `ChainSyncMode` once we get rid of ^ `Configuration`
468+
snap_sync: bool,
468469
pot_external_entropy: &[u8],
469470
) -> Result<PartialComponents<RuntimeApi>, ServiceError>
470471
where
@@ -502,7 +503,7 @@ where
502503

503504
let genesis_block_builder = GenesisBlockBuilder::new(
504505
config.chain_spec.as_storage_builder(),
505-
!config.no_genesis(),
506+
!snap_sync,
506507
backend.clone(),
507508
executor.clone(),
508509
)?;

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)