difftreelog
refactor ethereum RPC/tasks initialization
in: master
7 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6507,11 +6507,13 @@
"frame-benchmarking",
"frame-support",
"frame-system",
+ "hex-literal",
"parity-scale-codec",
"scale-info",
"smallvec",
"sp-arithmetic",
"sp-core",
+ "sp-io",
"sp-std",
"xcm",
]
@@ -13841,9 +13843,11 @@
"fc-rpc",
"fc-rpc-core",
"fp-rpc",
+ "fp-storage",
"frame-benchmarking",
"frame-benchmarking-cli",
"futures",
+ "jsonrpsee",
"log",
"opal-runtime",
"pallet-transaction-payment-rpc-runtime-api",
@@ -13861,6 +13865,7 @@
"sc-executor",
"sc-network",
"sc-network-sync",
+ "sc-rpc",
"sc-service",
"sc-sysinfo",
"sc-telemetry",
@@ -13906,9 +13911,9 @@
"fp-rpc",
"fp-storage",
"jsonrpsee",
+ "pallet-ethereum",
"pallet-transaction-payment-rpc",
"sc-client-api",
- "sc-consensus-grandpa",
"sc-network",
"sc-network-sync",
"sc-rpc",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -125,7 +125,6 @@
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
-sc-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -21,7 +21,7 @@
[dependencies]
clap = "4.1"
-futures = '0.3.17'
+futures = '0.3.28'
tokio = { version = "1.24", features = ["time"] }
serde_json = "1.0"
@@ -94,6 +94,9 @@
unique-rpc = { workspace = true }
up-pov-estimate-rpc = { workspace = true }
up-rpc = { workspace = true }
+jsonrpsee.workspace = true
+fp-storage.workspace = true
+sc-rpc.workspace = true
[build-dependencies]
substrate-build-script-utils = { workspace = true }
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -168,6 +168,7 @@
.collect(),
},
common: Default::default(),
+ configuration: Default::default(),
nonfungible: Default::default(),
treasury: Default::default(),
tokens: TokensConfig { balances: vec![] },
@@ -228,6 +229,7 @@
.to_vec(),
},
common: Default::default(),
+ configuration: Default::default(),
nonfungible: Default::default(),
balances: BalancesConfig {
balances: $endowed_accounts
node/cli/src/service.rsdiffbeforeafterboth20use std::collections::BTreeMap;20use std::collections::BTreeMap;21use std::time::Duration;21use std::time::Duration;22use std::pin::Pin;22use std::pin::Pin;23use fc_mapping_sync::EthereumBlockNotificationSinks;24use fc_rpc::EthBlockDataCacheTask;25use fc_rpc::EthTask;23use fc_rpc_core::types::FeeHistoryCache;26use fc_rpc_core::types::FeeHistoryCache;24use futures::{27use futures::{25 Stream, StreamExt,28 Stream, StreamExt,26 stream::select,29 stream::select,27 task::{Context, Poll},30 task::{Context, Poll},28};31};32use sc_rpc::SubscriptionTaskExecutor;29use sp_keystore::KeystorePtr;33use sp_keystore::KeystorePtr;30use tokio::time::Interval;34use tokio::time::Interval;35use jsonrpsee::RpcModule;313632use unique_rpc::overrides_handle;3334use serde::{Serialize, Deserialize};37use serde::{Serialize, Deserialize};353836// Cumulus Imports39// Cumulus Imports49use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;52use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;505351// Substrate Imports54// Substrate Imports52use sp_api::BlockT;55use sp_api::{BlockT, HeaderT, ProvideRuntimeApi, StateBackend};53use sc_executor::NativeElseWasmExecutor;56use sc_executor::NativeElseWasmExecutor;54use sc_executor::NativeExecutionDispatch;57use sc_executor::NativeExecutionDispatch;55use sc_network::NetworkBlock;58use sc_network::NetworkBlock;58use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};61use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};59use sp_runtime::traits::BlakeTwo256;62use sp_runtime::traits::BlakeTwo256;60use substrate_prometheus_endpoint::Registry;63use substrate_prometheus_endpoint::Registry;61use sc_client_api::BlockchainEvents;64use sc_client_api::{BlockchainEvents, BlockOf, Backend, AuxStore, StorageProvider};65use sp_blockchain::{HeaderBackend, HeaderMetadata, Error as BlockChainError};62use sc_consensus::ImportQueue;66use sc_consensus::ImportQueue;67use sp_core::H256;68use sp_block_builder::BlockBuilder;636964use polkadot_service::CollatorPair;70use polkadot_service::CollatorPair;657166// Frontier Imports72// Frontier Imports67use fc_rpc_core::types::FilterPool;73use fc_rpc_core::types::FilterPool;68use fc_mapping_sync::{kv::MappingSyncWorker, SyncStrategy};74use fc_mapping_sync::{kv::MappingSyncWorker, SyncStrategy};75use fc_rpc::{76 StorageOverride, OverrideHandle, SchemaV1Override, SchemaV2Override, SchemaV3Override,77 RuntimeApiStorageOverride,78};79use fp_rpc::EthereumRuntimeRPCApi;80use fp_storage::EthereumStorageSchema;698170use up_common::types::opaque::*;82use up_common::types::opaque::*;7183173 }185 }174}186}175187176pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(188pub fn open_frontier_backend<Block: BlockT, C: HeaderBackend<Block>>(177 client: Arc<C>,189 client: Arc<C>,178 config: &Configuration,190 config: &Configuration,179) -> Result<Arc<fc_db::kv::Backend<Block>>, String> {191) -> Result<Arc<fc_db::kv::Backend<Block>>, String> {213 FullSelectChain,225 FullSelectChain,214 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,226 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,215 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,227 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,216 (228 OtherPartial,217 Option<Telemetry>,218 Option<FilterPool>,219 Arc<fc_db::kv::Backend<Block>>,220 Option<TelemetryWorkerHandle>,221 FeeHistoryCache,222 ),223 >,229 >,224 sc_service::Error,230 sc_service::Error,225>231>242 sc_service::Error,248 sc_service::Error,243 >,249 >,244{250{245 let _telemetry = config246 .telemetry_endpoints247 .clone()248 .filter(|x| !x.is_empty())249 .map(|endpoints| -> Result<_, sc_telemetry::Error> {250 let worker = TelemetryWorker::new(16)?;251 let telemetry = worker.handle().new_telemetry(endpoints);252 Ok((worker, telemetry))253 })254 .transpose()?;255256 let telemetry = config251 let telemetry = config257 .telemetry_endpoints252 .telemetry_endpoints258 .clone()253 .clone()293 client.clone(),288 client.clone(),294 );289 );295290296 let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));291 let eth_filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));297292298 let frontier_backend = open_frontier_backend(client.clone(), config)?;293 let eth_backend = open_frontier_backend(client.clone(), config)?;299294300 let import_queue = build_import_queue(295 let import_queue = build_import_queue(301 client.clone(),296 client.clone(),304 telemetry.as_ref().map(|telemetry| telemetry.handle()),299 telemetry.as_ref().map(|telemetry| telemetry.handle()),305 &task_manager,300 &task_manager,306 )?;301 )?;307 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));308302309 let params = PartialComponents {303 let params = PartialComponents {310 backend,304 backend,314 task_manager,308 task_manager,315 transaction_pool,309 transaction_pool,316 select_chain,310 select_chain,317 other: (311 other: OtherPartial {318 telemetry,312 telemetry,319 filter_pool,313 eth_filter_pool,320 frontier_backend,314 eth_backend,321 telemetry_worker_handle,315 telemetry_worker_handle,322 fee_history_cache,316 },323 ),324 };317 };325318326 Ok(params)319 Ok(params)427420428 let params =421 let params =429 new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;422 new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;430 let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =423 let OtherPartial {424 mut telemetry,425 telemetry_worker_handle,426 eth_filter_pool,427 eth_backend,431 params.other;428 } = params.other;432 let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network);429 let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network);433430434 let client = params.client.clone();431 let client = params.client.clone();470467471 let select_chain = params.select_chain.clone();468 let select_chain = params.select_chain.clone();472469473 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(470 let runtime_id = parachain_config.chain_spec.runtime_id();474 task_manager.spawn_handle(),475 overrides_handle::<_, _, Runtime>(client.clone()),476 50,477 50,478 prometheus_registry.clone(),479 ));480471481 let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<472 // Frontier473 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));474 let fee_history_limit = 2048;475476 let eth_pubsub_notification_sinks: Arc<482 fc_mapping_sync::EthereumBlockNotification<Block>,477 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,483 > = Default::default();478 > = Default::default();484 let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);485479486 task_manager.spawn_essential_handle().spawn(480 let overrides = overrides_handle(client.clone());481 let eth_block_data_cache = spawn_frontier_tasks(487 "frontier-mapping-sync-worker",482 FrontierTaskParams {488 Some("frontier"),483 client: client.clone(),489 MappingSyncWorker::new(484 substrate_backend: backend.clone(),490 client.import_notification_stream(),485 eth_filter_pool: eth_filter_pool.clone(),491 Duration::new(6, 0),486 eth_backend: eth_backend.clone(),492 client.clone(),487 fee_history_limit,493 backend.clone(),488 fee_history_cache: fee_history_cache.clone(),494 overrides_handle::<_, _, Runtime>(client.clone()),489 task_manager: &task_manager,490 prometheus_registry: prometheus_registry.clone(),495 frontier_backend.clone(),491 overrides: overrides.clone(),496 3,492 sync_strategy: SyncStrategy::Parachain,497 0,498 SyncStrategy::Parachain,499 sync_service.clone(),493 },500 pubsub_notification_sinks.clone(),494 sync_service.clone(),501 )495 eth_pubsub_notification_sinks.clone(),502 .for_each(|()| futures::future::ready(())),503 );496 );504497505 let runtime_id = parachain_config.chain_spec.runtime_id();498 // Rpc506507 let rpc_builder = Box::new({499 let rpc_builder = Box::new({508 clone!(500 clone!(509 client,501 client,510 backend,502 backend,511 pubsub_notification_sinks,503 eth_backend,504 eth_pubsub_notification_sinks,505 fee_history_cache,506 eth_block_data_cache,507 overrides,512 transaction_pool,508 transaction_pool,513 network,509 network,514 sync_service,510 sync_service,515 frontier_backend,516 );511 );517 move |deny_unsafe, subscription_task_executor| {512 move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {518 clone!(513 clone!(519 backend,514 backend,515 eth_block_data_cache,516 client,517 eth_backend,518 eth_filter_pool,519 eth_pubsub_notification_sinks,520 fee_history_cache,521 eth_block_data_cache,522 network,520 runtime_id,523 runtime_id,521 client,522 transaction_pool,524 transaction_pool,523 filter_pool,524 network,525 select_chain,525 select_chain,526 block_data_cache,526 overrides,527 fee_history_cache,528 pubsub_notification_sinks,529 frontier_backend,530 );527 );531528532 #[cfg(not(feature = "pov-estimate"))]529 #[cfg(not(feature = "pov-estimate"))]533 let _ = backend;530 let _ = backend;534531532 let mut rpc_handle = RpcModule::new(());533535 let full_deps = unique_rpc::FullDeps {534 let full_deps = unique_rpc::FullDeps {535 client: client.clone(),536 runtime_id,536 runtime_id,537537538 #[cfg(feature = "pov-estimate")]538 #[cfg(feature = "pov-estimate")]546 #[cfg(feature = "pov-estimate")]546 #[cfg(feature = "pov-estimate")]547 backend,547 backend,548548549 eth_backend: frontier_backend,550 deny_unsafe,549 deny_unsafe,550 pool: transaction_pool.clone(),551 select_chain,552 };553554 unique_rpc::create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_handle, full_deps)?;555556 let eth_deps = unique_rpc::EthDeps {551 client,557 client,552 graph: transaction_pool.pool().clone(),558 graph: transaction_pool.pool().clone(),553 pool: transaction_pool,559 pool: transaction_pool,554 // TODO: Unhardcode560 is_authority: validator,555 enable_dev_signer: false,556 filter_pool,557 network,561 network,558 sync: sync_service.clone(),562 eth_backend,559 select_chain,560 is_authority: validator,561 // TODO: Unhardcode563 // TODO: Unhardcode562 max_past_logs: 10000,564 max_past_logs: 10000,563 block_data_cache,565 fee_history_limit,564 fee_history_cache,566 fee_history_cache,567 eth_block_data_cache,565 // TODO: Unhardcode568 // TODO: Unhardcode566 fee_history_limit: 2048,569 enable_dev_signer: false,567 pubsub_notification_sinks,570 eth_filter_pool,571 eth_pubsub_notification_sinks,572 overrides,573 sync: sync_service.clone(),568 };574 };569575570 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(576 unique_rpc::create_eth(577 &mut rpc_handle,571 full_deps,578 eth_deps,572 subscription_task_executor,579 subscription_task_executor.clone(),573 )580 )?;581574 .map_err(Into::into)582 Ok(rpc_handle)575 }583 }576 });584 });577585866 ))874 ))867}875}868876877pub struct OtherPartial {878 pub telemetry: Option<Telemetry>,879 pub telemetry_worker_handle: Option<TelemetryWorkerHandle>,880 pub eth_filter_pool: Option<FilterPool>,881 pub eth_backend: Arc<fc_db::kv::Backend<Block>>,882}883869/// Builds a new development service. This service uses instant seal, and mocks884/// Builds a new development service. This service uses instant seal, and mocks870/// the parachain inherent885/// the parachain inherent871pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(886pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(899{914{900 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};915 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};901 use fc_consensus::FrontierBlockImport;916 use fc_consensus::FrontierBlockImport;902 use sc_client_api::HeaderBackend;903917904 let sc_service::PartialComponents {918 let sc_service::PartialComponents {905 client,919 client,910 select_chain: maybe_select_chain,924 select_chain: maybe_select_chain,911 transaction_pool,925 transaction_pool,912 other:926 other:913 (telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),927 OtherPartial {928 telemetry,929 eth_filter_pool,930 eth_backend,931 telemetry_worker_handle: _,932 },914 } = new_partial::<RuntimeApi, ExecutorDispatch, _>(933 } = new_partial::<RuntimeApi, ExecutorDispatch, _>(915 &config,934 &config,916 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,935 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,917 )?;936 )?;918 let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);937 let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);919 let prometheus_registry = config.prometheus_registry().cloned();938 let prometheus_registry = config.prometheus_registry().cloned();920939921 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(922 task_manager.spawn_handle(),923 overrides_handle::<_, _, Runtime>(client.clone()),924 50,925 50,926 prometheus_registry.clone(),927 ));928929 let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<930 fc_mapping_sync::EthereumBlockNotification<Block>,931 > = Default::default();932 let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);933934 let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =940 let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =935 sc_service::build_network(sc_service::BuildNetworkParams {941 sc_service::build_network(sc_service::BuildNetworkParams {936 config: &config,942 config: &config,1047 );1053 );1048 }1054 }104910551050 task_manager.spawn_essential_handle().spawn(1051 "frontier-mapping-sync-worker",1052 Some("block-authoring"),1053 MappingSyncWorker::new(1054 client.import_notification_stream(),1055 Duration::new(6, 0),1056 client.clone(),1057 backend.clone(),1058 overrides_handle::<_, _, Runtime>(client.clone()),1059 frontier_backend.clone(),1060 3,1061 0,1062 SyncStrategy::Normal,1063 sync_service.clone(),1064 pubsub_notification_sinks.clone(),1065 )1066 .for_each(|()| futures::future::ready(())),1067 );10681069 #[cfg(feature = "pov-estimate")]1056 #[cfg(feature = "pov-estimate")]1070 let rpc_backend = backend.clone();1057 let rpc_backend = backend.clone();107110581072 let runtime_id = config.chain_spec.runtime_id();1059 let runtime_id = config.chain_spec.runtime_id();107310601061 // Frontier1062 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));1063 let fee_history_limit = 2048;10641065 let eth_pubsub_notification_sinks: Arc<1066 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,1067 > = Default::default();10681069 let overrides = overrides_handle(client.clone());1070 let eth_block_data_cache = spawn_frontier_tasks(1071 FrontierTaskParams {1072 client: client.clone(),1073 substrate_backend: backend.clone(),1074 eth_filter_pool: eth_filter_pool.clone(),1075 eth_backend: eth_backend.clone(),1076 fee_history_limit,1077 fee_history_cache: fee_history_cache.clone(),1078 task_manager: &task_manager,1079 prometheus_registry,1080 overrides: overrides.clone(),1081 sync_strategy: SyncStrategy::Normal,1082 },1083 sync_service.clone(),1084 eth_pubsub_notification_sinks.clone(),1085 );10861087 // Rpc1074 let rpc_builder = Box::new({1088 let rpc_builder = Box::new({1075 clone!(1089 clone!(1090 client,1076 backend,1091 backend,1077 client,1092 eth_backend,1093 eth_pubsub_notification_sinks,1094 fee_history_cache,1095 eth_block_data_cache,1096 overrides,1097 transaction_pool,1098 network,1078 sync_service,1099 sync_service,1079 frontier_backend,1080 network,1081 transaction_pool,1082 pubsub_notification_sinks1083 );1100 );1084 move |deny_unsafe, subscription_executor| {1101 move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {1085 clone!(1102 clone!(1086 backend,1103 backend,1087 block_data_cache,1104 eth_block_data_cache,1088 client,1105 client,1106 eth_backend,1107 eth_filter_pool,1108 eth_pubsub_notification_sinks,1089 fee_history_cache,1109 fee_history_cache,1090 filter_pool,1110 eth_block_data_cache,1091 network,1111 network,1092 pubsub_notification_sinks,1112 runtime_id,1113 transaction_pool,1114 select_chain,1115 overrides,1093 );1116 );109411171095 #[cfg(not(feature = "pov-estimate"))]1118 #[cfg(not(feature = "pov-estimate"))]1096 let _ = backend;1119 let _ = backend;109711201121 let mut rpc_module = RpcModule::new(());11221098 let full_deps = unique_rpc::FullDeps {1123 let full_deps = unique_rpc::FullDeps {1099 runtime_id: runtime_id.clone(),1124 runtime_id,110011251101 #[cfg(feature = "pov-estimate")]1126 #[cfg(feature = "pov-estimate")]1102 exec_params: uc_rpc::pov_estimate::ExecutorParams {1127 exec_params: uc_rpc::pov_estimate::ExecutorParams {110811331109 #[cfg(feature = "pov-estimate")]1134 #[cfg(feature = "pov-estimate")]1110 backend,1135 backend,1111 eth_backend: frontier_backend.clone(),1136 // eth_backend,1112 deny_unsafe,1137 deny_unsafe,1138 client: client.clone(),1139 pool: transaction_pool.clone(),1140 select_chain,1141 };11421143 unique_rpc::create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_module, full_deps)?;11441145 let eth_deps = unique_rpc::EthDeps {1113 client,1146 client,1114 pool: transaction_pool.clone(),1115 graph: transaction_pool.pool().clone(),1147 graph: transaction_pool.pool().clone(),1116 // TODO: Unhardcode1148 pool: transaction_pool,1117 enable_dev_signer: false,1149 is_authority: true,1118 filter_pool,1119 network,1150 network,1120 sync: sync_service.clone(),1151 eth_backend,1121 select_chain: select_chain.clone(),1122 is_authority: collator,1123 // TODO: Unhardcode1152 // TODO: Unhardcode1124 max_past_logs: 10000,1153 max_past_logs: 10000,1125 block_data_cache,1154 fee_history_limit,1126 fee_history_cache,1155 fee_history_cache,1156 eth_block_data_cache,1127 // TODO: Unhardcode1157 // TODO: Unhardcode1128 fee_history_limit: 2048,1158 enable_dev_signer: false,1129 pubsub_notification_sinks,1159 eth_filter_pool,1160 eth_pubsub_notification_sinks,1161 overrides,1162 sync: sync_service.clone(),1130 };1163 };113111641132 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1165 unique_rpc::create_eth(1166 &mut rpc_module,1133 full_deps,1167 eth_deps,1134 subscription_executor,1168 subscription_task_executor.clone(),1135 )1169 )?;11701136 .map_err(Into::into)1171 Ok(rpc_module)1137 }1172 }1138 });1173 });11391174115411891155 network_starter.start_network();1190 network_starter.start_network();1156 Ok(task_manager)1191 Ok(task_manager)1192}11931194fn overrides_handle<C, BE>(client: Arc<C>) -> Arc<OverrideHandle<Block>>1195where1196 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,1197 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,1198 C: Send + Sync + 'static,1199 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,1200 BE: Backend<Block> + 'static,1201 BE::State: StateBackend<BlakeTwo256>,1202{1203 let mut overrides_map = BTreeMap::new();1204 overrides_map.insert(1205 EthereumStorageSchema::V1,1206 Box::new(SchemaV1Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1207 );1208 overrides_map.insert(1209 EthereumStorageSchema::V2,1210 Box::new(SchemaV2Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1211 );1212 overrides_map.insert(1213 EthereumStorageSchema::V3,1214 Box::new(SchemaV3Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1215 );12161217 Arc::new(OverrideHandle {1218 schemas: overrides_map,1219 fallback: Box::new(RuntimeApiStorageOverride::new(client)),1220 })1221}12221223pub struct FrontierTaskParams<'a, B: BlockT, C, BE> {1224 pub task_manager: &'a TaskManager,1225 pub client: Arc<C>,1226 pub substrate_backend: Arc<BE>,1227 pub eth_backend: Arc<fc_db::kv::Backend<B>>,1228 pub eth_filter_pool: Option<FilterPool>,1229 pub overrides: Arc<OverrideHandle<B>>,1230 pub fee_history_limit: u64,1231 pub fee_history_cache: FeeHistoryCache,1232 pub sync_strategy: SyncStrategy,1233 pub prometheus_registry: Option<Registry>,1234}12351236pub fn spawn_frontier_tasks<B, C, BE>(1237 params: FrontierTaskParams<B, C, BE>,1238 sync: Arc<SyncingService<B>>,1239 pubsub_notification_sinks: Arc<1240 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<B>>,1241 >,1242) -> Arc<EthBlockDataCacheTask<B>>1243where1244 C: ProvideRuntimeApi<B> + BlockOf,1245 C: HeaderBackend<B> + HeaderMetadata<B, Error = BlockChainError> + 'static,1246 C: BlockchainEvents<B> + StorageProvider<B, BE>,1247 C: Send + Sync + 'static,1248 C::Api: EthereumRuntimeRPCApi<B>,1249 C::Api: BlockBuilder<B>,1250 B: BlockT<Hash = H256> + Send + Sync + 'static,1251 B::Header: HeaderT<Number = u32>,1252 BE: Backend<B> + 'static,1253 BE::State: StateBackend<BlakeTwo256>,1254{1255 let FrontierTaskParams {1256 task_manager,1257 client,1258 substrate_backend,1259 eth_backend,1260 eth_filter_pool,1261 overrides,1262 fee_history_limit,1263 fee_history_cache,1264 sync_strategy,1265 prometheus_registry,1266 } = params;1267 // Frontier offchain DB task. Essential.1268 // Maps emulated ethereum data to substrate native data.1269 params.task_manager.spawn_essential_handle().spawn(1270 "frontier-mapping-sync-worker",1271 Some("frontier"),1272 MappingSyncWorker::new(1273 client.import_notification_stream(),1274 Duration::new(6, 0),1275 client.clone(),1276 substrate_backend,1277 overrides.clone(),1278 eth_backend,1279 3,1280 0,1281 sync_strategy,1282 sync,1283 pubsub_notification_sinks,1284 )1285 .for_each(|()| futures::future::ready(())),1286 );12871288 // Frontier `EthFilterApi` maintenance.1289 // Manages the pool of user-created Filters.1290 if let Some(eth_filter_pool) = eth_filter_pool {1291 // Each filter is allowed to stay in the pool for 100 blocks.1292 const FILTER_RETAIN_THRESHOLD: u64 = 100;1293 params.task_manager.spawn_essential_handle().spawn(1294 "frontier-filter-pool",1295 Some("frontier"),1296 EthTask::filter_pool_task(client.clone(), eth_filter_pool, FILTER_RETAIN_THRESHOLD),1297 );1298 }12991300 // Spawn Frontier FeeHistory cache maintenance task.1301 params.task_manager.spawn_essential_handle().spawn(1302 "frontier-fee-history",1303 Some("frontier"),1304 EthTask::fee_history_task(1305 client,1306 overrides.clone(),1307 fee_history_cache,1308 fee_history_limit,1309 ),1310 );13111312 Arc::new(EthBlockDataCacheTask::new(1313 task_manager.spawn_handle(),1314 overrides,1315 50,1316 50,1317 prometheus_registry,1318 ))1157}1319}11581320node/rpc/Cargo.tomldiffbeforeafterboth--- a/node/rpc/Cargo.toml
+++ b/node/rpc/Cargo.toml
@@ -14,7 +14,6 @@
# pallet-contracts-rpc = { git = 'https://github.com/paritytech/substrate', branch = 'master' }
pallet-transaction-payment-rpc = { workspace = true }
sc-client-api = { workspace = true }
-sc-consensus-grandpa = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
sc-rpc = { workspace = true }
@@ -41,6 +40,7 @@
up-data-structs = { workspace = true }
up-pov-estimate-rpc = { workspace = true, default-features = true }
up-rpc = { workspace = true }
+pallet-ethereum.workspace = true
[features]
default = []
node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use fc_mapping_sync::{EthereumBlockNotificationSinks, EthereumBlockNotification};
use sp_runtime::traits::BlakeTwo256;
use fc_rpc::{
EthBlockDataCacheTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override,
@@ -26,9 +27,6 @@
backend::{AuxStore, StorageProvider},
client::BlockchainEvents,
StateBackend, Backend,
-};
-use sc_consensus_grandpa::{
- FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
};
use sc_network::NetworkService;
use sc_network_sync::SyncingService;
@@ -46,42 +44,16 @@
#[cfg(feature = "pov-estimate")]
type FullBackend = sc_service::TFullBackend<Block>;
-/// Extra dependencies for GRANDPA
-pub struct GrandpaDeps<B> {
- /// Voting round info.
- pub shared_voter_state: SharedVoterState,
- /// Authority set info.
- pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,
- /// Receives notifications about justification events from Grandpa.
- pub justification_stream: GrandpaJustificationStream<Block>,
- /// Executor to drive the subscription manager in the Grandpa RPC handler.
- pub subscription_executor: SubscriptionTaskExecutor,
- /// Finality proof provider.
- pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
-}
-
/// Full client dependencies.
-pub struct FullDeps<C, P, SC, CA: ChainApi> {
+pub struct FullDeps<C, P, SC> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
- /// Graph pool instance.
- pub graph: Arc<Pool<CA>>,
/// The SelectChain Strategy
pub select_chain: SC,
- /// The Node authority flag
- pub is_authority: bool,
- /// Whether to enable dev signer
- pub enable_dev_signer: bool,
- /// Network service
- pub network: Arc<NetworkService<Block, Hash>>,
- /// Syncing service
- pub sync: Arc<SyncingService<Block>>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
- /// EthFilterApi pool.
- pub filter_pool: Option<FilterPool>,
/// Runtime identification (read from the chain spec)
pub runtime_id: RuntimeId,
@@ -91,23 +63,6 @@
/// Substrate Backend.
#[cfg(feature = "pov-estimate")]
pub backend: Arc<FullBackend>,
-
- /// Ethereum Backend.
- pub eth_backend: Arc<dyn fc_db::BackendReader<Block> + Send + Sync>,
- /// Maximum number of logs in a query.
- pub max_past_logs: u32,
- /// Maximum fee history cache size.
- pub fee_history_limit: u64,
- /// Fee history cache.
- pub fee_history_cache: FeeHistoryCache,
- /// Cache for Ethereum block data.
- pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
-
- pub pubsub_notification_sinks: Arc<
- fc_mapping_sync::EthereumBlockNotificationSinks<
- fc_mapping_sync::EthereumBlockNotification<Block>,
- >,
- >,
}
pub fn overrides_handle<C, BE, R>(client: Arc<C>) -> Arc<OverrideHandle<Block>>
@@ -142,10 +97,10 @@
}
/// Instantiate all Full RPC extensions.
-pub fn create_full<C, P, SC, CA, R, A, B>(
- deps: FullDeps<C, P, SC, CA>,
- subscription_task_executor: SubscriptionTaskExecutor,
-) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
+pub fn create_full<C, P, SC, R, A, B>(
+ io: &mut RpcModule<()>,
+ deps: FullDeps<C, P, SC>,
+) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
@@ -155,8 +110,6 @@
C::Api: BlockBuilder<Block>,
// C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
- C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
- C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,
C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,
C::Api: app_promotion_rpc::AppPromotionApi<
Block,
@@ -168,7 +121,6 @@
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
P: TransactionPool<Block = Block> + 'static,
- CA: ChainApi<Block = Block> + 'static,
R: RuntimeInstance + Send + Sync + 'static,
<R as RuntimeInstance>::CrossAccountId: serde::Serialize,
C: sp_api::CallApiAt<
@@ -179,10 +131,6 @@
>,
for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,
{
- use fc_rpc::{
- Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,
- EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer, TxPool, TxPoolApiServer
- };
use uc_rpc::{UniqueApiServer, Unique};
use uc_rpc::{AppPromotionApiServer, AppPromotion};
@@ -194,21 +142,11 @@
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
- let mut io = RpcModule::new(());
let FullDeps {
client,
pool,
- graph,
select_chain: _,
- fee_history_limit,
- fee_history_cache,
- block_data_cache,
- enable_dev_signer,
- is_authority,
- network,
- sync,
deny_unsafe,
- filter_pool,
runtime_id: _,
@@ -217,37 +155,137 @@
#[cfg(feature = "pov-estimate")]
backend,
-
- eth_backend,
- max_past_logs,
- pubsub_notification_sinks,
} = deps;
io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;
- // io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));
+ io.merge(Unique::new(client.clone()).into_rpc())?;
+
+ io.merge(AppPromotion::new(client.clone()).into_rpc())?;
+
+ #[cfg(feature = "pov-estimate")]
+ io.merge(
+ PovEstimate::new(
+ client.clone(),
+ backend,
+ deny_unsafe,
+ exec_params,
+ runtime_id,
+ )
+ .into_rpc(),
+ )?;
+
+ Ok(())
+}
+
+pub struct EthDeps<C, P, CA: ChainApi> {
+ /// The client instance to use.
+ pub client: Arc<C>,
+ /// Transaction pool instance.
+ pub pool: Arc<P>,
+ /// Graph pool instance.
+ pub graph: Arc<Pool<CA>>,
+ /// Syncing service
+ pub sync: Arc<SyncingService<Block>>,
+ /// The Node authority flag
+ pub is_authority: bool,
+ /// Network service
+ pub network: Arc<NetworkService<Block, Hash>>,
+
+ /// Ethereum Backend.
+ pub eth_backend: Arc<dyn fc_db::BackendReader<Block> + Send + Sync>,
+ /// Maximum number of logs in a query.
+ pub max_past_logs: u32,
+ /// Maximum fee history cache size.
+ pub fee_history_limit: u64,
+ /// Fee history cache.
+ pub fee_history_cache: FeeHistoryCache,
+ pub eth_block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
+ /// EthFilterApi pool.
+ pub eth_filter_pool: Option<FilterPool>,
+ pub eth_pubsub_notification_sinks: Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>>,
+ /// Whether to enable eth dev signer
+ pub enable_dev_signer: bool,
+
+ pub overrides: Arc<OverrideHandle<Block>>,
+}
+
+/// This converter is never used, but we have a generic
+/// Option<T>, where T should implement ConvertTransaction
+///
+/// TODO: remove after never-type (`!`) stabilization
+enum NeverConvert {}
+impl<T> fp_rpc::ConvertTransaction<T> for NeverConvert {
+ fn convert_transaction(&self, _transaction: pallet_ethereum::Transaction) -> T {
+ unreachable!()
+ }
+}
+pub fn create_eth<C, P, CA, B>(
+ io: &mut RpcModule<()>,
+ deps: EthDeps<C, P, CA>,
+ subscription_task_executor: SubscriptionTaskExecutor,
+) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
+where
+ C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,
+ C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
+ C: Send + Sync + 'static,
+ C: BlockchainEvents<Block>,
+ C::Api: BlockBuilder<Block>,
+ C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
+ C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,
+ P: TransactionPool<Block = Block> + 'static,
+ CA: ChainApi<Block = Block> + 'static,
+ B: sc_client_api::Backend<Block> + Send + Sync + 'static,
+ C: sp_api::CallApiAt<
+ sp_runtime::generic::Block<
+ sp_runtime::generic::Header<u32, BlakeTwo256>,
+ sp_runtime::OpaqueExtrinsic,
+ >,
+ >,
+{
+ use fc_rpc::{
+ Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,
+ EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer, TxPool, TxPoolApiServer,
+ };
+
+ let EthDeps {
+ client,
+ pool,
+ graph,
+ eth_backend,
+ max_past_logs,
+ fee_history_limit,
+ fee_history_cache,
+ eth_block_data_cache,
+ eth_filter_pool,
+ eth_pubsub_notification_sinks,
+ enable_dev_signer,
+ sync,
+ is_authority,
+ network,
+ overrides,
+ } = deps;
+
let mut signers = Vec::new();
if enable_dev_signer {
signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);
}
-
- let overrides = overrides_handle::<_, _, R>(client.clone());
-
let execute_gas_limit_multiplier = 10;
io.merge(
Eth::new(
client.clone(),
pool.clone(),
graph.clone(),
- Some(<R as RuntimeInstance>::get_transaction_converter()),
+ // We have no runtimes old enough to only accept converted transactions
+ None::<NeverConvert>,
sync.clone(),
signers,
overrides.clone(),
eth_backend.clone(),
is_authority,
- block_data_cache.clone(),
+ eth_block_data_cache.clone(),
fee_history_cache,
fee_history_limit,
execute_gas_limit_multiplier,
@@ -256,24 +294,12 @@
.into_rpc(),
)?;
- io.merge(Unique::new(client.clone()).into_rpc())?;
-
- io.merge(AppPromotion::new(client.clone()).into_rpc())?;
+ let tx_pool = TxPool::new(
+ client.clone(),
+ graph,
+ );
- #[cfg(feature = "pov-estimate")]
- io.merge(
- PovEstimate::new(
- client.clone(),
- backend,
- deny_unsafe,
- exec_params,
- runtime_id,
- )
- .into_rpc(),
- )?;
-
- let tx_pool = TxPool::new(client.clone(), graph);
- if let Some(filter_pool) = filter_pool {
+ if let Some(filter_pool) = eth_filter_pool {
io.merge(
EthFilter::new(
client.clone(),
@@ -282,12 +308,11 @@
filter_pool,
500_usize, // max stored filters
max_past_logs,
- block_data_cache,
+ eth_block_data_cache,
)
.into_rpc(),
)?;
}
-
io.merge(
Net::new(
client.clone(),
@@ -297,9 +322,7 @@
)
.into_rpc(),
)?;
-
io.merge(Web3::new(client.clone()).into_rpc())?;
-
io.merge(
EthPubSub::new(
pool,
@@ -307,12 +330,11 @@
sync,
subscription_task_executor,
overrides,
- pubsub_notification_sinks,
+ eth_pubsub_notification_sinks,
)
.into_rpc(),
)?;
-
io.merge(tx_pool.into_rpc())?;
- Ok(io)
+ Ok(())
}