Network sync refactoring (part 4) (#11412)

* Remove direct dependency of `sc-network` on `sc-network-light`

* Move `WarpSyncProvider` trait and surrounding data structures into `sc-network-common`

* Move `WarpSyncProvider` trait and surrounding data structures into `sc-network-common`

* Create `sync` module in `sc-network-common`, create `ChainSync` trait there (not used yet), move a bunch of associated data structures from `sc-network-sync`

* Switch from concrete implementation to `ChainSync` trait from `sc-network-common`

* Introduce `OpaqueStateRequest`/`OpaqueStateResponse` to remove generics from `StateSync` trait

* Introduce `OpaqueBlockRequest`/`OpaqueBlockResponse`, make `scheme` module of `sc-network-sync` private

* Surface `sc-network-sync` into `sc-service` and make `sc-network` not depend on it anymore

* Remove now unnecessary dependency from `sc-network`

* Replace crate links with just text since dependencies are gone now

* Remove `warp_sync` re-export from `sc-network-common`

* Update copyright in network-related files

* Address review comments about documentation

* Apply review suggestion

* Rename `extra_requests` module to `metrics`

Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Nazar Mokrynskyi
2022-07-12 23:34:17 +03:00
committed by GitHub
parent 4b8d784210
commit 5896072b86
35 changed files with 1286 additions and 1041 deletions
+18 -6
View File
@@ -16,15 +16,17 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::{
config, state_request_handler::StateRequestHandler, Event, NetworkService, NetworkWorker,
};
use crate::{config, Event, NetworkService, NetworkWorker};
use futures::prelude::*;
use libp2p::PeerId;
use sc_network_common::config::ProtocolId;
use sc_network_light::light_client_requests::handler::LightClientRequestHandler;
use sc_network_sync::block_request_handler::BlockRequestHandler;
use sc_network_sync::{
block_request_handler::BlockRequestHandler, state_request_handler::StateRequestHandler,
ChainSync,
};
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;
use sp_runtime::traits::{Block as BlockT, Header as _};
use std::{borrow::Cow, sync::Arc, time::Duration};
use substrate_test_runtime_client::{TestClientBuilder, TestClientBuilderExt as _};
@@ -109,6 +111,7 @@ fn build_test_full_node(
protocol_config
};
let max_parallel_downloads = config.max_parallel_downloads;
let worker = NetworkWorker::new(config::Params {
role: config::Role::Full,
executor: None,
@@ -120,8 +123,17 @@ fn build_test_full_node(
transaction_pool: Arc::new(crate::config::EmptyTransactionPool),
protocol_id,
import_queue,
block_announce_validator: Box::new(
sp_consensus::block_validation::DefaultBlockAnnounceValidator,
create_chain_sync: Box::new(
move |sync_mode, chain, warp_sync_provider| match ChainSync::new(
sync_mode,
chain,
Box::new(DefaultBlockAnnounceValidator),
max_parallel_downloads,
warp_sync_provider,
) {
Ok(chain_sync) => Ok(Box::new(chain_sync)),
Err(error) => Err(Box::new(error).into()),
},
),
metrics_registry: None,
block_request_protocol_config,