Skip to content

Commit 5ce31f7

Browse files
Bump to polkadot-v0.9.40 as a base for substrate related deps (#848)
* Use locked/polkadot-v0.9.40 substrate and frontier deps * [substrate-apply] Move grandpa crates to consensus folder #13458 * Use suitable evm version * Fix naming * [frontier-apply] EVM + Weight v2 support #1039 * [substrate-apply] Deprecate Weight::from_{ref_time, proof_size} #13475 * [substrate-apply] Offences report system rework #13425 * Add missing GasLimitPovSizeRatio for pallet_evm::Config * [frontier-apply] Add pending support for eth_getBlockByNumber #1048 * Fix is_precompile return value * Add missing args for weight limit and transaction len at runner call and created methods * Add missing trait OnFinalize * Use SyncingService for Eth * [frontier-apply] sql backend w/ receipt log indexing #883 (part 1) * [frontier-apply] Add txpool RPC and impl new_pending_transaction_filter #1073 * [substrate-apply] Extract syncing protocol from sc-network #12828 * sql backend w/ receipt log indexing #883 (part 2) * [frontier-apply] sql backend w/ receipt log indexing #883 (part 3) * Fix tests * Update features snapshot * Fux typo * Fix clippy default usage * Fix clippy ref usage * Add missing docs * Introduce frontier backend configuration * [frontier-apply] make rocksdb and paritydb optional. (#1088) * Make new_partial async * Return result for frontier backend creation * Implement a helper function to remove frontier offchain db * Update features snapshot * Fix clippy * Update help stdout fixture * [substrate-apply] Pub enum runtime to pub struct runtime #13250 * Update frontier * Properly use evm deps * Fix fmt * Use fully qualified TxPool usage * Link TODO to humanode issue * Add test to verify pending block extraction * Return new_partial to be synchronously * Remove missed added test file * Fix help sdtout fixture * Remove pending block test
1 parent 7b2044e commit 5ce31f7

File tree

58 files changed

+1709
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1709
-726
lines changed

Cargo.lock

+808-339
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+90-89
Large diffs are not rendered by default.

crates/crypto-utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ publish = false
88
frame-support = { workspace = true }
99
pallet-im-online = { workspace = true }
1010
sp-consensus-babe = { workspace = true }
11-
sp-finality-grandpa = { workspace = true }
11+
sp-consensus-grandpa = { workspace = true }
1212
sp-runtime = { workspace = true }

crates/crypto-utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
44
use sp_consensus_babe::AuthorityId as BabeId;
5-
use sp_finality_grandpa::AuthorityId as GrandpaId;
5+
use sp_consensus_grandpa::AuthorityId as GrandpaId;
66
use sp_runtime::{
77
app_crypto::{Pair, Public},
88
traits::IdentifyAccount,

crates/humanode-peer/Cargo.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ clap = { workspace = true, features = ["derive"] }
2727
codec = { workspace = true, package = "parity-scale-codec" }
2828
fc-cli = { workspace = true }
2929
fc-consensus = { workspace = true }
30-
fc-db = { workspace = true }
31-
fc-mapping-sync = { workspace = true }
30+
fc-db = { workspace = true, features = ["sql"] }
31+
fc-mapping-sync = { workspace = true, features = ["sql"] }
3232
fc-rpc = { workspace = true }
3333
fc-rpc-core = { workspace = true }
3434
fc-storage = { workspace = true }
@@ -53,8 +53,8 @@ sc-cli = { workspace = true }
5353
sc-client-api = { workspace = true }
5454
sc-consensus = { workspace = true }
5555
sc-consensus-babe = { workspace = true }
56+
sc-consensus-grandpa = { workspace = true }
5657
sc-executor = { workspace = true }
57-
sc-finality-grandpa = { workspace = true }
5858
sc-service = { workspace = true }
5959
sc-telemetry = { workspace = true }
6060
sc-transaction-pool = { workspace = true }
@@ -63,8 +63,8 @@ serde_json = { workspace = true }
6363
sp-api = { workspace = true }
6464
sp-application-crypto = { workspace = true }
6565
sp-consensus-babe = { workspace = true }
66+
sp-consensus-grandpa = { workspace = true }
6667
sp-core = { workspace = true }
67-
sp-finality-grandpa = { workspace = true }
6868
sp-inherents = { workspace = true }
6969
sp-io = { workspace = true }
7070
sp-keyring = { workspace = true }
@@ -87,7 +87,8 @@ sp-io = { workspace = true }
8787
vergen = { workspace = true, features = ["cargo", "git", "gitcl"] }
8888

8989
[features]
90-
default = []
90+
default = ["rocksdb"]
91+
rocksdb = ["fc-db/rocksdb"]
9192
runtime-benchmarks = [
9293
"frame-benchmarking-cli/runtime-benchmarks",
9394
"frame-benchmarking/runtime-benchmarks",

crates/humanode-peer/src/chain_spec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use sc_chain_spec_derive::{ChainSpecExtension, ChainSpecGroup};
1515
use sc_service::ChainType;
1616
use serde::{Deserialize, Serialize};
1717
use sp_consensus_babe::AuthorityId as BabeId;
18-
use sp_finality_grandpa::AuthorityId as GrandpaId;
18+
use sp_consensus_grandpa::AuthorityId as GrandpaId;
1919
use sp_runtime::{app_crypto::sr25519, traits::Verify};
2020

2121
/// The concrete chain spec type we're using for the humanode network.

crates/humanode-peer/src/cli/config.rs

+15
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
5454
execute_gas_limit_multiplier: params.execute_gas_limit_multiplier,
5555
});
5656

57+
let fb_params = self.frontier_backend();
58+
let frontier_backend = configuration::FrontierBackend {
59+
frontier_backend_type: fb_params.frontier_backend_type,
60+
frontier_sql_backend_pool_size: fb_params.frontier_sql_backend_pool_size,
61+
frontier_sql_backend_num_ops_timeout: fb_params.frontier_sql_backend_num_ops_timeout,
62+
frontier_sql_backend_thread_count: fb_params.frontier_sql_backend_thread_count,
63+
frontier_sql_backend_cache_size: fb_params.frontier_sql_backend_cache_size,
64+
};
65+
5766
let time_warp = self.time_warp_params().and_then(|params| {
5867
params
5968
.time_warp_fork_timestamp
@@ -71,6 +80,7 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
7180
substrate,
7281
bioauth_flow,
7382
ethereum_rpc,
83+
frontier_backend,
7484
time_warp,
7585
})
7686
}
@@ -85,6 +95,11 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
8595
None
8696
}
8797

98+
/// Provide the Frontier backend params.
99+
fn frontier_backend(&self) -> params::FrontierBackendParams {
100+
Default::default()
101+
}
102+
88103
/// Provide the time warp related params, if available.
89104
fn time_warp_params(&self) -> Option<&params::TimeWarpParams> {
90105
None

crates/humanode-peer/src/cli/params.rs

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Shared CLI parameters.
22
3+
use crate::configuration::FrontierBackendType;
4+
35
/// Possible RPC URL scheme preference options.
46
#[derive(Debug, clap::ValueEnum, Clone)]
57
pub enum RpcUrlSchemePreference {
@@ -75,6 +77,31 @@ pub struct EthereumRpcParams {
7577
pub execute_gas_limit_multiplier: u64,
7678
}
7779

80+
/// Shared CLI parameters used to configure Frontier backend.
81+
#[derive(Debug, Default, clap::Parser, Clone)]
82+
pub struct FrontierBackendParams {
83+
/// Sets the frontier backend type (KeyValue or Sql).
84+
#[arg(long, value_enum, ignore_case = true, default_value_t = FrontierBackendType::default())]
85+
pub frontier_backend_type: FrontierBackendType,
86+
87+
/// Sets the SQL backend's pool size.
88+
#[arg(long, default_value = "100")]
89+
pub frontier_sql_backend_pool_size: u32,
90+
91+
/// Sets the SQL backend's query timeout in number of VM ops.
92+
#[arg(long, default_value = "10000000")]
93+
pub frontier_sql_backend_num_ops_timeout: u32,
94+
95+
/// Sets the SQL backend's auxiliary thread limit.
96+
#[arg(long, default_value = "4")]
97+
pub frontier_sql_backend_thread_count: u32,
98+
99+
/// Sets the SQL backend's query timeout in number of VM ops.
100+
/// Default value is 200MB.
101+
#[arg(long, default_value = "209715200")]
102+
pub frontier_sql_backend_cache_size: u64,
103+
}
104+
78105
/// Shared CLI parameters used to configure time warp mode.
79106
#[derive(Debug, clap::Parser, Clone)]
80107
pub struct TimeWarpParams {

crates/humanode-peer/src/cli/run.rs

+54-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use frame_benchmarking_cli::*;
66
use humanode_runtime::Block;
77
#[cfg(feature = "runtime-benchmarks")]
88
use humanode_runtime::Runtime;
9-
use sc_service::PartialComponents;
9+
use sc_service::{DatabaseSource, PartialComponents};
1010
#[cfg(feature = "runtime-benchmarks")]
1111
use sp_core::Get;
1212
#[cfg(feature = "try-runtime")]
@@ -18,7 +18,7 @@ use {
1818
use super::{bioauth, Root, Subcommand};
1919
#[cfg(feature = "runtime-benchmarks")]
2020
use crate::benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder};
21-
use crate::service;
21+
use crate::{configuration, service};
2222

2323
/// Parse command line arguments and run the requested operation.
2424
pub async fn run() -> sc_cli::Result<()> {
@@ -86,7 +86,10 @@ pub async fn run() -> sc_cli::Result<()> {
8686
}
8787
Some(Subcommand::PurgeChain(cmd)) => {
8888
let runner = root.create_humanode_runner(cmd)?;
89-
runner.sync_run(|config| cmd.run(config.substrate.database))
89+
runner.sync_run(|config| {
90+
remove_frontier_offchain_db(cmd, &config)?;
91+
cmd.run(config.substrate.database)
92+
})
9093
}
9194
Some(Subcommand::Revert(cmd)) => {
9295
let runner = root.create_humanode_runner(cmd)?;
@@ -100,7 +103,7 @@ pub async fn run() -> sc_cli::Result<()> {
100103
} = service::new_partial(&config)?;
101104
let aux_revert = Box::new(|client, backend, blocks| {
102105
sc_consensus_babe::revert(Arc::clone(&client), backend, blocks)?;
103-
sc_finality_grandpa::revert(client, blocks)?;
106+
sc_consensus_grandpa::revert(client, blocks)?;
104107
Ok(())
105108
});
106109
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
@@ -230,7 +233,12 @@ pub async fn run() -> sc_cli::Result<()> {
230233
let runner = root.create_humanode_runner(cmd)?;
231234
runner.sync_run(|config| {
232235
let partial = service::new_partial(&config)?;
233-
let frontier_backend = partial.other.4;
236+
let frontier_backend = match partial.other.4 {
237+
fc_db::Backend::KeyValue(kv_fb) => Arc::new(kv_fb),
238+
_ => {
239+
panic!("Only fc_db::Backend::KeyValue supported for FrontierDb command")
240+
}
241+
};
234242
cmd.run(partial.client, frontier_backend)
235243
})
236244
}
@@ -297,3 +305,44 @@ fn print_build_info() {
297305
crate::build_info::CARGO_FEATURES
298306
);
299307
}
308+
309+
/// Remove Frontier offchain db.
310+
fn remove_frontier_offchain_db(
311+
cmd: &sc_cli::PurgeChainCmd,
312+
config: &configuration::Configuration,
313+
) -> sc_cli::Result<()> {
314+
let fdb_config_dir = service::frontier::db_config_dir(&config.substrate);
315+
316+
match config.frontier_backend.frontier_backend_type {
317+
crate::configuration::FrontierBackendType::KeyValue => {
318+
let frontier_database_config = match config.substrate.database {
319+
DatabaseSource::RocksDb { .. } => DatabaseSource::RocksDb {
320+
path: fc_db::kv::frontier_database_dir(&fdb_config_dir, "db"),
321+
cache_size: 0,
322+
},
323+
DatabaseSource::ParityDb { .. } => DatabaseSource::ParityDb {
324+
path: fc_db::kv::frontier_database_dir(&fdb_config_dir, "paritydb"),
325+
},
326+
_ => panic!("frontier supports either rocksdb or paritydb"),
327+
};
328+
cmd.run(frontier_database_config)?;
329+
}
330+
crate::configuration::FrontierBackendType::Sql => {
331+
let db_path = fdb_config_dir.join("sql");
332+
333+
match std::fs::remove_dir_all(&db_path) {
334+
Ok(_) => {
335+
tracing::info!("{:?} removed.", &db_path);
336+
}
337+
Err(ref err) if err.kind() == std::io::ErrorKind::NotFound => {
338+
tracing::error!("{:?} did not exist.", &db_path);
339+
}
340+
Err(err) => {
341+
return Err(format!("Cannot purge `{:?}` database: {:?}", db_path, err).into())
342+
}
343+
};
344+
}
345+
};
346+
347+
Ok(())
348+
}

crates/humanode-peer/src/configuration.rs

+32
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub struct Configuration {
2121
/// Ethereum RPC configuration.
2222
pub ethereum_rpc: Option<EthereumRpc>,
2323

24+
/// Frontier backend configuration.
25+
pub frontier_backend: FrontierBackend,
26+
2427
/// Time warp mode configuration.
2528
/// If not defined, time warp mode isn't enabled.
2629
pub time_warp: Option<TimeWarp>,
@@ -73,3 +76,32 @@ pub struct EthereumRpc {
7376
/// block.gas_limit * execute_gas_limit_multiplier.
7477
pub execute_gas_limit_multiplier: u64,
7578
}
79+
80+
/// Frontier backend configuration parameters.
81+
pub struct FrontierBackend {
82+
/// Sets the frontier backend type (KeyValue or Sql).
83+
pub frontier_backend_type: FrontierBackendType,
84+
85+
/// Sets the SQL backend's pool size.
86+
pub frontier_sql_backend_pool_size: u32,
87+
88+
/// Sets the SQL backend's query timeout in number of VM ops.
89+
pub frontier_sql_backend_num_ops_timeout: u32,
90+
91+
/// Sets the SQL backend's auxiliary thread limit.
92+
pub frontier_sql_backend_thread_count: u32,
93+
94+
/// Sets the SQL backend's query timeout in number of VM ops.
95+
/// Default value is 200MB.
96+
pub frontier_sql_backend_cache_size: u64,
97+
}
98+
99+
/// Avalailable frontier backend types.
100+
#[derive(Default, Debug, Copy, Clone, clap::ValueEnum)]
101+
pub enum FrontierBackendType {
102+
/// Either RocksDb or ParityDb as per inherited from the global backend settings.
103+
#[default]
104+
KeyValue,
105+
/// Sql database with custom log indexing.
106+
Sql,
107+
}

crates/humanode-peer/src/service/frontier.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
//! The Frontier related stuff.
22
3+
use std::{path::Path, sync::Arc};
4+
5+
use fc_storage::OverrideHandle;
36
use humanode_runtime::opaque::Block;
47
use sc_cli::SubstrateCli;
58
use sc_client_api::backend::Backend;
6-
use sc_service::BasePath;
9+
use sc_service::{BasePath, Configuration};
10+
11+
use super::{FrontierBackend, FullClient, ServiceError};
12+
use crate::configuration::{self, FrontierBackendType};
713

814
/// Create frontier dir.
915
pub fn db_config_dir(config: &sc_service::Configuration) -> std::path::PathBuf {
@@ -17,6 +23,45 @@ pub fn db_config_dir(config: &sc_service::Configuration) -> std::path::PathBuf {
1723
})
1824
}
1925

26+
/// Create frontier backend.
27+
pub fn backend(
28+
config: &Configuration,
29+
client: Arc<FullClient>,
30+
fb_config: &configuration::FrontierBackend,
31+
eth_overrides: Arc<OverrideHandle<Block>>,
32+
) -> Result<FrontierBackend, ServiceError> {
33+
match fb_config.frontier_backend_type {
34+
FrontierBackendType::KeyValue => Ok(FrontierBackend::KeyValue(fc_db::kv::Backend::open(
35+
Arc::clone(&client),
36+
&config.database,
37+
&db_config_dir(config),
38+
)?)),
39+
FrontierBackendType::Sql => {
40+
let db_path = db_config_dir(config).join("sql");
41+
std::fs::create_dir_all(&db_path)?;
42+
43+
let backend = futures::executor::block_on(fc_db::sql::Backend::new(
44+
fc_db::sql::BackendConfig::Sqlite(fc_db::sql::SqliteBackendConfig {
45+
path: Path::new("sqlite:///")
46+
.join(db_path)
47+
.join("frontier.db3")
48+
.to_str()
49+
.ok_or(ServiceError::Other("invalid sqlite path".to_owned()))?,
50+
create_if_missing: true,
51+
thread_count: fb_config.frontier_sql_backend_thread_count,
52+
cache_size: fb_config.frontier_sql_backend_cache_size,
53+
}),
54+
fb_config.frontier_sql_backend_pool_size,
55+
std::num::NonZeroU32::new(fb_config.frontier_sql_backend_num_ops_timeout),
56+
Arc::clone(&eth_overrides),
57+
))
58+
.map_err(|err| ServiceError::Application(err.into()))?;
59+
60+
Ok(FrontierBackend::Sql(backend))
61+
}
62+
}
63+
}
64+
2065
/// Default ethereum config.
2166
pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);
2267

0 commit comments

Comments
 (0)