Remove legacy network code (#860)

* expunge legacy code from polkadot-network

* mostly rip out old legacy protocol from service

* ensure validation work is spawned by incoming messages

* decouple availabliity store from network logic; clean up data flow

* av_store: test helpers and use futures-abort

* update polkadot-validation to pass n_validators when submitting chunks

* fallible erasure-chunk fetching

* implement `ErasureNetworking` for new network prot

* API for registering availability store in network

* fully integrate new network service into service

* fix validation tests

* scaffolding for porting collator over to new network

* track connected validators' peer IDs and distribute collators' collations

* helper in network for fetching all checked statements

* fix adder-collator

* actually register notifications protocol

* Update service/src/lib.rs

* merge with master
This commit is contained in:
Robert Habermeier
2020-03-05 10:11:21 -08:00
committed by GitHub
parent b49bf9d5b0
commit 7931380825
19 changed files with 863 additions and 3120 deletions
+69 -68
View File
@@ -22,10 +22,8 @@ use sc_client::LongestChain;
use std::sync::Arc;
use std::time::Duration;
use polkadot_primitives::{parachain, Hash, BlockId, AccountId, Nonce, Balance};
use polkadot_network::legacy::{
gossip::{self as network_gossip, Known},
validation::ValidationNetwork,
};
use polkadot_network::legacy::gossip::Known;
use polkadot_network::{protocol as network_protocol, PolkadotProtocol as StubSpecialization};
use service::{error::{Error as ServiceError}, ServiceBuilder};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use inherents::InherentDataProviders;
@@ -42,7 +40,6 @@ pub use sc_client_api::backend::Backend;
pub use sp_api::{Core as CoreApi, ConstructRuntimeApi, ProvideRuntimeApi, StateBackend};
pub use sp_runtime::traits::HashFor;
pub use consensus_common::SelectChain;
pub use polkadot_network::legacy::PolkadotProtocol;
pub use polkadot_primitives::parachain::{CollatorId, ParachainHost};
pub use polkadot_primitives::Block;
pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256};
@@ -209,14 +206,17 @@ pub fn polkadot_new_full(
authority_discovery_enabled: bool,
slot_duration: u64,
)
-> Result<impl AbstractService<
Block = Block,
RuntimeApi = polkadot_runtime::RuntimeApi,
NetworkSpecialization = PolkadotProtocol,
Backend = TFullBackend<Block>,
SelectChain = LongestChain<TFullBackend<Block>, Block>,
CallExecutor = TFullCallExecutor<Block, PolkadotExecutor>,
>, ServiceError>
-> Result<(
impl AbstractService<
Block = Block,
RuntimeApi = polkadot_runtime::RuntimeApi,
NetworkSpecialization = StubSpecialization,
Backend = TFullBackend<Block>,
SelectChain = LongestChain<TFullBackend<Block>, Block>,
CallExecutor = TFullCallExecutor<Block, PolkadotExecutor>,
>,
FullNodeHandles,
), ServiceError>
{
new_full(config, collating_for, max_block_data_size, authority_discovery_enabled, slot_duration)
}
@@ -229,18 +229,28 @@ pub fn kusama_new_full(
authority_discovery_enabled: bool,
slot_duration: u64,
)
-> Result<impl AbstractService<
Block = Block,
RuntimeApi = kusama_runtime::RuntimeApi,
NetworkSpecialization = PolkadotProtocol,
Backend = TFullBackend<Block>,
SelectChain = LongestChain<TFullBackend<Block>, Block>,
CallExecutor = TFullCallExecutor<Block, KusamaExecutor>,
>, ServiceError>
-> Result<(
impl AbstractService<
Block = Block,
RuntimeApi = kusama_runtime::RuntimeApi,
NetworkSpecialization = StubSpecialization,
Backend = TFullBackend<Block>,
SelectChain = LongestChain<TFullBackend<Block>, Block>,
CallExecutor = TFullCallExecutor<Block, KusamaExecutor>,
>,
FullNodeHandles,
), ServiceError>
{
new_full(config, collating_for, max_block_data_size, authority_discovery_enabled, slot_duration)
}
/// Handles to other sub-services that full nodes instantiate, which consumers
/// of the node may use.
pub struct FullNodeHandles {
/// A handle to the Polkadot networking protocol.
pub polkadot_network: Option<network_protocol::Service>,
}
/// Builds a new service for a full client.
pub fn new_full<Runtime, Dispatch, Extrinsic>(
config: Configuration,
@@ -249,14 +259,17 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
authority_discovery_enabled: bool,
slot_duration: u64,
)
-> Result<impl AbstractService<
Block = Block,
RuntimeApi = Runtime,
NetworkSpecialization = PolkadotProtocol,
Backend = TFullBackend<Block>,
SelectChain = LongestChain<TFullBackend<Block>, Block>,
CallExecutor = TFullCallExecutor<Block, Dispatch>,
>, ServiceError>
-> Result<(
impl AbstractService<
Block = Block,
RuntimeApi = Runtime,
NetworkSpecialization = StubSpecialization,
Backend = TFullBackend<Block>,
SelectChain = LongestChain<TFullBackend<Block>, Block>,
CallExecutor = TFullCallExecutor<Block, Dispatch>,
>,
FullNodeHandles,
), ServiceError>
where
Runtime: ConstructRuntimeApi<Block, service::TFullClient<Block, Runtime, Dispatch>> + Send + Sync + 'static,
Runtime::RuntimeApi:
@@ -294,7 +307,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
let backend = builder.backend().clone();
let service = builder
.with_network_protocol(|_config| Ok(PolkadotProtocol::new(collating_for.clone())))?
.with_network_protocol(|_config| Ok(StubSpecialization::new()))?
.with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)?
@@ -305,11 +318,13 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
let client = service.client();
let known_oracle = client.clone();
let mut handles = FullNodeHandles { polkadot_network: None };
let select_chain = if let Some(select_chain) = service.select_chain() {
select_chain
} else {
info!("The node cannot start as an authority because it can't select chain.");
return Ok(service);
return Ok((service, handles));
};
let gossip_validator_select_chain = select_chain.clone();
@@ -332,11 +347,15 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
}
};
let mut gossip_validator = network_gossip::register_validator(
let polkadot_network_service = network_protocol::start(
service.network(),
network_protocol::Config {
collating_for,
},
(is_known, client.clone()),
&service.spawn_task_handle(),
);
client.clone(),
service.spawn_task_handle(),
).map_err(|e| format!("Could not spawn network worker: {:?}", e))?;
if participates_in_consensus {
let availability_store = {
@@ -345,13 +364,14 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
let mut path = PathBuf::from(db_path);
path.push("availability");
let gossip = polkadot_network::legacy::AvailabilityNetworkShim(gossip_validator.clone());
#[cfg(not(target_os = "unknown"))]
{
av_store::Store::new(
av_store::Config { cache_size: None, path },
gossip,
::av_store::Config {
cache_size: None,
path,
},
polkadot_network_service.clone(),
)?
}
@@ -359,29 +379,12 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
av_store::Store::new_in_memory(gossip)
};
{
let availability_store = availability_store.clone();
service.network().with_spec(
|spec, _ctx| spec.register_availability_store(availability_store)
);
}
{
let availability_store = availability_store.clone();
gossip_validator.register_availability_store(availability_store);
}
// collator connections and validation network both fulfilled by this
let validation_network = ValidationNetwork::new(
gossip_validator,
service.client(),
service.spawn_task_handle(),
);
polkadot_network_service.register_availability_store(availability_store.clone());
let (validation_service_handle, validation_service) = consensus::ServiceBuilder {
client: client.clone(),
network: validation_network.clone(),
collators: validation_network,
network: polkadot_network_service.clone(),
collators: polkadot_network_service.clone(),
spawner: service.spawn_task_handle(),
availability_store: availability_store.clone(),
select_chain: select_chain.clone(),
@@ -493,41 +496,40 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
)?;
}
Ok(service)
handles.polkadot_network = Some(polkadot_network_service);
Ok((service, handles))
}
/// Create a new Polkadot service for a light client.
pub fn polkadot_new_light(
config: Configuration,
collating_for: Option<(CollatorId, parachain::Id)>,
)
-> Result<impl AbstractService<
Block = Block,
RuntimeApi = polkadot_runtime::RuntimeApi,
NetworkSpecialization = PolkadotProtocol,
NetworkSpecialization = StubSpecialization,
Backend = TLightBackend<Block>,
SelectChain = LongestChain<TLightBackend<Block>, Block>,
CallExecutor = TLightCallExecutor<Block, PolkadotExecutor>,
>, ServiceError>
{
new_light(config, collating_for)
new_light(config)
}
/// Create a new Kusama service for a light client.
pub fn kusama_new_light(
config: Configuration,
collating_for: Option<(CollatorId, parachain::Id)>,
)
-> Result<impl AbstractService<
Block = Block,
RuntimeApi = kusama_runtime::RuntimeApi,
NetworkSpecialization = PolkadotProtocol,
NetworkSpecialization = StubSpecialization,
Backend = TLightBackend<Block>,
SelectChain = LongestChain<TLightBackend<Block>, Block>,
CallExecutor = TLightCallExecutor<Block, KusamaExecutor>,
>, ServiceError>
{
new_light(config, collating_for)
new_light(config)
}
// We can't use service::TLightClient due to
@@ -551,12 +553,11 @@ type TLocalLightClient<Runtime, Dispatch> = Client<
/// Builds a new service for a light client.
pub fn new_light<Runtime, Dispatch, Extrinsic>(
config: Configuration,
collating_for: Option<(CollatorId, parachain::Id)>,
)
-> Result<impl AbstractService<
Block = Block,
RuntimeApi = Runtime,
NetworkSpecialization = PolkadotProtocol,
NetworkSpecialization = StubSpecialization,
Backend = TLightBackend<Block>,
SelectChain = LongestChain<TLightBackend<Block>, Block>,
CallExecutor = TLightCallExecutor<Block, Dispatch>,
@@ -619,7 +620,7 @@ where
Ok((import_queue, finality_proof_request_builder))
})?
.with_network_protocol(|_config| Ok(PolkadotProtocol::new(collating_for.clone())))?
.with_network_protocol(|_config| Ok(StubSpecialization::new()))?
.with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)?