Skip to content

Commit

Permalink
client changes
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed May 16, 2024
1 parent 90eeb7d commit 039531d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
20 changes: 8 additions & 12 deletions client/rpc/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,27 +31,24 @@ use fp_rpc::EthereumRuntimeRPCApi;
use crate::internal_err;

/// Net API implementation.
pub struct Net<B: BlockT, C, H: ExHashT> {
pub struct Net<B: BlockT, C> {
client: Arc<C>,
network: Arc<NetworkService<B, H>>,
network: Arc<dyn NetworkService>,
peer_count_as_hex: bool,
_phantom_data: std::marker::PhantomData<B>,
}

impl<B: BlockT, C, H: ExHashT> Net<B, C, H> {
pub fn new(
client: Arc<C>,
network: Arc<NetworkService<B, H>>,
peer_count_as_hex: bool,
) -> Self {
impl<B: BlockT, C> Net<B, C> {
pub fn new(client: Arc<C>, network: Arc<dyn NetworkService>, peer_count_as_hex: bool) -> Self {
Self {
client,
network,
peer_count_as_hex,
_phantom_data: Default::default(),
}
}
}

impl<B, C, H: ExHashT> NetApiServer for Net<B, C, H>
impl<B, C> NetApiServer for Net<B, C>
where
B: BlockT,
C: ProvideRuntimeApi<B>,
Expand Down
4 changes: 2 additions & 2 deletions template/node/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct EthDeps<B: BlockT, C, P, A: ChainApi, CT, CIDP> {
/// Whether to enable dev signer
pub enable_dev_signer: bool,
/// Network service
pub network: Arc<NetworkService<B, B::Hash>>,
pub network: Arc<dyn NetworkService>,
/// Chain syncing service
pub sync: Arc<SyncingService<B>>,
/// Frontier Backend.
Expand Down
31 changes: 24 additions & 7 deletions template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -258,7 +260,7 @@ where
}

/// Builds a new service for a full client.
pub async fn new_full<RuntimeApi, Executor>(
pub async fn new_full<RuntimeApi, Executor, N>(
mut config: Configuration,
eth_config: EthConfiguration,
sealing: Option<Sealing>,
Expand All @@ -268,6 +270,7 @@ where
RuntimeApi: Send + Sync + 'static,
RuntimeApi::RuntimeApi: RuntimeApiCollection,
Executor: NativeExecutionDispatch + 'static,
N: sc_network::NetworkBackend<Block, <Block as BlockT>::Hash>,
{
let build_import_queue = if sealing.is_some() {
build_manual_seal_import_queue::<RuntimeApi, Executor>
Expand All @@ -292,13 +295,24 @@ where
fee_history_cache_limit,
} = new_frontier_partial(&eth_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
Expand All @@ -324,6 +338,7 @@ where
block_announce_validator_builder: None,
warp_sync_params,
block_relay: None,
metrics,
})?;

if config.offchain_worker.enabled {
Expand All @@ -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![],
})
Expand Down Expand Up @@ -697,9 +712,11 @@ pub async fn build_full(
eth_config: EthConfiguration,
sealing: Option<Sealing>,
) -> Result<TaskManager, ServiceError> {
new_full::<frontier_template_runtime::RuntimeApi, TemplateRuntimeExecutor>(
config, eth_config, sealing,
)
new_full::<
frontier_template_runtime::RuntimeApi,
TemplateRuntimeExecutor,
sc_network::NetworkWorker<_, _>,
>(config, eth_config, sealing)
.await
}

Expand Down
4 changes: 2 additions & 2 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")]
Expand All @@ -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;
Expand Down

0 comments on commit 039531d

Please sign in to comment.