Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into update-polkadot-v…
Browse files Browse the repository at this point in the history
…0.9.43
  • Loading branch information
koushiro committed Jun 27, 2023
2 parents f0b434b + 3b87145 commit a6fe689
Show file tree
Hide file tree
Showing 61 changed files with 3,234 additions and 343 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.69.0
toolchain: nightly-2023-05-23
target: wasm32-unknown-unknown
override: true
components: rust-docs
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.69.0
toolchain: nightly-2023-05-23
target: wasm32-unknown-unknown
override: true
- name: Install protoc
Expand All @@ -39,7 +39,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.69.0
toolchain: nightly-2023-05-23
target: wasm32-unknown-unknown
override: true
- name: Install protoc
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.69.0
toolchain: nightly-2023-05-23
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy
Expand Down
16 changes: 7 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ clap = { version = "4.3", features = ["derive", "deprecated"] }
environmental = { version = "1.1.4", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.39.1", default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
futures = "0.3.28"
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
hex-literal = "0.4.1"
Expand All @@ -68,7 +68,7 @@ tokio = "1.28.2"
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" }
Expand All @@ -82,7 +82,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" }
Expand All @@ -101,6 +101,7 @@ sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate", br
sp-keyring = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime-interface = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-session = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-state-machine = { version = "0.13.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { version = "5.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
45 changes: 32 additions & 13 deletions client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,54 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = { workspace = true }
ethereum = { workspace = true, features = ["with-codec"] }
futures = { workspace = true }
ethereum = { workspace = true, features = ["with-codec"], optional = true }
futures = { workspace = true, optional = true }
kvdb-rocksdb = { workspace = true, optional = true }
log = { workspace = true }
parity-db = { workspace = true, optional = true }
parking_lot = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
smallvec = "1.10"
sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"] }
tokio = { workspace = true, features = ["macros", "sync"] }
smallvec = { version = "1.10", optional = true }
sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"], optional = true }
tokio = { workspace = true, features = ["macros", "sync"], optional = true }
# Substrate
sc-client-api = { workspace = true }
sc-client-db = { workspace = true, features = ["rocksdb"] }
sp-api = { workspace = true }
sc-client-api = { workspace = true, optional = true }
sc-client-db = { workspace = true }
sp-api = { workspace = true, optional = true }
sp-blockchain = { workspace = true }
sp-core = { workspace = true }
sp-database = { workspace = true }
sp-runtime = { workspace = true }
sp-storage = { workspace = true }
sp-storage = { workspace = true, optional = true }
# Frontier
fc-storage = { workspace = true }
fp-consensus = { workspace = true, features = ["default"] }
fp-rpc = { workspace = true, features = ["default"] }
fc-storage = { workspace = true, optional = true }
fp-consensus = { workspace = true, features = ["default"], optional = true }
fp-rpc = { workspace = true, features = ["default"], optional = true }
fp-storage = { workspace = true, features = ["default"] }

[features]
default = ["kvdb-rocksdb", "parity-db"]
default = ["rocksdb"]
rocksdb = [
"kvdb-rocksdb",
"sc-client-db/rocksdb",
"smallvec",
]
parity-db = ["dep:parity-db"]
sql = [
"ethereum",
"futures",
"sqlx",
"tokio",
"sc-client-api",
"sp-api",
"sp-storage",
"fc-storage",
"fp-consensus",
"fp-rpc",
]

[dev-dependencies]
futures = { version = "0.3.25" }
maplit = "1.0.2"
tempfile = "3.3.0"
# Substrate
Expand Down
18 changes: 11 additions & 7 deletions client/db/src/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ impl<Block: BlockT> Backend<Block> {
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"),
},
Expand Down Expand Up @@ -308,13 +310,15 @@ impl<Block: BlockT> MappingDb<Block> {

let substrate_hashes = match self.block_hash(&commitment.ethereum_block_hash) {
Ok(Some(mut data)) => {
data.push(commitment.block_hash);
log::warn!(
target: "fc-db",
"Possible equivocation at ethereum block hash {} {:?}",
&commitment.ethereum_block_hash,
&data
);
if !data.contains(&commitment.block_hash) {
data.push(commitment.block_hash);
log::warn!(
target: "fc-db",
"Possible equivocation at ethereum block hash {} {:?}",
&commitment.ethereum_block_hash,
&data
);
}
data
}
_ => vec![commitment.block_hash],
Expand Down
34 changes: 21 additions & 13 deletions client/db/src/kv/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ pub(crate) fn upgrade_db<Block: BlockT, C: HeaderBackend<Block>>(
match db_version {
0 => return Err(UpgradeError::UnsupportedVersion(db_version)),
1 => {
let summary = match source {
DatabaseSource::ParityDb { .. } => {
migrate_1_to_2_parity_db::<Block, C>(client, db_path)?
}
DatabaseSource::RocksDb { .. } => {
migrate_1_to_2_rocks_db::<Block, C>(client, db_path)?
}
let summary: UpgradeVersion1To2Summary = match source {
#[cfg(feature = "parity-db")]
DatabaseSource::ParityDb { .. } => migrate_1_to_2_parity_db::<Block, C>(client, db_path)?,
#[cfg(feature = "rocksdb")]
DatabaseSource::RocksDb { .. } => migrate_1_to_2_rocks_db::<Block, C>(client, db_path)?,
_ => panic!("DatabaseSource required for upgrade ParityDb | RocksDb"),
};
if !summary.error.is_empty() {
Expand Down Expand Up @@ -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<SubstrateHash>) relationship.
#[cfg(feature = "rocksdb")]
pub(crate) fn migrate_1_to_2_rocks_db<Block: BlockT, C: HeaderBackend<Block>>(
client: Arc<C>,
db_path: &Path,
Expand Down Expand Up @@ -246,6 +245,7 @@ pub(crate) fn migrate_1_to_2_rocks_db<Block: BlockT, C: HeaderBackend<Block>>(
Ok(res)
}

#[cfg(feature = "parity-db")]
pub(crate) fn migrate_1_to_2_parity_db<Block: BlockT, C: HeaderBackend<Block>>(
client: Arc<C>,
db_path: &Path,
Expand Down Expand Up @@ -333,6 +333,7 @@ mod tests {
sync::Arc,
};

use crate::kv::DatabaseSettings;
use scale_codec::Encode;
use sp_blockchain::HeaderBackend;
use sp_core::H256;
Expand All @@ -352,23 +353,29 @@ mod tests {
Ok(Arc::new(crate::kv::Backend::<Block>::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<DatabaseSettings> = 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(),
},
},
];
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions client/db/src/kv/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub fn open_database<Block: BlockT, C: HeaderBackend<Block>>(
config: &DatabaseSettings,
) -> Result<Arc<dyn Database<DbHash>>, String> {
let db: Arc<dyn Database<DbHash>> = match &config.source {
DatabaseSource::ParityDb { path } => {
open_parity_db::<Block, C>(client, path, &config.source)?
}
#[cfg(feature = "parity-db")]
DatabaseSource::ParityDb { path } => open_parity_db::<Block, C>(client, path, &config.source)?,
#[cfg(feature = "rocksdb")]
DatabaseSource::RocksDb { path, .. } => {
open_kvdb_rocksdb::<Block, C>(client, path, true, &config.source)?
}
Expand All @@ -51,7 +51,7 @@ pub fn open_database<Block: BlockT, C: HeaderBackend<Block>>(
Ok(db)
}

#[cfg(feature = "kvdb-rocksdb")]
#[cfg(feature = "rocksdb")]
fn open_kvdb_rocksdb<Block: BlockT, C: HeaderBackend<Block>>(
client: Arc<C>,
path: &Path,
Expand All @@ -75,7 +75,7 @@ fn open_kvdb_rocksdb<Block: BlockT, C: HeaderBackend<Block>>(
return Ok(sp_database::as_database(db));
}

#[cfg(not(feature = "kvdb-rocksdb"))]
#[cfg(not(feature = "rocksdb"))]
fn open_kvdb_rocksdb<Block: BlockT, C: HeaderBackend<Block>>(
_client: Arc<C>,
_path: &Path,
Expand Down
5 changes: 4 additions & 1 deletion client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ use sp_core::H256;
use sp_runtime::traits::Block as BlockT;

pub mod kv;
pub mod sql;
use kv::{columns, static_keys};

#[cfg(feature = "sql")]
pub mod sql;

#[derive(Clone)]
pub enum Backend<Block: BlockT> {
KeyValue(kv::Backend<Block>),
#[cfg(feature = "sql")]
Sql(sql::Backend<Block>),
}

Expand Down
Loading

0 comments on commit a6fe689

Please sign in to comment.