mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Modular block request handler (#1524)
Submit the outstanding PRs from the old repos(these were already reviewed and approved before the repo rorg, but not yet submitted): Main PR: https://github.com/paritytech/substrate/pull/14014 Companion PRs: https://github.com/paritytech/polkadot/pull/7134, https://github.com/paritytech/cumulus/pull/2489 The changes in the PR: 1. ChainSync currently calls into the block request handler directly. Instead, move the block request handler behind a trait. This allows new protocols to be plugged into ChainSync. 2. BuildNetworkParams is changed so that custom relay protocol implementations can be (optionally) passed in during network creation time. If custom protocol is not specified, it defaults to the existing block handler 3. BlockServer and BlockDownloader traits are introduced for the protocol implementation. The existing block handler has been changed to implement these traits 4. Other changes: [X] Make TxHash serializable. This is needed for exchanging the serialized hash in the relay protocol messages [X] Clean up types no longer used(OpaqueBlockRequest, OpaqueBlockResponse) --------- Co-authored-by: Dmitry Markin <dmitry@markin.tech> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
c6df364157
commit
b35b28ca4b
@@ -798,12 +798,18 @@ pub trait TestNetFactory: Default + Sized + Send {
|
||||
|
||||
let fork_id = Some(String::from("test-fork-id"));
|
||||
|
||||
let block_request_protocol_config = {
|
||||
let (handler, protocol_config) =
|
||||
BlockRequestHandler::new(&protocol_id, None, client.clone(), 50);
|
||||
self.spawn_task(handler.run().boxed());
|
||||
protocol_config
|
||||
};
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) =
|
||||
NetworkServiceProvider::new();
|
||||
let mut block_relay_params = BlockRequestHandler::new(
|
||||
chain_sync_network_handle.clone(),
|
||||
&protocol_id,
|
||||
None,
|
||||
client.clone(),
|
||||
50,
|
||||
);
|
||||
self.spawn_task(Box::pin(async move {
|
||||
block_relay_params.server.run().await;
|
||||
}));
|
||||
|
||||
let state_request_protocol_config = {
|
||||
let (handler, protocol_config) =
|
||||
@@ -848,8 +854,6 @@ pub trait TestNetFactory: Default + Sized + Send {
|
||||
let block_announce_validator = config
|
||||
.block_announce_validator
|
||||
.unwrap_or_else(|| Box::new(DefaultBlockAnnounceValidator));
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) =
|
||||
NetworkServiceProvider::new();
|
||||
|
||||
let (tx, rx) = sc_utils::mpsc::tracing_unbounded("mpsc_syncing_engine_protocol", 100_000);
|
||||
let (engine, sync_service, block_announce_config) =
|
||||
@@ -864,7 +868,7 @@ pub trait TestNetFactory: Default + Sized + Send {
|
||||
Some(warp_sync_params),
|
||||
chain_sync_network_handle,
|
||||
import_queue.service(),
|
||||
block_request_protocol_config.name.clone(),
|
||||
block_relay_params.downloader,
|
||||
state_request_protocol_config.name.clone(),
|
||||
Some(warp_protocol_config.name.clone()),
|
||||
rx,
|
||||
@@ -877,7 +881,7 @@ pub trait TestNetFactory: Default + Sized + Send {
|
||||
full_net_config.add_request_response_protocol(config);
|
||||
}
|
||||
for config in [
|
||||
block_request_protocol_config,
|
||||
block_relay_params.request_response_config,
|
||||
state_request_protocol_config,
|
||||
light_client_request_protocol_config,
|
||||
warp_protocol_config,
|
||||
|
||||
@@ -156,12 +156,18 @@ impl TestNetworkBuilder {
|
||||
let fork_id = Some(String::from("test-fork-id"));
|
||||
let mut full_net_config = FullNetworkConfiguration::new(&network_config);
|
||||
|
||||
let block_request_protocol_config = {
|
||||
let (handler, protocol_config) =
|
||||
BlockRequestHandler::new(&protocol_id, None, client.clone(), 50);
|
||||
tokio::spawn(handler.run().boxed());
|
||||
protocol_config
|
||||
};
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) =
|
||||
self.chain_sync_network.unwrap_or(NetworkServiceProvider::new());
|
||||
let mut block_relay_params = BlockRequestHandler::new(
|
||||
chain_sync_network_handle.clone(),
|
||||
&protocol_id,
|
||||
None,
|
||||
client.clone(),
|
||||
50,
|
||||
);
|
||||
tokio::spawn(Box::pin(async move {
|
||||
block_relay_params.server.run().await;
|
||||
}));
|
||||
|
||||
let state_request_protocol_config = {
|
||||
let (handler, protocol_config) =
|
||||
@@ -177,8 +183,6 @@ impl TestNetworkBuilder {
|
||||
protocol_config
|
||||
};
|
||||
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) =
|
||||
self.chain_sync_network.unwrap_or(NetworkServiceProvider::new());
|
||||
let (tx, rx) = sc_utils::mpsc::tracing_unbounded("mpsc_syncing_engine_protocol", 100_000);
|
||||
let (engine, chain_sync_service, block_announce_config) = SyncingEngine::new(
|
||||
Roles::from(&config::Role::Full),
|
||||
@@ -191,7 +195,7 @@ impl TestNetworkBuilder {
|
||||
None,
|
||||
chain_sync_network_handle,
|
||||
import_queue.service(),
|
||||
block_request_protocol_config.name.clone(),
|
||||
block_relay_params.downloader,
|
||||
state_request_protocol_config.name.clone(),
|
||||
None,
|
||||
rx,
|
||||
@@ -214,7 +218,7 @@ impl TestNetworkBuilder {
|
||||
}
|
||||
|
||||
for config in [
|
||||
block_request_protocol_config,
|
||||
block_relay_params.request_response_config,
|
||||
state_request_protocol_config,
|
||||
light_client_request_protocol_config,
|
||||
] {
|
||||
|
||||
Reference in New Issue
Block a user