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

Add fast-sync. #2657

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ fn main() -> Result<(), Error> {
sync_from_dsn: true,
is_timekeeper: false,
timekeeper_cpu_cores: Default::default(),
fast_sync_enabled: false,
};

let partial_components = subspace_service::new_partial::<PosTable, RuntimeApi>(
Expand Down
24 changes: 19 additions & 5 deletions crates/subspace-node/src/commands/run/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ enum StatePruningMode {
Archive,
/// Keep only the data of finalized blocks.
ArchiveCanonical,
/// Keep the data of the last number of finalized blocks.
Number(u32),
}

impl FromStr for StatePruningMode {
Expand All @@ -181,17 +183,21 @@ impl FromStr for StatePruningMode {
match input {
"archive" => Ok(Self::Archive),
"archive-canonical" => Ok(Self::ArchiveCanonical),
_ => Err("Invalid state pruning mode specified".to_string()),
n => n
.parse()
.map_err(|_| "Invalid block pruning mode specified".to_string())
.map(Self::Number),
}
}
}

impl fmt::Display for StatePruningMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Archive => "archive",
Self::ArchiveCanonical => "archive-canonical",
})
match self {
Self::Archive => f.write_str("archive"),
Self::ArchiveCanonical => f.write_str("archive-canonical"),
Self::Number(n) => f.write_str(n.to_string().as_str()),
}
}
}

Expand Down Expand Up @@ -266,6 +272,7 @@ impl PruningOptions {
match self.state_pruning {
StatePruningMode::Archive => PruningMode::ArchiveAll,
StatePruningMode::ArchiveCanonical => PruningMode::ArchiveCanonical,
StatePruningMode::Number(num) => PruningMode::blocks_pruning(num),
}
}

Expand Down Expand Up @@ -407,6 +414,10 @@ pub(super) struct ConsensusChainOptions {

#[clap(flatten)]
timekeeper_options: TimekeeperOptions,

/// Experimental support of state-only sync using DSN.
#[arg(long, default_value_t = false)]
fast_sync: bool,
}

pub(super) struct PrometheusConfiguration {
Expand Down Expand Up @@ -450,6 +461,7 @@ pub(super) fn create_consensus_chain_configuration(
sync_from_dsn,
storage_monitor,
mut timekeeper_options,
mut fast_sync,
} = consensus_node_options;

let transaction_pool;
Expand All @@ -467,6 +479,7 @@ pub(super) fn create_consensus_chain_configuration(
network_options.allow_private_ips = true;
dsn_options.dsn_disable_bootstrap_on_start = true;
timekeeper_options.timekeeper = true;
fast_sync = false; // Experimental state
}

transaction_pool = pool_config.transaction_pool(dev);
Expand Down Expand Up @@ -660,6 +673,7 @@ pub(super) fn create_consensus_chain_configuration(
sync_from_dsn,
is_timekeeper: timekeeper_options.timekeeper,
timekeeper_cpu_cores: timekeeper_options.timekeeper_cpu_cores,
fast_sync_enabled: fast_sync,
},
dev,
pot_external_entropy,
Expand Down
10 changes: 8 additions & 2 deletions crates/subspace-service/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::dsn::DsnConfig;
use crate::sync_from_dsn::DsnSyncPieceGetter;
use crate::sync_from_dsn::import_blocks::DsnSyncPieceGetter;
use sc_chain_spec::ChainSpec;
use sc_network::config::{
MultiaddrWithPeerId, NetworkConfiguration, NodeKeyConfig, SetConfig, SyncMode, TransportConfig,
Expand Down Expand Up @@ -137,7 +137,11 @@ impl From<SubstrateConfiguration> for Configuration {
// Substrate's default
max_blocks_per_request: 64,
// Substrate's default, full mode
sync_mode: SyncMode::Full,
sync_mode: SyncMode::LightState {
skip_proofs: true,
storage_chain_mode: false,
},
// sync_mode: SyncMode::Full, // TODO: add configurable default sync-state
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment

pause_sync: Arc::new(AtomicBool::new(false)),
// Substrate's default
enable_dht_random_walk: true,
Expand Down Expand Up @@ -248,6 +252,8 @@ pub struct SubspaceConfiguration {
pub is_timekeeper: bool,
/// CPU cores that timekeeper can use
pub timekeeper_cpu_cores: HashSet<usize>,
/// Enables state-only sync using DSN.
pub fast_sync_enabled: bool,
}

impl Deref for SubspaceConfiguration {
Expand Down