diff --git a/Cargo.toml b/Cargo.toml index e71fc735cb..db5a09fd8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ sqlx = "0.7.0-alpha.3" sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } +sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } @@ -75,7 +75,7 @@ sc-network-common = { version = "0.10.0-dev", git = "https://github.com/parityte sc-network-sync = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index a5a0689d72..69ea420852 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -31,9 +31,10 @@ scale-codec = { package = "parity-scale-codec", workspace = true } tempfile = "3.3.0" # Substrate sc-block-builder = { workspace = true } -sc-client-db = { workspace = true } +sc-client-db = { workspace = true, features = ["rocksdb"] } sp-consensus = { workspace = true } sp-io = { workspace = true } substrate-test-runtime-client = { workspace = true } # Frontier +fc-db = { workspace = true, features = ["rocksdb"] } frontier-template-runtime = { workspace = true, features = ["default"] } diff --git a/client/db/Cargo.toml b/client/db/Cargo.toml index 14d62a9ab1..92d489e089 100644 --- a/client/db/Cargo.toml +++ b/client/db/Cargo.toml @@ -19,12 +19,12 @@ log = "0.4.17" parity-db = { workspace = true, optional = true } parking_lot = "0.12.1" scale-codec = { package = "parity-scale-codec", workspace = true } -smallvec = "1.10" +smallvec = { version = "1.10", optional = true } sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"] } tokio = { version = "1.19", features = ["macros", "sync"] } # Substrate sc-client-api = { workspace = true } -sc-client-db = { workspace = true, features = ["rocksdb"] } +sc-client-db = { workspace = true } sp-api = { workspace = true } sp-blockchain = { workspace = true } sp-core = { workspace = true } @@ -38,7 +38,13 @@ fp-rpc = { workspace = true, features = ["default"] } fp-storage = { workspace = true, features = ["default"] } [features] -default = ["kvdb-rocksdb", "parity-db"] +default = ["parity-db"] +parity-db = ["dep:parity-db"] +rocksdb = [ + "kvdb-rocksdb", + "sc-client-db/rocksdb", + "smallvec", +] [dev-dependencies] maplit = "1.0.2" diff --git a/client/db/src/kv/mod.rs b/client/db/src/kv/mod.rs index 74d3c10ed3..adf4992e3a 100644 --- a/client/db/src/kv/mod.rs +++ b/client/db/src/kv/mod.rs @@ -114,10 +114,12 @@ impl Backend { client, &DatabaseSettings { source: match database { + #[cfg(feature = "rocksdb")] DatabaseSource::RocksDb { .. } => DatabaseSource::RocksDb { path: frontier_database_dir(db_config_dir, "db"), cache_size: 0, }, + #[cfg(feature = "parity-db")] DatabaseSource::ParityDb { .. } => DatabaseSource::ParityDb { path: frontier_database_dir(db_config_dir, "paritydb"), }, diff --git a/client/db/src/kv/upgrade.rs b/client/db/src/kv/upgrade.rs index 20ab19befd..6243f53481 100644 --- a/client/db/src/kv/upgrade.rs +++ b/client/db/src/kv/upgrade.rs @@ -100,13 +100,11 @@ pub(crate) fn upgrade_db>( match db_version { 0 => return Err(UpgradeError::UnsupportedVersion(db_version)), 1 => { - let summary = match source { - DatabaseSource::ParityDb { .. } => { - migrate_1_to_2_parity_db::(client, db_path)? - } - DatabaseSource::RocksDb { .. } => { - migrate_1_to_2_rocks_db::(client, db_path)? - } + let summary: UpgradeVersion1To2Summary = match source { + #[cfg(feature = "parity-db")] + DatabaseSource::ParityDb { .. } => migrate_1_to_2_parity_db::(client, db_path)?, + #[cfg(feature = "rocksdb")] + DatabaseSource::RocksDb { .. } => migrate_1_to_2_rocks_db::(client, db_path)?, _ => panic!("DatabaseSource required for upgrade ParityDb | RocksDb"), }; if !summary.error.is_empty() { @@ -165,6 +163,7 @@ fn version_file_path(path: &Path) -> PathBuf { /// Migration from version1 to version2: /// - The format of the Ethereum<>Substrate block mapping changed to support equivocation. /// - Migrating schema from One-to-one to One-to-many (EthHash: Vec) relationship. +#[cfg(feature = "rocksdb")] pub(crate) fn migrate_1_to_2_rocks_db>( client: Arc, db_path: &Path, @@ -246,6 +245,7 @@ pub(crate) fn migrate_1_to_2_rocks_db>( Ok(res) } +#[cfg(feature = "parity-db")] pub(crate) fn migrate_1_to_2_parity_db>( client: Arc, db_path: &Path, @@ -333,6 +333,7 @@ mod tests { sync::Arc, }; + use crate::kv::DatabaseSettings; use scale_codec::Encode; use sp_blockchain::HeaderBackend; use sp_core::H256; @@ -352,23 +353,29 @@ mod tests { Ok(Arc::new(crate::kv::Backend::::new(client, setting)?)) } + #[cfg_attr(not(any(feature = "rocksdb", feature = "parity-db")), ignore)] #[test] fn upgrade_1_to_2_works() { - let tmp_1 = tempdir().expect("create a temporary directory"); - let tmp_2 = tempdir().expect("create a temporary directory"); - - let settings = vec![ + let settings: Vec = vec![ // Rocks db + #[cfg(feature = "rocksdb")] crate::kv::DatabaseSettings { source: sc_client_db::DatabaseSource::RocksDb { - path: tmp_1.path().to_owned(), + path: tempdir() + .expect("create a temporary directory") + .path() + .to_owned(), cache_size: 0, }, }, // Parity db + #[cfg(feature = "parity-db")] crate::kv::DatabaseSettings { source: sc_client_db::DatabaseSource::ParityDb { - path: tmp_2.path().to_owned(), + path: tempdir() + .expect("create a temporary directory") + .path() + .to_owned(), }, }, ]; @@ -495,6 +502,7 @@ mod tests { } } + #[cfg(feature = "rocksdb")] #[test] fn create_db_with_current_version_works() { let tmp = tempdir().expect("create a temporary directory"); diff --git a/client/db/src/kv/utils.rs b/client/db/src/kv/utils.rs index a6c4da2dfb..ff241b9cfb 100644 --- a/client/db/src/kv/utils.rs +++ b/client/db/src/kv/utils.rs @@ -29,9 +29,9 @@ pub fn open_database>( config: &DatabaseSettings, ) -> Result>, String> { let db: Arc> = match &config.source { - DatabaseSource::ParityDb { path } => { - open_parity_db::(client, path, &config.source)? - } + #[cfg(feature = "parity-db")] + DatabaseSource::ParityDb { path } => open_parity_db::(client, path, &config.source)?, + #[cfg(feature = "rocksdb")] DatabaseSource::RocksDb { path, .. } => { open_kvdb_rocksdb::(client, path, true, &config.source)? } @@ -51,7 +51,7 @@ pub fn open_database>( Ok(db) } -#[cfg(feature = "kvdb-rocksdb")] +#[cfg(feature = "rocksdb")] fn open_kvdb_rocksdb>( client: Arc, path: &Path, @@ -75,7 +75,7 @@ fn open_kvdb_rocksdb>( return Ok(sp_database::as_database(db)); } -#[cfg(not(feature = "kvdb-rocksdb"))] +#[cfg(not(feature = "rocksdb"))] fn open_kvdb_rocksdb>( _client: Arc, _path: &Path, diff --git a/template/node/Cargo.toml b/template/node/Cargo.toml index 95d238afc1..d6e8d53589 100644 --- a/template/node/Cargo.toml +++ b/template/node/Cargo.toml @@ -38,7 +38,7 @@ sc-network-common = { workspace = true } sc-network-sync = { workspace = true } sc-rpc = { workspace = true } sc-rpc-api = { workspace = true } -sc-service = { workspace = true } +sc-service = { workspace = true, features = ["default"] } sc-telemetry = { workspace = true } sc-transaction-pool = { workspace = true } sc-transaction-pool-api = { workspace = true }