diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 83cdd0272b48be49b4f6f8af037744862127d947..3be3cf423f07de45961f8bba22f1ef9eebcb5aaa 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -5884,34 +5884,6 @@ dependencies = [ "tracing-futures", ] -[[package]] -name = "polkadot-validation" -version = "0.8.27" -dependencies = [ - "futures 0.3.10", - "log", - "parity-scale-codec", - "polkadot-parachain", - "polkadot-primitives", - "sc-basic-authorship", - "sc-block-builder", - "sc-client-api", - "sc-finality-grandpa", - "sp-api", - "sp-blockchain", - "sp-consensus", - "sp-consensus-babe", - "sp-core", - "sp-inherents", - "sp-keyring", - "sp-runtime", - "sp-timestamp", - "sp-transaction-pool", - "sp-trie", - "substrate-prometheus-endpoint", - "thiserror", -] - [[package]] name = "polling" version = "2.0.2" diff --git a/polkadot/Cargo.toml b/polkadot/Cargo.toml index a69f8afab4de5f162637295185c5ee76fa3b3c3c..2d771ceeb4d1555ed4dbe7de72a408726b9902c6 100644 --- a/polkadot/Cargo.toml +++ b/polkadot/Cargo.toml @@ -38,7 +38,6 @@ members = [ "runtime/westend", "runtime/test-runtime", "statement-table", - "validation", "xcm", "xcm/xcm-builder", "xcm/xcm-executor", diff --git a/polkadot/validation/Cargo.toml b/polkadot/validation/Cargo.toml deleted file mode 100644 index 10bd546202be736962d565a195d2d6103065fec3..0000000000000000000000000000000000000000 --- a/polkadot/validation/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "polkadot-validation" -version = "0.8.27" -authors = ["Parity Technologies <admin@parity.io>"] -edition = "2018" - -[dependencies] -polkadot-primitives = { path = "../primitives" } -parachain = { package = "polkadot-parachain", path = "../parachain" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } -consensus = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "master" } -runtime_primitives = { package = "sp-runtime", git = "https://github.com/paritytech/substrate", branch = "master" } -futures = "0.3.8" -log = "0.4.13" -parity-scale-codec = { version = "1.3.6", default-features = false, features = ["derive"] } -grandpa = { package = "sc-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" } -inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master" } -primitives = { package = "sp-core", git = "https://github.com/paritytech/substrate", branch = "master" } -txpool-api = { package = "sp-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "master" } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" } -block-builder = { package = "sc-block-builder", git = "https://github.com/paritytech/substrate", branch = "master" } -trie = { package = "sp-trie", git = "https://github.com/paritytech/substrate", branch = "master" } -babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" } -prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "master" } -thiserror = "1.0.23" - -[dev-dependencies] -sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot/validation/README.adoc b/polkadot/validation/README.adoc deleted file mode 100644 index 1723bf2ae25e4634179504f86c9f8c7aefe9043c..0000000000000000000000000000000000000000 --- a/polkadot/validation/README.adoc +++ /dev/null @@ -1,5 +0,0 @@ - -= Polkadot Validation - -placeholder -//TODO Write content :) (https://github.com/paritytech/polkadot/issues/159) diff --git a/polkadot/validation/src/block_production.rs b/polkadot/validation/src/block_production.rs deleted file mode 100644 index 517d8ced816830ea33f88493e18444c3d9dfa7f9..0000000000000000000000000000000000000000 --- a/polkadot/validation/src/block_production.rs +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. - -//! The block production pipeline of Polkadot. -//! -//! The `ProposerFactory` exported by this module will be wrapped by some -//! consensus engine, and triggered when it is time to create a block. - -use std::{ - pin::Pin, - sync::Arc, - time::Duration, -}; - -use sp_blockchain::HeaderBackend; -use block_builder::{BlockBuilderApi, BlockBuilderProvider}; -use consensus::{Proposal, RecordProof}; -use primitives::traits::SpawnNamed; -use polkadot_primitives::v0::{NEW_HEADS_IDENTIFIER, Block, Header, AttestedCandidate}; -use runtime_primitives::traits::{DigestFor, HashFor}; -use txpool_api::TransactionPool; - -use futures::prelude::*; -use inherents::InherentData; -use sp_api::{ApiExt, ProvideRuntimeApi}; -use prometheus_endpoint::Registry as PrometheusRegistry; - -use crate::Error; - -// Polkadot proposer factory. -pub struct ProposerFactory<Client, TxPool, Backend> { - factory: sc_basic_authorship::ProposerFactory<TxPool, Backend, Client>, -} - -impl<Client, TxPool, Backend> ProposerFactory<Client, TxPool, Backend> { - /// Create a new proposer factory. - pub fn new( - spawn_handle: Box<dyn SpawnNamed>, - client: Arc<Client>, - transaction_pool: Arc<TxPool>, - prometheus: Option<&PrometheusRegistry>, - ) -> Self { - let factory = sc_basic_authorship::ProposerFactory::new( - spawn_handle, - client, - transaction_pool, - prometheus, - ); - ProposerFactory { - factory, - } - } -} - -impl<Client, TxPool, Backend> consensus::Environment<Block> - for ProposerFactory<Client, TxPool, Backend> -where - TxPool: TransactionPool<Block=Block> + 'static, - Client: BlockBuilderProvider<Backend, Block, Client> + ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static, - Client::Api: BlockBuilderApi<Block> - + ApiExt<Block, Error = sp_blockchain::Error>, - Backend: sc_client_api::Backend< - Block, - State = sp_api::StateBackendFor<Client, Block> - > + 'static, - // Rust bug: https://github.com/rust-lang/rust/issues/24159 - sp_api::StateBackendFor<Client, Block>: sp_api::StateBackend<HashFor<Block>> + Send, -{ - type CreateProposer = Pin<Box< - dyn Future<Output = Result<Self::Proposer, Self::Error>> + Send + 'static - >>; - type Proposer = Proposer<Client, TxPool, Backend>; - type Error = Error; - - fn init( - &mut self, - parent_header: &Header, - ) -> Self::CreateProposer { - let proposer = self.factory.init(parent_header) - .into_inner() - .map_err(Into::into) - .map(|proposer| Proposer { proposer }); - - Box::pin(future::ready(proposer)) - } -} - -/// The Polkadot proposer logic. -pub struct Proposer<Client, TxPool: TransactionPool<Block=Block>, Backend> { - proposer: sc_basic_authorship::Proposer<Backend, Block, Client, TxPool>, -} - -impl<Client, TxPool, Backend> consensus::Proposer<Block> for Proposer<Client, TxPool, Backend> where - TxPool: TransactionPool<Block=Block> + 'static, - Client: BlockBuilderProvider<Backend, Block, Client> + ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static, - Client::Api: BlockBuilderApi<Block> + ApiExt<Block, Error = sp_blockchain::Error>, - Backend: sc_client_api::Backend<Block, State = sp_api::StateBackendFor<Client, Block>> + 'static, - // Rust bug: https://github.com/rust-lang/rust/issues/24159 - sp_api::StateBackendFor<Client, Block>: sp_api::StateBackend<HashFor<Block>> + Send, -{ - type Error = Error; - type Transaction = sp_api::TransactionFor<Client, Block>; - type Proposal = Pin< - Box< - dyn Future<Output = Result< - Proposal<Block, sp_api::TransactionFor<Client, Block>>, - Self::Error, - >> - + Send - > - >; - - fn propose( - self, - inherent_data: InherentData, - inherent_digests: DigestFor<Block>, - max_duration: Duration, - record_proof: RecordProof, - ) -> Self::Proposal { - async move { - let mut inherent_data = inherent_data; - inherent_data.put_data(NEW_HEADS_IDENTIFIER, &Vec::<AttestedCandidate>::new()) - .map_err(Error::InherentError)?; - - self.proposer.propose( - inherent_data, - inherent_digests.clone(), - max_duration, - record_proof - ).await.map_err(Into::into) - }.boxed() - } -} diff --git a/polkadot/validation/src/error.rs b/polkadot/validation/src/error.rs deleted file mode 100644 index 0665a70f331289ae2508a84d07365f7d96e652f6..0000000000000000000000000000000000000000 --- a/polkadot/validation/src/error.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017-2020 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. - -//! Errors that can occur during the validation process. - -use thiserror::Error; - -/// Error type for validation -#[derive(Debug, Error)] -pub enum Error { - /// Client error - #[error(transparent)] - Client(#[from] sp_blockchain::Error), - /// Consensus error - #[error(transparent)] - Consensus(#[from] consensus::error::Error), - /// Unexpected error checking inherents - #[error("Unexpected error while checking inherents: {0}")] - InherentError(inherents::Error), -} - - -impl std::convert::From<inherents::Error> for Error { - fn from(inner: inherents::Error) -> Self { - Self::InherentError(inner) - } -} diff --git a/polkadot/validation/src/lib.rs b/polkadot/validation/src/lib.rs deleted file mode 100644 index ff86cdd11d914467c795b1741b30325b301fa0c2..0000000000000000000000000000000000000000 --- a/polkadot/validation/src/lib.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017-2020 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. - -//! Propagation and agreement of candidates. -//! -//! Authorities are split into groups by parachain, and each authority might come -//! up its own candidate for their parachain. Within groups, authorities pass around -//! their candidates and produce statements of validity. -//! -//! Any candidate that receives majority approval by the authorities in a group -//! may be subject to inclusion, unless any authorities flag that candidate as invalid. -//! -//! Wrongly flagging as invalid should be strongly disincentivized, so that in the -//! equilibrium state it is not expected to happen. Likewise with the submission -//! of invalid blocks. -//! -//! Groups themselves may be compromised by malicious authorities. - -pub use self::block_production::ProposerFactory; -pub use self::error::Error; -pub use parachain::wasm_executor::run_worker as run_validation_worker; - -mod error; - -pub mod block_production;