git.delta.rocks / unique-network / refs/commits / e6ed5f4e38db

difftreelog

refactor use build_network from cumulus_client_service

Yaroslav Bolyukin2024-06-19parent: #72b9f19.patch.diff
in: master

2 files changed

modifiednode/cli/src/rpc.rsdiffbeforeafterboth
after · node/cli/src/rpc.rs
1// 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> {47	/// The client instance to use.48	pub client: Arc<C>,49	/// Transaction pool instance.50	pub pool: Arc<P>,51	/// Whether to deny unsafe calls52	pub deny_unsafe: DenyUnsafe,53	/// Executor params for PoV estimating54	#[cfg(feature = "pov-estimate")]55	pub exec_params: uc_rpc::pov_estimate::ExecutorParams,56	/// Substrate Backend.57	#[cfg(feature = "pov-estimate")]58	pub backend: Arc<FullBackend>,59}6061/// Instantiate all Full RPC extensions.62pub fn create_full<C, P, R, B>(63	io: &mut RpcModule<()>,64	deps: FullDeps<C, P>,65) -> Result<(), Box<dyn std::error::Error + Send + Sync>>66where67	C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,68	C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,69	C: Send + Sync + 'static,70	C: BlockchainEvents<Block>,71	C::Api: RuntimeApiDep<R>,72	B: sc_client_api::Backend<Block> + Send + Sync + 'static,73	P: TransactionPool<Block = Block> + 'static,74	R: RuntimeInstance + Send + Sync + 'static,75	<R as RuntimeInstance>::CrossAccountId: serde::Serialize,76	C: sp_api::CallApiAt<77		generic::Block<generic::Header<u32, BlakeTwo256>, sp_runtime::OpaqueExtrinsic>,78	>,79	for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,80{81	// use pallet_contracts_rpc::{Contracts, ContractsApi};82	use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};83	use substrate_frame_rpc_system::{System, SystemApiServer};84	#[cfg(feature = "pov-estimate")]85	use uc_rpc::pov_estimate::{PovEstimate, PovEstimateApiServer};86	use uc_rpc::{AppPromotion, AppPromotionApiServer, Unique, UniqueApiServer};8788	let FullDeps {89		client,90		pool,91		deny_unsafe,9293		#[cfg(feature = "pov-estimate")]94		exec_params,9596		#[cfg(feature = "pov-estimate")]97		backend,98	} = deps;99100	io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;101	io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;102103	io.merge(Unique::new(client.clone()).into_rpc())?;104105	io.merge(AppPromotion::new(client).into_rpc())?;106107	#[cfg(feature = "pov-estimate")]108	io.merge(109		PovEstimate::new(110			client.clone(),111			backend,112			deny_unsafe,113			exec_params,114			runtime_id,115		)116		.into_rpc(),117	)?;118119	Ok(())120}121122pub struct EthDeps<C, P, CA: ChainApi, CIDP> {123	/// The client instance to use.124	pub client: Arc<C>,125	/// Transaction pool instance.126	pub pool: Arc<P>,127	/// Graph pool instance.128	pub graph: Arc<Pool<CA>>,129	/// Syncing service130	pub sync: Arc<SyncingService<Block>>,131	/// The Node authority flag132	pub is_authority: bool,133	/// Network service134	pub network: Arc<NetworkService<Block, Hash>>,135136	/// Ethereum Backend.137	pub eth_backend: Arc<dyn fc_api::Backend<Block> + Send + Sync>,138	/// Maximum number of logs in a query.139	pub max_past_logs: u32,140	/// Maximum fee history cache size.141	pub fee_history_limit: u64,142	/// Fee history cache.143	pub fee_history_cache: FeeHistoryCache,144	pub eth_block_data_cache: Arc<EthBlockDataCacheTask<Block>>,145	/// EthFilterApi pool.146	pub eth_filter_pool: Option<FilterPool>,147	pub eth_pubsub_notification_sinks:148		Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>>,149	/// Whether to enable eth dev signer150	pub enable_dev_signer: bool,151152	pub overrides: Arc<OverrideHandle<Block>>,153	pub pending_create_inherent_data_providers: CIDP,154}155156pub fn create_eth<C, R, P, CA, B, CIDP, EC>(157	io: &mut RpcModule<()>,158	deps: EthDeps<C, P, CA, CIDP>,159	subscription_task_executor: SubscriptionTaskExecutor,160) -> Result<(), Box<dyn std::error::Error + Send + Sync>>161where162	C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,163	C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,164	C: Send + Sync + 'static,165	C: BlockchainEvents<Block>,166	C: UsageProvider<Block>,167	C::Api: RuntimeApiDep<R>,168	P: TransactionPool<Block = Block> + 'static,169	CA: ChainApi<Block = Block> + 'static,170	B: sc_client_api::Backend<Block> + Send + Sync + 'static,171	C: sp_api::CallApiAt<Block>,172	CIDP: CreateInherentDataProviders<Block, ()> + Send + 'static,173	EC: EthConfig<Block, C>,174	R: RuntimeInstance,175{176	use fc_rpc::{177		Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,178		EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,179	};180181	let EthDeps {182		client,183		pool,184		graph,185		eth_backend,186		max_past_logs,187		fee_history_limit,188		fee_history_cache,189		eth_block_data_cache,190		eth_filter_pool,191		eth_pubsub_notification_sinks,192		enable_dev_signer,193		sync,194		is_authority,195		network,196		overrides,197		pending_create_inherent_data_providers,198	} = deps;199200	let mut signers = Vec::new();201	if enable_dev_signer {202		signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);203	}204	let execute_gas_limit_multiplier = 10;205	io.merge(206		Eth::<_, _, _, _, _, _, _, EC>::new(207			client.clone(),208			pool.clone(),209			graph.clone(),210			// We have no runtimes old enough to only accept converted transactions.211			None::<NoTransactionConverter>,212			sync.clone(),213			signers,214			overrides.clone(),215			eth_backend.clone(),216			is_authority,217			eth_block_data_cache.clone(),218			fee_history_cache,219			fee_history_limit,220			execute_gas_limit_multiplier,221			None,222			pending_create_inherent_data_providers,223			// Our extrinsics have nothing to do with consensus digest items yet.224			None,225		)226		.into_rpc(),227	)?;228229	if let Some(filter_pool) = eth_filter_pool {230		io.merge(231			EthFilter::new(232				client.clone(),233				eth_backend,234				graph,235				filter_pool,236				500_usize, // max stored filters237				max_past_logs,238				eth_block_data_cache,239			)240			.into_rpc(),241		)?;242	}243	io.merge(244		Net::new(245			client.clone(),246			network,247			// Whether to format the `peer_count` response as Hex (default) or not.248			true,249		)250		.into_rpc(),251	)?;252	io.merge(Web3::new(client.clone()).into_rpc())?;253	io.merge(254		EthPubSub::new(255			pool,256			client,257			sync,258			subscription_task_executor,259			overrides,260			eth_pubsub_notification_sinks,261		)262		.into_rpc(),263	)?;264265	Ok(())266}
modifiednode/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: &parachain_config,
+		cumulus_client_service::build_network(cumulus_client_service::BuildNetworkParams {
+			parachain_config: &parachain_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,