difftreelog
refactor use build_network from cumulus_client_service
in: master
2 files changed
node/cli/src/rpc.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use std::sync::Arc;1819use fc_mapping_sync::{EthereumBlockNotification, EthereumBlockNotificationSinks};20use fc_rpc::{EthBlockDataCacheTask, EthConfig, OverrideHandle};21use fc_rpc_core::types::{FeeHistoryCache, FilterPool};22use fp_rpc::NoTransactionConverter;23use jsonrpsee::RpcModule;24use sc_client_api::{25 backend::{AuxStore, StorageProvider},26 client::BlockchainEvents,27 UsageProvider,28};29use sc_network::NetworkService;30use sc_network_sync::SyncingService;31use sc_rpc::SubscriptionTaskExecutor;32pub use sc_rpc_api::DenyUnsafe;33use sc_service::TransactionPool;34use sc_transaction_pool::{ChainApi, Pool};35use sp_api::ProvideRuntimeApi;36use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};37use sp_inherents::CreateInherentDataProviders;38use up_common::types::opaque::*;3940use crate::service::RuntimeApiDep;4142#[cfg(feature = "pov-estimate")]43type FullBackend = sc_service::TFullBackend<Block>;4445/// Full client dependencies.46pub struct FullDeps<C, P, SC> {47 /// The client instance to use.48 pub client: Arc<C>,49 /// Transaction pool instance.50 pub pool: Arc<P>,51 /// The SelectChain Strategy52 pub select_chain: SC,53 /// Whether to deny unsafe calls54 pub deny_unsafe: DenyUnsafe,5556 /// Runtime identification (read from the chain spec)57 pub runtime_id: RuntimeId,58 /// Executor params for PoV estimating59 #[cfg(feature = "pov-estimate")]60 pub exec_params: uc_rpc::pov_estimate::ExecutorParams,61 /// Substrate Backend.62 #[cfg(feature = "pov-estimate")]63 pub backend: Arc<FullBackend>,64}6566/// Instantiate all Full RPC extensions.67pub fn create_full<C, P, SC, R, B>(68 io: &mut RpcModule<()>,69 deps: FullDeps<C, P, SC>,70) -> Result<(), Box<dyn std::error::Error + Send + Sync>>71where72 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,73 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,74 C: Send + Sync + 'static,75 C: BlockchainEvents<Block>,76 C::Api: RuntimeApiDep<R>,77 B: sc_client_api::Backend<Block> + Send + Sync + 'static,78 P: TransactionPool<Block = Block> + 'static,79 R: RuntimeInstance + Send + Sync + 'static,80 <R as RuntimeInstance>::CrossAccountId: serde::Serialize,81 C: sp_api::CallApiAt<82 generic::Block<generic::Header<u32, BlakeTwo256>, sp_runtime::OpaqueExtrinsic>,83 >,84 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,85{86 // use pallet_contracts_rpc::{Contracts, ContractsApi};87 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};88 use substrate_frame_rpc_system::{System, SystemApiServer};89 #[cfg(feature = "pov-estimate")]90 use uc_rpc::pov_estimate::{PovEstimate, PovEstimateApiServer};91 use uc_rpc::{AppPromotion, AppPromotionApiServer, Unique, UniqueApiServer};9293 let FullDeps {94 client,95 pool,96 select_chain: _,97 deny_unsafe,9899 runtime_id: _,100101 #[cfg(feature = "pov-estimate")]102 exec_params,103104 #[cfg(feature = "pov-estimate")]105 backend,106 } = deps;107108 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;109 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;110111 io.merge(Unique::new(client.clone()).into_rpc())?;112113 io.merge(AppPromotion::new(client).into_rpc())?;114115 #[cfg(feature = "pov-estimate")]116 io.merge(117 PovEstimate::new(118 client.clone(),119 backend,120 deny_unsafe,121 exec_params,122 runtime_id,123 )124 .into_rpc(),125 )?;126127 Ok(())128}129130pub struct EthDeps<C, P, CA: ChainApi, CIDP> {131 /// The client instance to use.132 pub client: Arc<C>,133 /// Transaction pool instance.134 pub pool: Arc<P>,135 /// Graph pool instance.136 pub graph: Arc<Pool<CA>>,137 /// Syncing service138 pub sync: Arc<SyncingService<Block>>,139 /// The Node authority flag140 pub is_authority: bool,141 /// Network service142 pub network: Arc<NetworkService<Block, Hash>>,143144 /// Ethereum Backend.145 pub eth_backend: Arc<dyn fc_api::Backend<Block> + Send + Sync>,146 /// Maximum number of logs in a query.147 pub max_past_logs: u32,148 /// Maximum fee history cache size.149 pub fee_history_limit: u64,150 /// Fee history cache.151 pub fee_history_cache: FeeHistoryCache,152 pub eth_block_data_cache: Arc<EthBlockDataCacheTask<Block>>,153 /// EthFilterApi pool.154 pub eth_filter_pool: Option<FilterPool>,155 pub eth_pubsub_notification_sinks:156 Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>>,157 /// Whether to enable eth dev signer158 pub enable_dev_signer: bool,159160 pub overrides: Arc<OverrideHandle<Block>>,161 pub pending_create_inherent_data_providers: CIDP,162}163164pub fn create_eth<C, R, P, CA, B, CIDP, EC>(165 io: &mut RpcModule<()>,166 deps: EthDeps<C, P, CA, CIDP>,167 subscription_task_executor: SubscriptionTaskExecutor,168) -> Result<(), Box<dyn std::error::Error + Send + Sync>>169where170 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,171 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,172 C: Send + Sync + 'static,173 C: BlockchainEvents<Block>,174 C: UsageProvider<Block>,175 C::Api: RuntimeApiDep<R>,176 P: TransactionPool<Block = Block> + 'static,177 CA: ChainApi<Block = Block> + 'static,178 B: sc_client_api::Backend<Block> + Send + Sync + 'static,179 C: sp_api::CallApiAt<Block>,180 CIDP: CreateInherentDataProviders<Block, ()> + Send + 'static,181 EC: EthConfig<Block, C>,182 R: RuntimeInstance,183{184 use fc_rpc::{185 Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,186 EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,187 };188189 let EthDeps {190 client,191 pool,192 graph,193 eth_backend,194 max_past_logs,195 fee_history_limit,196 fee_history_cache,197 eth_block_data_cache,198 eth_filter_pool,199 eth_pubsub_notification_sinks,200 enable_dev_signer,201 sync,202 is_authority,203 network,204 overrides,205 pending_create_inherent_data_providers,206 } = deps;207208 let mut signers = Vec::new();209 if enable_dev_signer {210 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);211 }212 let execute_gas_limit_multiplier = 10;213 io.merge(214 Eth::<_, _, _, _, _, _, _, EC>::new(215 client.clone(),216 pool.clone(),217 graph.clone(),218 // We have no runtimes old enough to only accept converted transactions.219 None::<NoTransactionConverter>,220 sync.clone(),221 signers,222 overrides.clone(),223 eth_backend.clone(),224 is_authority,225 eth_block_data_cache.clone(),226 fee_history_cache,227 fee_history_limit,228 execute_gas_limit_multiplier,229 None,230 pending_create_inherent_data_providers,231 // Our extrinsics have nothing to do with consensus digest items yet.232 None,233 )234 .into_rpc(),235 )?;236237 if let Some(filter_pool) = eth_filter_pool {238 io.merge(239 EthFilter::new(240 client.clone(),241 eth_backend,242 graph,243 filter_pool,244 500_usize, // max stored filters245 max_past_logs,246 eth_block_data_cache,247 )248 .into_rpc(),249 )?;250 }251 io.merge(252 Net::new(253 client.clone(),254 network,255 // Whether to format the `peer_count` response as Hex (default) or not.256 true,257 )258 .into_rpc(),259 )?;260 io.merge(Web3::new(client.clone()).into_rpc())?;261 io.merge(262 EthPubSub::new(263 pool,264 client,265 sync,266 subscription_task_executor,267 overrides,268 eth_pubsub_notification_sinks,269 )270 .into_rpc(),271 )?;272273 Ok(())274}node/cli/src/service.rsdiffbeforeafterboth--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -36,8 +36,8 @@
use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;
use cumulus_client_consensus_proposer::Proposer;
use cumulus_client_service::{
- build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, DARecoveryProfile,
- StartRelayChainTasksParams,
+ build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks,
+ CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
};
use cumulus_primitives_core::ParaId;
use cumulus_primitives_parachain_inherent::ParachainInherentData;
@@ -85,10 +85,7 @@
use cumulus_primitives_core::PersistedValidationData;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
-use crate::{
- chain_spec::RuntimeIdentification,
- rpc::{create_eth, create_full, EthDeps, FullDeps},
-};
+use crate::rpc::{create_eth, create_full, EthDeps, FullDeps};
/// Unique native executor instance.
#[cfg(feature = "unique-runtime")]
@@ -428,10 +425,6 @@
)
.await
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;
-
- // Aura is sybil-resistant, collator-selection is generally too.
- let block_announce_validator =
- cumulus_client_network::AssumeSybilResistance::allow_seconded_messages();
let validator = parachain_config.role.is_authority();
let prometheus_registry = parachain_config.prometheus_registry().cloned();
@@ -439,23 +432,19 @@
let import_queue_service = params.import_queue.service();
let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
- sc_service::build_network(sc_service::BuildNetworkParams {
- config: ¶chain_config,
+ cumulus_client_service::build_network(cumulus_client_service::BuildNetworkParams {
+ parachain_config: ¶chain_config,
net_config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
+ para_id,
spawn_handle: task_manager.spawn_handle(),
+ relay_chain_interface: relay_chain_interface.clone(),
import_queue: params.import_queue,
- block_announce_validator_builder: Some(Box::new(|_| {
- Box::new(block_announce_validator)
- })),
- warp_sync_params: None,
- block_relay: None,
- })?;
-
- let select_chain = params.select_chain.clone();
-
- let runtime_id = parachain_config.chain_spec.runtime_id();
+ // Aura is sybil-resistant, collator-selection is generally too.
+ sybil_resistance_level: CollatorSybilResistance::Resistant,
+ })
+ .await?;
// Frontier
let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));
@@ -508,9 +497,7 @@
fee_history_cache,
eth_block_data_cache,
network,
- runtime_id,
transaction_pool,
- select_chain,
overrides,
);
@@ -521,7 +508,6 @@
let full_deps = FullDeps {
client: client.clone(),
- runtime_id,
#[cfg(feature = "pov-estimate")]
exec_params: uc_rpc::pov_estimate::ExecutorParams {
@@ -536,10 +522,9 @@
deny_unsafe,
pool: transaction_pool.clone(),
- select_chain,
};
- create_full::<_, _, _, Runtime, _>(&mut rpc_handle, full_deps)?;
+ create_full::<_, _, Runtime, _>(&mut rpc_handle, full_deps)?;
let eth_deps = EthDeps {
client,
@@ -1044,8 +1029,6 @@
#[cfg(feature = "pov-estimate")]
let rpc_backend = backend.clone();
- let runtime_id = config.chain_spec.runtime_id();
-
// Frontier
let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));
let fee_history_limit = 2048;
@@ -1097,9 +1080,7 @@
fee_history_cache,
eth_block_data_cache,
network,
- runtime_id,
transaction_pool,
- select_chain,
overrides,
);
@@ -1109,8 +1090,6 @@
let mut rpc_module = RpcModule::new(());
let full_deps = FullDeps {
- runtime_id,
-
#[cfg(feature = "pov-estimate")]
exec_params: uc_rpc::pov_estimate::ExecutorParams {
wasm_method: config.wasm_method,
@@ -1125,10 +1104,9 @@
deny_unsafe,
client: client.clone(),
pool: transaction_pool.clone(),
- select_chain,
};
- create_full::<_, _, _, Runtime, _>(&mut rpc_module, full_deps)?;
+ create_full::<_, _, Runtime, _>(&mut rpc_module, full_deps)?;
let eth_deps = EthDeps {
client,