Skip to content

Commit

Permalink
Fix the compile
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Apr 23, 2024
1 parent f43f826 commit b37678d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
5 changes: 3 additions & 2 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
pub use sc_client_db::DatabaseSource;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
use std::sync::Arc;

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

#[derive(Clone)]
pub enum Backend<Block: BlockT, C: HeaderBackend<Block>> {
KeyValue(kv::Backend<Block, C>),
KeyValue(Arc<kv::Backend<Block, C>>),
#[cfg(feature = "sql")]
Sql(sql::Backend<Block>),
Sql(Arc<sql::Backend<Block>>),
}
2 changes: 1 addition & 1 deletion template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn run() -> sc_cli::Result<()> {
let (client, _, _, _, frontier_backend) =
service::new_chain_ops(&mut config, &cli.eth)?;
let frontier_backend = match frontier_backend {
fc_db::Backend::KeyValue(kv) => std::sync::Arc::new(kv),
fc_db::Backend::KeyValue(kv) => kv,
_ => panic!("Only fc_db::Backend::KeyValue supported"),
};
cmd.run(client, frontier_backend)
Expand Down
10 changes: 5 additions & 5 deletions template/node/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use futures::{future, prelude::*};
use sc_client_api::BlockchainEvents;
use sc_executor::NativeExecutionDispatch;
use sc_network_sync::SyncingService;
use sp_blockchain::HeaderBackend;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sp_api::ConstructRuntimeApi;
use sp_blockchain::HeaderBackend;
// Frontier
pub use fc_consensus::FrontierBlockImport;
use fc_rpc::{EthTask, OverrideHandle};
Expand Down Expand Up @@ -127,7 +127,7 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
task_manager: &TaskManager,
client: Arc<FullClient<RuntimeApi, Executor>>,
backend: Arc<FullBackend>,
frontier_backend: FrontierBackend<FullClient<RuntimeApi, Executor>>,
frontier_backend: Arc<FrontierBackend<FullClient<RuntimeApi, Executor>>>,
filter_pool: Option<FilterPool>,
overrides: Arc<OverrideHandle<Block>>,
fee_history_cache: FeeHistoryCache,
Expand All @@ -146,7 +146,7 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
FullClient<RuntimeApi, Executor>: HeaderBackend<Block>,
{
// Spawn main mapping sync worker background task.
match frontier_backend {
match &*frontier_backend {
fc_db::Backend::KeyValue(b) => {
task_manager.spawn_essential_handle().spawn(
"frontier-mapping-sync-worker",
Expand All @@ -157,7 +157,7 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
client.clone(),
backend,
overrides.clone(),
Arc::new(b),
b.clone(),
3,
0,
fc_mapping_sync::SyncStrategy::Normal,
Expand All @@ -174,7 +174,7 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
fc_mapping_sync::sql::SyncWorker::run(
client.clone(),
backend,
Arc::new(b),
b.clone(),
client.import_notification_stream(),
fc_mapping_sync::sql::SyncWorkerConfig {
read_notification_timeout: Duration::from_secs(10),
Expand Down
4 changes: 2 additions & 2 deletions template/node/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use fp_rpc::{ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRP
use crate::eth::FrontierBackend;

/// Extra dependencies for Ethereum compatibility.
pub struct EthDeps<B: BlockT, C: HeaderBackend<B>, P, A: ChainApi, CT, CIDP> {
pub struct EthDeps<B: BlockT, C, P, A: ChainApi, CT, CIDP> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand All @@ -46,7 +46,7 @@ pub struct EthDeps<B: BlockT, C: HeaderBackend<B>, P, A: ChainApi, CT, CIDP> {
/// Chain syncing service
pub sync: Arc<SyncingService<B>>,
/// Frontier Backend.
pub frontier_backend: Arc<FrontierBackend<C>>,
pub frontier_backend: Arc<dyn fc_api::Backend<B>>,
/// Ethereum data access overrides.
pub overrides: Arc<OverrideHandle<B>>,
/// Cache for Ethereum block data.
Expand Down
23 changes: 11 additions & 12 deletions template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::{cell::RefCell, path::Path, sync::Arc, time::Duration};

use fc_rpc::frontier_backend_client;
use futures::{channel::mpsc, prelude::*};
// Substrate
use prometheus_endpoint::Registry;
Expand Down Expand Up @@ -119,11 +120,11 @@ where

let overrides = crate::rpc::overrides_handle(client.clone());
let frontier_backend = match eth_config.frontier_backend_type {
BackendType::KeyValue => FrontierBackend::KeyValue(fc_db::kv::Backend::open(
BackendType::KeyValue => FrontierBackend::KeyValue(Arc::new(fc_db::kv::Backend::open(
Arc::clone(&client),
&config.database,
&db_config_dir(config),
)?),
)?)),
BackendType::Sql => {
let db_path = db_config_dir(config).join("sql");
std::fs::create_dir_all(&db_path).expect("failed creating sql db directory");
Expand All @@ -143,7 +144,7 @@ where
overrides.clone(),
))
.unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err));
FrontierBackend::Sql(backend)
FrontierBackend::Sql(Arc::new(backend))
}
};

Expand Down Expand Up @@ -365,10 +366,10 @@ where
> = Default::default();
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);

let frontier_backend_arc = Arc::new(frontier_backend);

// for ethereum-compatibility rpc.
config.rpc_id_provider = Some(Box::new(fc_rpc::EthereumSubIdProvider));

let frontier_backend_arc: Arc<FrontierBackend<FullClient<RuntimeApi, Executor>>> = Arc::new(frontier_backend);
let rpc_builder = {
let client = client.clone();
let pool = transaction_pool.clone();
Expand All @@ -381,7 +382,6 @@ where
let execute_gas_limit_multiplier = eth_config.execute_gas_limit_multiplier;
let filter_pool = filter_pool.clone();
let frontier_backend = frontier_backend_arc.clone();
// let frontier_backend = frontier_backend.clone();
let pubsub_notification_sinks = pubsub_notification_sinks.clone();
let overrides = overrides.clone();
let fee_history_cache = fee_history_cache.clone();
Expand Down Expand Up @@ -417,11 +417,10 @@ where
enable_dev_signer,
network: network.clone(),
sync: sync_service.clone(),
// frontier_backend: match frontier_backend.clone() {
// fc_db::Backend::KeyValue(b) => Arc::new(b),
// fc_db::Backend::Sql(b) => Arc::new(b.into()),
// },
frontier_backend: frontier_backend_arc.clone(),
frontier_backend: match &*frontier_backend {
fc_db::Backend::KeyValue(b) => b.clone(),
fc_db::Backend::Sql(b) => b.clone(),
},
overrides: overrides.clone(),
block_data_cache: block_data_cache.clone(),
filter_pool: filter_pool.clone(),
Expand Down Expand Up @@ -471,7 +470,7 @@ where
&task_manager,
client.clone(),
backend,
frontier_backend,
frontier_backend_arc,
filter_pool,
overrides,
fee_history_cache,
Expand Down

0 comments on commit b37678d

Please sign in to comment.