From 07a893e9ac4173a2b4ee4be2d2d66bf7de669a94 Mon Sep 17 00:00:00 2001 From: bear Date: Tue, 23 May 2023 11:51:52 +0800 Subject: [PATCH 1/2] Fix compile --- node/src/frontier_service.rs | 9 ++++++++ node/src/rpc.rs | 37 ++++++++++++++++++++++++++++----- node/src/service/mod.rs | 40 ++++++++++++++++++++++++++++++++---- 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/node/src/frontier_service.rs b/node/src/frontier_service.rs index d430c3e60..e95ce1b56 100644 --- a/node/src/frontier_service.rs +++ b/node/src/frontier_service.rs @@ -36,6 +36,7 @@ use moonbeam_rpc_debug::{DebugHandler, DebugRequester}; use moonbeam_rpc_trace::{CacheRequester as TraceFilterCacheRequester, CacheTask}; // substrate use sc_cli::SubstrateCli; +use sc_network_sync::SyncingService; use sc_service::{BasePath, Configuration, TaskManager}; #[derive(Clone)] @@ -54,6 +55,12 @@ pub fn spawn_frontier_tasks( overrides: Arc>, fee_history_cache: FeeHistoryCache, fee_history_cache_limit: FeeHistoryCacheLimit, + sync: Arc>, + pubsub_notification_sinks: Arc< + fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + >, + >, eth_rpc_config: EthRpcConfig, ) -> RpcRequesters where @@ -85,6 +92,8 @@ where 3, 0, SyncStrategy::Parachain, + sync, + pubsub_notification_sinks, ) .for_each(|()| future::ready(())), ); diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 420983543..f10460b16 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -24,7 +24,7 @@ pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; // std -use std::sync::Arc; +use std::{collections::BTreeMap, sync::Arc}; // darwinia use dc_primitives::*; // moonbeam @@ -47,7 +47,9 @@ pub struct FullDeps { /// The Node authority flag pub is_authority: bool, /// Network service - pub network: Arc>, + pub network: Arc>, + /// Chain syncing service + pub sync: Arc>, /// EthFilterApi pool. pub filter_pool: Option, /// Backend. @@ -62,6 +64,8 @@ pub struct FullDeps { pub overrides: Arc>, /// Cache for Ethereum block data. pub block_data_cache: Arc>, + /// Mandated parent hashes for a given block hash. + pub forced_parent_hashes: Option>, } /// EVM tracing rpc server config @@ -70,10 +74,27 @@ pub struct TracingConfig { pub trace_filter_max_count: u32, } +pub struct DefaultEthConfig(std::marker::PhantomData<(C, BE)>); + +impl fc_rpc::EthConfig for DefaultEthConfig +where + C: sc_client_api::StorageProvider + Sync + Send + 'static, + BE: sc_client_api::Backend + 'static, +{ + type EstimateGasAdapter = (); + type RuntimeStorageOverride = + fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride; +} + /// Instantiate all RPC extensions. -pub fn create_full( +pub fn create_full>( deps: FullDeps, subscription_task_executor: sc_rpc::SubscriptionTaskExecutor, + pubsub_notification_sinks: Arc< + fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + >, + >, maybe_tracing_config: Option, ) -> Result> where @@ -86,6 +107,7 @@ where + sc_client_api::BlockchainEvents + sc_client_api::backend::AuxStore + sp_api::ProvideRuntimeApi + + sp_api::CallApiAt + sp_blockchain::HeaderBackend + sp_blockchain::HeaderMetadata, C::Api: fp_rpc::ConvertTransactionRuntimeApi @@ -114,6 +136,7 @@ where deny_unsafe, is_authority, network, + sync, filter_pool, backend, max_past_logs, @@ -121,6 +144,7 @@ where fee_history_cache_limit, overrides, block_data_cache, + forced_parent_hashes, } = deps; module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?; @@ -131,7 +155,7 @@ where pool.clone(), graph, >::None, - network.clone(), + sync.clone(), vec![], overrides.clone(), backend.clone(), @@ -140,7 +164,9 @@ where fee_history_cache, fee_history_cache_limit, 10, + forced_parent_hashes, ) + .replace_config::() .into_rpc(), )?; @@ -162,9 +188,10 @@ where EthPubSub::new( pool, client.clone(), - network.clone(), + sync.clone(), subscription_task_executor, overrides, + pubsub_notification_sinks, ) .into_rpc(), )?; diff --git a/node/src/service/mod.rs b/node/src/service/mod.rs index 12700a735..e1cbf8de3 100644 --- a/node/src/service/mod.rs +++ b/node/src/service/mod.rs @@ -350,6 +350,10 @@ where eth_rpc_config.eth_statuses_cache, prometheus_registry.clone(), )); + let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + > = Default::default(); + let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks); // for ethereum-compatibility rpc. parachain_config.rpc_id_provider = Some(Box::new(fc_rpc::EthereumSubIdProvider)); let tracing_requesters = frontier_service::spawn_frontier_tasks( @@ -361,6 +365,8 @@ where overrides.clone(), fee_history_cache.clone(), fee_history_cache_limit, + sync_service.clone(), + pubsub_notification_sinks.clone(), eth_rpc_config.clone(), ); let rpc_builder = { @@ -374,6 +380,7 @@ where let max_past_logs = eth_rpc_config.max_past_logs; let collator = parachain_config.role.is_authority(); let eth_rpc_config = eth_rpc_config.clone(); + let sync_service = sync_service.clone(); Box::new(move |deny_unsafe, subscription_task_executor| { let deps = crate::rpc::FullDeps { @@ -383,6 +390,7 @@ where deny_unsafe, is_authority: collator, network: network.clone(), + sync: sync_service.clone(), filter_pool: filter_pool.clone(), backend: frontier_backend.clone(), max_past_logs, @@ -390,14 +398,16 @@ where fee_history_cache_limit, overrides: overrides.clone(), block_data_cache: block_data_cache.clone(), + forced_parent_hashes: None, }; if eth_rpc_config.tracing_api.contains(&TracingApi::Debug) || eth_rpc_config.tracing_api.contains(&TracingApi::Trace) { - crate::rpc::create_full( + crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>( deps, subscription_task_executor, + pubsub_notification_sinks.clone(), Some(crate::rpc::TracingConfig { tracing_requesters: tracing_requesters.clone(), trace_filter_max_count: eth_rpc_config.tracing_max_count, @@ -405,7 +415,13 @@ where ) .map_err(Into::into) } else { - crate::rpc::create_full(deps, subscription_task_executor, None).map_err(Into::into) + crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>( + deps, + subscription_task_executor, + pubsub_notification_sinks.clone(), + None, + ) + .map_err(Into::into) } }) }; @@ -837,6 +853,10 @@ where eth_rpc_config.eth_statuses_cache, prometheus_registry, )); + let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + > = Default::default(); + let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks); // for ethereum-compatibility rpc. config.rpc_id_provider = Some(Box::new(fc_rpc::EthereumSubIdProvider)); let tracing_requesters = frontier_service::spawn_frontier_tasks( @@ -848,6 +868,8 @@ where overrides.clone(), fee_history_cache.clone(), fee_history_cache_limit, + sync_service.clone(), + pubsub_notification_sinks.clone(), eth_rpc_config.clone(), ); let rpc_extensions_builder = { @@ -861,6 +883,7 @@ where let max_past_logs = eth_rpc_config.max_past_logs; let collator = config.role.is_authority(); let eth_rpc_config = eth_rpc_config.clone(); + let sync_service = sync_service.clone(); Box::new(move |deny_unsafe, subscription_task_executor| { let deps = crate::rpc::FullDeps { @@ -870,6 +893,7 @@ where deny_unsafe, is_authority: collator, network: network.clone(), + sync: sync_service.clone(), filter_pool: filter_pool.clone(), backend: frontier_backend.clone(), max_past_logs, @@ -877,14 +901,16 @@ where fee_history_cache_limit, overrides: overrides.clone(), block_data_cache: block_data_cache.clone(), + forced_parent_hashes: None, }; if eth_rpc_config.tracing_api.contains(&TracingApi::Debug) || eth_rpc_config.tracing_api.contains(&TracingApi::Trace) { - crate::rpc::create_full( + crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>( deps, subscription_task_executor, + pubsub_notification_sinks.clone(), Some(crate::rpc::TracingConfig { tracing_requesters: tracing_requesters.clone(), trace_filter_max_count: eth_rpc_config.tracing_max_count, @@ -892,7 +918,13 @@ where ) .map_err(Into::into) } else { - crate::rpc::create_full(deps, subscription_task_executor, None).map_err(Into::into) + crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>( + deps, + subscription_task_executor, + pubsub_notification_sinks.clone(), + None, + ) + .map_err(Into::into) } }) }; From 4532fe90c0576c6d4b9b07a3dc17ee843c4239a7 Mon Sep 17 00:00:00 2001 From: bear Date: Tue, 23 May 2023 13:36:12 +0800 Subject: [PATCH 2/2] Format --- node/src/frontier_service.rs | 10 ++++------ node/src/rpc.rs | 5 +++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/node/src/frontier_service.rs b/node/src/frontier_service.rs index e95ce1b56..be983371b 100644 --- a/node/src/frontier_service.rs +++ b/node/src/frontier_service.rs @@ -28,7 +28,9 @@ use crate::cli::{Cli, EthRpcConfig, TracingApi}; use dc_primitives::{BlockNumber, Hash, Hashing}; // frontier use fc_db::Backend as FrontierBackend; -use fc_mapping_sync::{MappingSyncWorker, SyncStrategy}; +use fc_mapping_sync::{ + EthereumBlockNotification, EthereumBlockNotificationSinks, MappingSyncWorker, SyncStrategy, +}; use fc_rpc::{EthTask, OverrideHandle}; use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; // moonbeam @@ -56,11 +58,7 @@ pub fn spawn_frontier_tasks( fee_history_cache: FeeHistoryCache, fee_history_cache_limit: FeeHistoryCacheLimit, sync: Arc>, - pubsub_notification_sinks: Arc< - fc_mapping_sync::EthereumBlockNotificationSinks< - fc_mapping_sync::EthereumBlockNotification, - >, - >, + pubsub_notification_sinks: Arc>>, eth_rpc_config: EthRpcConfig, ) -> RpcRequesters where diff --git a/node/src/rpc.rs b/node/src/rpc.rs index f10460b16..c0ff2280e 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -74,6 +74,7 @@ pub struct TracingConfig { pub trace_filter_max_count: u32, } +/// Default Ethereum RPC config pub struct DefaultEthConfig(std::marker::PhantomData<(C, BE)>); impl fc_rpc::EthConfig for DefaultEthConfig @@ -103,11 +104,11 @@ where C: 'static + Send + Sync + + sc_client_api::backend::AuxStore + sc_client_api::backend::StorageProvider + sc_client_api::BlockchainEvents - + sc_client_api::backend::AuxStore - + sp_api::ProvideRuntimeApi + sp_api::CallApiAt + + sp_api::ProvideRuntimeApi + sp_blockchain::HeaderBackend + sp_blockchain::HeaderMetadata, C::Api: fp_rpc::ConvertTransactionRuntimeApi