mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 04:41:02 +00:00
Network sync refactoring (part 6) (#11940)
* Extract `NetworkKVProvider` trait in `sc-authority-discovery` and remove unnecessary dependency * Extract `NetworkSyncForkRequest` trait in `sc-finality-grandpa` * Relax requirements on `SyncOracle` trait, remove extra native methods from `NetworkService` that are already provided by trait impls * Move `NetworkSigner` trait from `sc-authority-discovery` into `sc-network-common` and de-duplicate methods on `NetworkService` * Move `NetworkKVProvider` trait from `sc-authority-discovery` into `sc-network-common` and de-duplicate methods on `NetworkService` * Minimize `sc-authority-discovery` dependency on `sc-network` * Move `NetworkSyncForkRequest` trait from `sc-finality-grandpa` to `sc-network-common` and de-duplicate methods in `NetworkService` * Extract `NetworkStatusProvider` trait and de-duplicate methods on `NetworkService` * Extract `NetworkPeers` trait and de-duplicate methods on `NetworkService` * Extract `NetworkEventStream` trait and de-duplicate methods on `NetworkService` * Move more methods from `NetworkService` into `NetworkPeers` trait * Move `NetworkStateInfo` trait into `sc-network-common` * Extract `NetworkNotification` trait and de-duplicate methods on `NetworkService` * Extract `NetworkRequest` trait and de-duplicate methods on `NetworkService` * Remove `NetworkService::local_peer_id()`, it is already provided by `NetworkStateInfo` impl * Extract `NetworkTransaction` trait and de-duplicate methods on `NetworkService` * Extract `NetworkBlock` trait and de-duplicate methods on `NetworkService` * Remove dependencies on `NetworkService` from most of the methods of `sc-service` * Address simple review comments
This commit is contained in:
@@ -38,7 +38,10 @@ use sc_consensus::import_queue::ImportQueue;
|
||||
use sc_executor::RuntimeVersionOf;
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sc_network::{config::SyncMode, NetworkService};
|
||||
use sc_network_common::sync::warp::WarpSyncProvider;
|
||||
use sc_network_common::{
|
||||
service::{NetworkStateInfo, NetworkStatusProvider, NetworkTransaction},
|
||||
sync::warp::WarpSyncProvider,
|
||||
};
|
||||
use sc_network_light::light_client_requests::handler::LightClientRequestHandler;
|
||||
use sc_network_sync::{
|
||||
block_request_handler::BlockRequestHandler, state_request_handler::StateRequestHandler,
|
||||
@@ -319,6 +322,31 @@ where
|
||||
)
|
||||
}
|
||||
|
||||
/// Shared network instance implementing a set of mandatory traits.
|
||||
pub trait SpawnTaskNetwork<Block: BlockT>:
|
||||
sc_offchain::NetworkProvider
|
||||
+ NetworkStateInfo
|
||||
+ NetworkTransaction<Block::Hash>
|
||||
+ NetworkStatusProvider<Block>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static
|
||||
{
|
||||
}
|
||||
|
||||
impl<T, Block> SpawnTaskNetwork<Block> for T
|
||||
where
|
||||
Block: BlockT,
|
||||
T: sc_offchain::NetworkProvider
|
||||
+ NetworkStateInfo
|
||||
+ NetworkTransaction<Block::Hash>
|
||||
+ NetworkStatusProvider<Block>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
{
|
||||
}
|
||||
|
||||
/// Parameters to pass into `build`.
|
||||
pub struct SpawnTasksParams<'a, TBl: BlockT, TCl, TExPool, TRpc, Backend> {
|
||||
/// The service configuration.
|
||||
@@ -337,7 +365,7 @@ pub struct SpawnTasksParams<'a, TBl: BlockT, TCl, TExPool, TRpc, Backend> {
|
||||
pub rpc_builder:
|
||||
Box<dyn Fn(DenyUnsafe, SubscriptionTaskExecutor) -> Result<RpcModule<TRpc>, Error>>,
|
||||
/// A shared network instance.
|
||||
pub network: Arc<NetworkService<TBl, <TBl as BlockT>::Hash>>,
|
||||
pub network: Arc<dyn SpawnTaskNetwork<TBl>>,
|
||||
/// A Sender for RPC requests.
|
||||
pub system_rpc_tx: TracingUnboundedSender<sc_rpc::system::Request<TBl>>,
|
||||
/// Telemetry instance for this node.
|
||||
@@ -349,7 +377,7 @@ pub fn build_offchain_workers<TBl, TCl>(
|
||||
config: &Configuration,
|
||||
spawn_handle: SpawnTaskHandle,
|
||||
client: Arc<TCl>,
|
||||
network: Arc<NetworkService<TBl, <TBl as BlockT>::Hash>>,
|
||||
network: Arc<dyn sc_offchain::NetworkProvider + Send + Sync>,
|
||||
) -> Option<Arc<sc_offchain::OffchainWorkers<TCl, TBl>>>
|
||||
where
|
||||
TBl: BlockT,
|
||||
@@ -516,13 +544,14 @@ where
|
||||
Ok(rpc_handlers)
|
||||
}
|
||||
|
||||
async fn transaction_notifications<TBl, TExPool>(
|
||||
transaction_pool: Arc<TExPool>,
|
||||
network: Arc<NetworkService<TBl, <TBl as BlockT>::Hash>>,
|
||||
async fn transaction_notifications<Block, ExPool, Network>(
|
||||
transaction_pool: Arc<ExPool>,
|
||||
network: Network,
|
||||
telemetry: Option<TelemetryHandle>,
|
||||
) where
|
||||
TBl: BlockT,
|
||||
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash>,
|
||||
Block: BlockT,
|
||||
ExPool: MaintainedTransactionPool<Block = Block, Hash = <Block as BlockT>::Hash>,
|
||||
Network: NetworkTransaction<<Block as BlockT>::Hash> + Send + Sync,
|
||||
{
|
||||
// transaction notifications
|
||||
transaction_pool
|
||||
@@ -542,13 +571,18 @@ async fn transaction_notifications<TBl, TExPool>(
|
||||
.await;
|
||||
}
|
||||
|
||||
fn init_telemetry<TBl: BlockT, TCl: BlockBackend<TBl>>(
|
||||
fn init_telemetry<Block, Client, Network>(
|
||||
config: &mut Configuration,
|
||||
network: Arc<NetworkService<TBl, <TBl as BlockT>::Hash>>,
|
||||
client: Arc<TCl>,
|
||||
network: Network,
|
||||
client: Arc<Client>,
|
||||
telemetry: &mut Telemetry,
|
||||
sysinfo: Option<sc_telemetry::SysInfo>,
|
||||
) -> sc_telemetry::Result<TelemetryHandle> {
|
||||
) -> sc_telemetry::Result<TelemetryHandle>
|
||||
where
|
||||
Block: BlockT,
|
||||
Client: BlockBackend<Block>,
|
||||
Network: NetworkStateInfo,
|
||||
{
|
||||
let genesis_hash = client.block_hash(Zero::zero()).ok().flatten().unwrap_or_default();
|
||||
let connection_message = ConnectionMessage {
|
||||
name: config.network.node_name.to_owned(),
|
||||
|
||||
@@ -42,9 +42,11 @@ use jsonrpsee::{core::Error as JsonRpseeError, RpcModule};
|
||||
use log::{debug, error, warn};
|
||||
use sc_client_api::{blockchain::HeaderBackend, BlockBackend, BlockchainEvents, ProofProvider};
|
||||
use sc_network::PeerId;
|
||||
use sc_network_common::service::NetworkBlock;
|
||||
use sc_rpc_server::WsConfig;
|
||||
use sc_utils::mpsc::TracingUnboundedReceiver;
|
||||
use sp_blockchain::HeaderMetadata;
|
||||
use sp_consensus::SyncOracle;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, Header as HeaderT},
|
||||
|
||||
@@ -22,7 +22,8 @@ use crate::config::Configuration;
|
||||
use futures_timer::Delay;
|
||||
use prometheus_endpoint::{register, Gauge, GaugeVec, Opts, PrometheusError, Registry, U64};
|
||||
use sc_client_api::{ClientInfo, UsageProvider};
|
||||
use sc_network::{config::Role, NetworkService, NetworkStatus};
|
||||
use sc_network::config::Role;
|
||||
use sc_network_common::service::{NetworkStatus, NetworkStatusProvider};
|
||||
use sc_telemetry::{telemetry, TelemetryHandle, SUBSTRATE_INFO};
|
||||
use sc_transaction_pool_api::{MaintainedTransactionPool, PoolStatus};
|
||||
use sc_utils::metrics::register_globals;
|
||||
@@ -182,15 +183,16 @@ impl MetricsService {
|
||||
/// Returns a never-ending `Future` that performs the
|
||||
/// metric and telemetry updates with information from
|
||||
/// the given sources.
|
||||
pub async fn run<TBl, TExPool, TCl>(
|
||||
pub async fn run<TBl, TExPool, TCl, TNet>(
|
||||
mut self,
|
||||
client: Arc<TCl>,
|
||||
transactions: Arc<TExPool>,
|
||||
network: Arc<NetworkService<TBl, <TBl as Block>::Hash>>,
|
||||
network: TNet,
|
||||
) where
|
||||
TBl: Block,
|
||||
TCl: ProvideRuntimeApi<TBl> + UsageProvider<TBl>,
|
||||
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as Block>::Hash>,
|
||||
TNet: NetworkStatusProvider<TBl>,
|
||||
{
|
||||
let mut timer = Delay::new(Duration::from_secs(0));
|
||||
let timer_interval = Duration::from_secs(5);
|
||||
|
||||
Reference in New Issue
Block a user