Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the frontier part #1154

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion node/src/frontier_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ 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
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)]
Expand All @@ -54,6 +57,8 @@ pub fn spawn_frontier_tasks<B, BE, C>(
overrides: Arc<OverrideHandle<B>>,
fee_history_cache: FeeHistoryCache,
fee_history_cache_limit: FeeHistoryCacheLimit,
sync: Arc<SyncingService<B>>,
pubsub_notification_sinks: Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<B>>>,
eth_rpc_config: EthRpcConfig,
) -> RpcRequesters
where
Expand Down Expand Up @@ -85,6 +90,8 @@ where
3,
0,
SyncStrategy::Parachain,
sync,
pubsub_notification_sinks,
)
.for_each(|()| future::ready(())),
);
Expand Down
40 changes: 34 additions & 6 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,7 +47,9 @@ pub struct FullDeps<C, P, A: sc_transaction_pool::ChainApi> {
/// The Node authority flag
pub is_authority: bool,
/// Network service
pub network: Arc<sc_network_sync::SyncingService<Block>>,
pub network: Arc<sc_network::NetworkService<Block, Hash>>,
/// Chain syncing service
pub sync: Arc<sc_network_sync::SyncingService<Block>>,
/// EthFilterApi pool.
pub filter_pool: Option<fc_rpc_core::types::FilterPool>,
/// Backend.
Expand All @@ -62,6 +64,8 @@ pub struct FullDeps<C, P, A: sc_transaction_pool::ChainApi> {
pub overrides: Arc<fc_rpc::OverrideHandle<Block>>,
/// Cache for Ethereum block data.
pub block_data_cache: Arc<fc_rpc::EthBlockDataCacheTask<Block>>,
/// Mandated parent hashes for a given block hash.
pub forced_parent_hashes: Option<BTreeMap<sp_core::H256, sp_core::H256>>,
}

/// EVM tracing rpc server config
Expand All @@ -70,10 +74,28 @@ pub struct TracingConfig {
pub trace_filter_max_count: u32,
}

/// Default Ethereum RPC config
pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);

impl<C, BE> fc_rpc::EthConfig<Block, C> for DefaultEthConfig<C, BE>
where
C: sc_client_api::StorageProvider<Block, BE> + Sync + Send + 'static,
BE: sc_client_api::Backend<Block> + 'static,
{
type EstimateGasAdapter = ();
type RuntimeStorageOverride =
fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride<Block, C, BE>;
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, BE, A>(
pub fn create_full<C, P, BE, A, EC: fc_rpc::EthConfig<Block, C>>(
deps: FullDeps<C, P, A>,
subscription_task_executor: sc_rpc::SubscriptionTaskExecutor,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
>,
>,
maybe_tracing_config: Option<TracingConfig>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
Expand All @@ -82,9 +104,10 @@ where
C: 'static
+ Send
+ Sync
+ sc_client_api::backend::AuxStore
+ sc_client_api::backend::StorageProvider<Block, BE>
+ sc_client_api::BlockchainEvents<Block>
+ sc_client_api::backend::AuxStore
+ sp_api::CallApiAt<Block>
+ sp_api::ProvideRuntimeApi<Block>
+ sp_blockchain::HeaderBackend<Block>
+ sp_blockchain::HeaderMetadata<Block, Error = sp_blockchain::Error>,
Expand Down Expand Up @@ -114,13 +137,15 @@ where
deny_unsafe,
is_authority,
network,
sync,
filter_pool,
backend,
max_past_logs,
fee_history_cache,
fee_history_cache_limit,
overrides,
block_data_cache,
forced_parent_hashes,
} = deps;

module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
Expand All @@ -131,7 +156,7 @@ where
pool.clone(),
graph,
<Option<NoTransactionConverter>>::None,
network.clone(),
sync.clone(),
vec![],
overrides.clone(),
backend.clone(),
Expand All @@ -140,7 +165,9 @@ where
fee_history_cache,
fee_history_cache_limit,
10,
forced_parent_hashes,
)
.replace_config::<EC>()
.into_rpc(),
)?;

Expand All @@ -162,9 +189,10 @@ where
EthPubSub::new(
pool,
client.clone(),
network.clone(),
sync.clone(),
subscription_task_executor,
overrides,
pubsub_notification_sinks,
)
.into_rpc(),
)?;
Expand Down
40 changes: 36 additions & 4 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block>,
> = 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(
Expand All @@ -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 = {
Expand All @@ -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 {
Expand All @@ -383,29 +390,38 @@ 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,
fee_history_cache: fee_history_cache.clone(),
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,
}),
)
.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)
}
})
};
Expand Down Expand Up @@ -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<Block>,
> = 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(
Expand All @@ -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 = {
Expand All @@ -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 {
Expand All @@ -870,29 +893,38 @@ 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,
fee_history_cache: fee_history_cache.clone(),
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,
}),
)
.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)
}
})
};
Expand Down