Companion for #6726 (#1469)

* Companion for #6726

* Spaces

* 'Update substrate'

Co-authored-by: parity-processbot <>
This commit is contained in:
Bastian Köcher
2020-07-26 15:16:09 +02:00
committed by GitHub
parent a2527913a6
commit fa598f176b
24 changed files with 278 additions and 204 deletions
+3
View File
@@ -29,6 +29,7 @@ use polkadot_erasure_coding as erasure;
use sp_api::ProvideRuntimeApi;
use futures::prelude::*;
use log::debug;
use primitives::traits::SpawnNamed;
/// Encapsulates connections to collators and allows collation on any parachain.
///
@@ -64,6 +65,7 @@ pub async fn collation_fetch<C: Collators, P>(
client: Arc<P>,
max_block_data_size: Option<u64>,
n_validators: usize,
spawner: impl SpawnNamed + Clone + 'static,
) -> Result<(CollationInfo, crate::pipeline::FullOutput), C::Error>
where
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
@@ -82,6 +84,7 @@ pub async fn collation_fetch<C: Collators, P>(
&relay_parent,
max_block_data_size,
n_validators,
spawner.clone(),
);
match res {
+5
View File
@@ -32,6 +32,7 @@ use parachain::{
use runtime_primitives::traits::{BlakeTwo256, Hash as HashT};
use sp_api::ProvideRuntimeApi;
use crate::Error;
use primitives::traits::SpawnNamed;
pub use parachain::wasm_executor::ValidationPool;
@@ -191,6 +192,7 @@ pub fn validate<'a>(
local_validation: &'a LocalValidationData,
global_validation: &'a GlobalValidationData,
validation_code: &ValidationCode,
spawner: impl SpawnNamed + 'static,
) -> Result<ValidatedCandidate<'a>, Error> {
if collation.head_data.0.len() > global_validation.max_head_data_size as _ {
return Err(Error::HeadDataTooLarge(
@@ -222,6 +224,7 @@ pub fn validate<'a>(
&validation_code.0,
params,
execution_mode,
spawner,
) {
Ok(result) => {
if result.head_data == collation.head_data {
@@ -277,6 +280,7 @@ pub fn full_output_validation_with_api<P>(
expected_relay_parent: &Hash,
max_block_data_size: Option<u64>,
n_validators: usize,
spawner: impl SpawnNamed + 'static,
) -> Result<FullOutput, Error> where
P: ProvideRuntimeApi<Block>,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
@@ -302,6 +306,7 @@ pub fn full_output_validation_with_api<P>(
&local_validation,
&global_validation,
&validation_code,
spawner,
);
match res {
@@ -312,6 +312,7 @@ impl<Fetch: Future + Unpin> ParachainWork<Fetch> {
&expected_relay_parent,
max_block_data_size,
n_validators,
primitives::testing::TaskExecutor::new(),
)?;
full_output.check_consistency(candidate)?;
@@ -145,7 +145,7 @@ impl<C, N, P, SC, SP> ServiceBuilder<C, N, P, SC, SP> where
N::BuildTableRouter: Send + Unpin + 'static,
<N::TableRouter as TableRouter>::SendLocalCollation: Send,
SC: SelectChain<Block> + 'static,
SP: SpawnNamed + Send + 'static,
SP: SpawnNamed + Clone + 'static,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HashFor<Block>>,
{
@@ -167,11 +167,15 @@ impl<C, N, P, SC, SP> ServiceBuilder<C, N, P, SC, SP> where
let mut parachain_validation = ParachainValidationInstances {
client: self.client.clone(),
network: self.network,
spawner: self.spawner,
spawner: self.spawner.clone(),
availability_store: self.availability_store,
live_instances: HashMap::new(),
validation_pool: validation_pool.clone(),
collation_fetch: DefaultCollationFetch(self.collators, validation_pool),
collation_fetch: DefaultCollationFetch {
collators: self.collators,
validation_pool,
spawner: self.spawner,
},
};
let client = self.client;
@@ -253,11 +257,17 @@ pub(crate) trait CollationFetch {
}
#[derive(Clone)]
struct DefaultCollationFetch<C>(C, Option<ValidationPool>);
impl<C> CollationFetch for DefaultCollationFetch<C>
struct DefaultCollationFetch<C, S> {
collators: C,
validation_pool: Option<ValidationPool>,
spawner: S,
}
impl<C, S> CollationFetch for DefaultCollationFetch<C, S>
where
C: Collators + Send + Sync + Unpin + 'static,
C::Collation: Send + Unpin + 'static,
S: SpawnNamed + Clone + 'static,
{
type Error = C::Error;
@@ -273,15 +283,15 @@ impl<C> CollationFetch for DefaultCollationFetch<C>
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
P: ProvideRuntimeApi<Block> + Send + Sync + 'static,
{
let DefaultCollationFetch(collators, validation_pool) = self;
crate::collation::collation_fetch(
validation_pool,
self.validation_pool,
parachain,
relay_parent,
collators,
self.collators,
client,
max_block_data_size,
n_validators,
self.spawner,
).boxed()
}
}
@@ -553,7 +563,7 @@ mod tests {
use runtime_primitives::traits::Block as BlockT;
use std::pin::Pin;
use sp_keyring::sr25519::Keyring;
use primitives::testing::SpawnBlockingExecutor;
use primitives::testing::TaskExecutor;
/// Events fired while running mock implementations to follow execution.
enum Events {
@@ -714,7 +724,7 @@ mod tests {
#[test]
fn launch_work_is_executed_properly() {
let executor = SpawnBlockingExecutor::new();
let executor = TaskExecutor::new();
let keystore = keystore::Store::new_in_memory();
// Make sure `Bob` key is in the keystore, so this mocked node will be a parachain validator.
@@ -754,7 +764,7 @@ mod tests {
#[test]
fn router_is_built_on_relay_chain_validator() {
let executor = SpawnBlockingExecutor::new();
let executor = TaskExecutor::new();
let keystore = keystore::Store::new_in_memory();
// Make sure `Alice` key is in the keystore, so this mocked node will be a relay-chain validator.