From 039531d27a8a1cf7a30ddcd833766e2c85ff6b7c Mon Sep 17 00:00:00 2001 From: girazoki Date: Thu, 16 May 2024 16:38:09 +0200 Subject: [PATCH] client changes --- client/rpc/src/net.rs | 20 ++++++++------------ template/node/src/rpc/eth.rs | 4 ++-- template/node/src/service.rs | 31 ++++++++++++++++++++++++------- template/runtime/src/lib.rs | 4 ++-- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/client/rpc/src/net.rs b/client/rpc/src/net.rs index 17f48e42a3..5e2ffd59f2 100644 --- a/client/rpc/src/net.rs +++ b/client/rpc/src/net.rs @@ -20,8 +20,7 @@ use std::sync::Arc; use jsonrpsee::core::RpcResult; // Substrate -use sc_network::{NetworkPeers, NetworkService}; -use sc_network_common::ExHashT; +use sc_network::{service::traits::NetworkService, NetworkPeers}; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; @@ -32,27 +31,24 @@ use fp_rpc::EthereumRuntimeRPCApi; use crate::internal_err; /// Net API implementation. -pub struct Net { +pub struct Net { client: Arc, - network: Arc>, + network: Arc, peer_count_as_hex: bool, + _phantom_data: std::marker::PhantomData, } - -impl Net { - pub fn new( - client: Arc, - network: Arc>, - peer_count_as_hex: bool, - ) -> Self { +impl Net { + pub fn new(client: Arc, network: Arc, peer_count_as_hex: bool) -> Self { Self { client, network, peer_count_as_hex, + _phantom_data: Default::default(), } } } -impl NetApiServer for Net +impl NetApiServer for Net where B: BlockT, C: ProvideRuntimeApi, diff --git a/template/node/src/rpc/eth.rs b/template/node/src/rpc/eth.rs index 8e4ca12dc3..322679da0d 100644 --- a/template/node/src/rpc/eth.rs +++ b/template/node/src/rpc/eth.rs @@ -7,7 +7,7 @@ use sc_client_api::{ client::BlockchainEvents, AuxStore, UsageProvider, }; -use sc_network::NetworkService; +use sc_network::service::traits::NetworkService; use sc_network_sync::SyncingService; use sc_rpc::SubscriptionTaskExecutor; use sc_transaction_pool::{ChainApi, Pool}; @@ -40,7 +40,7 @@ pub struct EthDeps { /// Whether to enable dev signer pub enable_dev_signer: bool, /// Network service - pub network: Arc>, + pub network: Arc, /// Chain syncing service pub sync: Arc>, /// Frontier Backend. diff --git a/template/node/src/service.rs b/template/node/src/service.rs index 5f5308144c..ca96763fb2 100644 --- a/template/node/src/service.rs +++ b/template/node/src/service.rs @@ -15,6 +15,8 @@ use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_api::ConstructRuntimeApi; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use sp_core::U256; +use sp_runtime::traits::Block as BlockT; + // Runtime use frontier_template_runtime::{opaque::Block, Hash, TransactionConverter}; @@ -258,7 +260,7 @@ where } /// Builds a new service for a full client. -pub async fn new_full( +pub async fn new_full( mut config: Configuration, eth_config: EthConfiguration, sealing: Option, @@ -268,6 +270,7 @@ where RuntimeApi: Send + Sync + 'static, RuntimeApi::RuntimeApi: RuntimeApiCollection, Executor: NativeExecutionDispatch + 'static, + N: sc_network::NetworkBackend::Hash>, { let build_import_queue = if sealing.is_some() { build_manual_seal_import_queue:: @@ -292,13 +295,24 @@ where fee_history_cache_limit, } = new_frontier_partial(ð_config)?; - let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); + let mut net_config = + sc_network::config::FullNetworkConfiguration::<_, _, N>::new(&config.network); + let peer_store_handle = net_config.peer_store_handle(); + let metrics = N::register_notification_metrics( + config.prometheus_config.as_ref().map(|cfg| &cfg.registry), + ); + let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name( &client.block_hash(0)?.expect("Genesis block exists; qed"), &config.chain_spec, ); + let (grandpa_protocol_config, grandpa_notification_service) = - sc_consensus_grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone()); + sc_consensus_grandpa::grandpa_peers_set_config::<_, N>( + grandpa_protocol_name.clone(), + metrics.clone(), + peer_store_handle, + ); let warp_sync_params = if sealing.is_some() { None @@ -324,6 +338,7 @@ where block_announce_validator_builder: None, warp_sync_params, block_relay: None, + metrics, })?; if config.offchain_worker.enabled { @@ -338,7 +353,7 @@ where transaction_pool: Some(OffchainTransactionPoolFactory::new( transaction_pool.clone(), )), - network_provider: network.clone(), + network_provider: Arc::new(network.clone()), enable_http_requests: true, custom_extensions: |_| vec![], }) @@ -697,9 +712,11 @@ pub async fn build_full( eth_config: EthConfiguration, sealing: Option, ) -> Result { - new_full::( - config, eth_config, sealing, - ) + new_full::< + frontier_template_runtime::RuntimeApi, + TemplateRuntimeExecutor, + sc_network::NetworkWorker<_, _>, + >(config, eth_config, sealing) .await } diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 24c7ce192e..a41a82178f 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -18,7 +18,6 @@ use scale_codec::{Decode, Encode}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; -use sp_std::prelude::*; use sp_core::{ crypto::{ByteArray, KeyTypeId}, ConstU128, OpaqueMetadata, H160, H256, U256, @@ -32,6 +31,7 @@ use sp_runtime::{ transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, ApplyExtrinsicResult, ConsensusEngineId, ExtrinsicInclusionMode, Perbill, Permill, }; +use sp_std::prelude::*; use sp_version::RuntimeVersion; // Substrate FRAME #[cfg(feature = "with-paritydb-weights")] @@ -45,8 +45,8 @@ use frame_support::{ traits::{ConstBool, ConstU32, ConstU64, ConstU8, FindAuthor, OnFinalize, OnTimestampSet}, weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, IdentityFee, Weight}, }; -use sp_genesis_builder::PresetId; use pallet_transaction_payment::{ConstFeeMultiplier, CurrencyAdapter}; +use sp_genesis_builder::PresetId; // Frontier use fp_account::EthereumSignature; use fp_evm::weight_per_gas;