From c463b53bb9b87f56020bb4594d65deb328e17e4c Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Sat, 18 Dec 2021 08:29:54 +0800 Subject: [PATCH] Introduce OpaqueBundle and integrate tx pool in bundle production (#206) * Introduce OpaqueBundle and integrate tx pool in bundle production `OpaqueBundle` with opaque extrinsics will be used on primary chain as the primary chain does not care about the extrinsic format, it can be evolved as `CompactBundle` or something like that in the future. This PR also starts an initial transaction pool integration in bundle production, not the final version, but should be a step towards it. Co-authored-by: Nazar Mokrynskyi --- .github/workflows/rust.yaml | 6 +- .github/workflows/rustdoc.yml | 3 +- .github/workflows/snapshot-build.yml | 3 +- Cargo.lock | 3 + Dockerfile-farmer | 5 +- Dockerfile-node | 5 +- crates/cirrus-node-primitives/src/lib.rs | 12 +-- crates/pallet-executor/src/lib.rs | 21 ++-- crates/sp-executor/src/lib.rs | 76 +++++++++++++-- crates/subspace-runtime/src/lib.rs | 14 +-- cumulus/client/cirrus-executor/Cargo.toml | 4 +- cumulus/client/cirrus-executor/src/lib.rs | 96 ++++++++++++++----- cumulus/client/cirrus-service/Cargo.toml | 1 + cumulus/client/cirrus-service/src/lib.rs | 11 ++- .../parachain-template/node/src/service.rs | 3 +- polkadot/node/collation-generation/src/lib.rs | 6 +- polkadot/node/core/runtime-api/src/lib.rs | 6 +- .../tests/ui/err-01-duplicate-consumer.stderr | 8 +- polkadot/node/subsystem-types/src/messages.rs | 6 +- polkadot/node/subsystem-util/src/lib.rs | 4 +- rust-toolchain.toml | 3 +- 21 files changed, 214 insertions(+), 82 deletions(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index b0c5971eec..6b18407b10 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -56,7 +56,8 @@ jobs: uses: actions-rs/toolchain@v1 # TODO: Below can be removed when https://github.com/actions-rs/toolchain/issues/126 is resolved with: - toolchain: nightly + # TODO: roll back to nightly on new wasmtime release, ref https://github.com/bytecodealliance/rustix/issues/142 + toolchain: nightly-2021-12-14 target: wasm32-unknown-unknown override: true components: rustfmt, clippy @@ -110,7 +111,8 @@ jobs: uses: actions-rs/toolchain@v1 # TODO: Below can be removed when https://github.com/actions-rs/toolchain/issues/126 is resolved with: - toolchain: nightly + # TODO: roll back to nightly on new wasmtime release, ref https://github.com/bytecodealliance/rustix/issues/142 + toolchain: nightly-2021-12-14 target: wasm32-unknown-unknown override: true components: rustfmt, clippy diff --git a/.github/workflows/rustdoc.yml b/.github/workflows/rustdoc.yml index 5107e38546..3375984100 100644 --- a/.github/workflows/rustdoc.yml +++ b/.github/workflows/rustdoc.yml @@ -21,7 +21,8 @@ jobs: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly + # TODO: roll back to nightly on new wasmtime release, ref https://github.com/bytecodealliance/rustix/issues/142 + toolchain: nightly-2021-12-14 target: wasm32-unknown-unknown profile: minimal override: true diff --git a/.github/workflows/snapshot-build.yml b/.github/workflows/snapshot-build.yml index 01c9b959ea..609d6b6741 100644 --- a/.github/workflows/snapshot-build.yml +++ b/.github/workflows/snapshot-build.yml @@ -100,7 +100,8 @@ jobs: uses: actions-rs/toolchain@v1 # TODO: Below can be removed when https://github.com/actions-rs/toolchain/issues/126 is resolved with: - toolchain: nightly + # TODO: roll back to nightly on new wasmtime release, ref https://github.com/bytecodealliance/rustix/issues/142 + toolchain: nightly-2021-12-14 target: wasm32-unknown-unknown override: true diff --git a/Cargo.lock b/Cargo.lock index 58ae6a6e53..9966062623 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -791,11 +791,13 @@ dependencies = [ "cirrus-node-primitives", "cumulus-client-consensus-common", "futures 0.3.18", + "futures-timer 3.0.2", "parity-scale-codec", "parking_lot 0.10.2", "polkadot-node-subsystem", "polkadot-overseer", "sc-client-api", + "sc-transaction-pool-api", "sp-api", "sp-blockchain", "sp-consensus", @@ -823,6 +825,7 @@ dependencies = [ "sc-service", "sc-telemetry", "sc-tracing", + "sc-transaction-pool-api", "sp-api", "sp-blockchain", "sp-consensus", diff --git a/Dockerfile-farmer b/Dockerfile-farmer index 92ed3778af..4f67e4c5d7 100644 --- a/Dockerfile-farmer +++ b/Dockerfile-farmer @@ -1,5 +1,8 @@ FROM ubuntu:20.04 +# TODO: roll back to nightly on new wasmtime release, ref https://github.com/bytecodealliance/rustix/issues/142 +ARG RUSTC_VERSION=nightly-2021-12-14 + WORKDIR /code RUN \ @@ -10,7 +13,7 @@ RUN \ git \ llvm \ clang && \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown diff --git a/Dockerfile-node b/Dockerfile-node index 5240126683..d7c6251d53 100644 --- a/Dockerfile-node +++ b/Dockerfile-node @@ -1,5 +1,8 @@ FROM ubuntu:20.04 +# TODO: roll back to nightly on new wasmtime release, ref https://github.com/bytecodealliance/rustix/issues/142 +ARG RUSTC_VERSION=nightly-2021-12-14 + WORKDIR /code RUN \ @@ -10,7 +13,7 @@ RUN \ git \ llvm \ clang && \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown diff --git a/crates/cirrus-node-primitives/src/lib.rs b/crates/cirrus-node-primitives/src/lib.rs index c7476adfb1..8beefdc876 100644 --- a/crates/cirrus-node-primitives/src/lib.rs +++ b/crates/cirrus-node-primitives/src/lib.rs @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize}; use sp_application_crypto::KeyTypeId; use sp_consensus_slots::Slot; use sp_core::bytes; -use sp_executor::{Bundle, ExecutionReceipt}; +use sp_executor::{ExecutionReceipt, OpaqueBundle}; use sp_runtime::traits::Hash as HashT; use std::pin::Pin; use subspace_core_primitives::Tag; @@ -83,13 +83,13 @@ pub struct CollationResult { /// Result of the [`BundlerFn`] invocation. pub struct BundleResult { - /// The bundle that was built. - pub bundle: Bundle, + /// The opaque bundle that was built. + pub opaque_bundle: OpaqueBundle, } impl BundleResult { - pub fn to_bundle(self) -> Bundle { - self.bundle + pub fn to_opaque_bundle(self) -> OpaqueBundle { + self.opaque_bundle } } @@ -163,7 +163,7 @@ pub type BundlerFn = Box< /// /// Returns an optional [`ProcessorResult`]. pub type ProcessorFn = Box< - dyn Fn(Hash, Vec) -> Pin> + Send>> + dyn Fn(Hash, Vec) -> Pin> + Send>> + Send + Sync, >; diff --git a/crates/pallet-executor/src/lib.rs b/crates/pallet-executor/src/lib.rs index 0cfc8f329d..a8b8dd92b3 100644 --- a/crates/pallet-executor/src/lib.rs +++ b/crates/pallet-executor/src/lib.rs @@ -19,7 +19,7 @@ use frame_system::offchain::SubmitTransaction; pub use pallet::*; -use sp_executor::{Bundle, ExecutionReceipt, FraudProof}; +use sp_executor::{ExecutionReceipt, FraudProof, OpaqueBundle}; // TODO: proper error value const INVALID_FRAUD_PROOF: u8 = 100; @@ -30,7 +30,7 @@ mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_core::H256; - use sp_executor::{Bundle, ExecutionReceipt, FraudProof}; + use sp_executor::{ExecutionReceipt, FraudProof, OpaqueBundle}; #[pallet::config] pub trait Config: frame_system::Config { @@ -125,17 +125,20 @@ mod pallet { } #[pallet::weight((10_000, Pays::No))] - pub fn submit_transaction_bundle(origin: OriginFor, bundle: Bundle) -> DispatchResult { + pub fn submit_transaction_bundle( + origin: OriginFor, + opaque_bundle: OpaqueBundle, + ) -> DispatchResult { ensure_none(origin)?; log::debug!( target: "runtime::subspace::executor", "Submitting transaction bundle: {:?}", - bundle + opaque_bundle ); Self::deposit_event(Event::TransactionBundleStored { - bundle_hash: bundle.hash(), + bundle_hash: opaque_bundle.hash(), }); Ok(()) @@ -209,12 +212,12 @@ mod pallet { .propagate(true) .build() } - Call::submit_transaction_bundle { bundle } => { + Call::submit_transaction_bundle { opaque_bundle } => { // TODO: validate the Proof-of-Election ValidTransaction::with_tag_prefix("SubspaceSubmitTransactionBundle") .priority(TransactionPriority::MAX) - .and_provides(bundle.hash()) + .and_provides(opaque_bundle.hash()) .longevity(TransactionLongevity::MAX) // We need this extrinsic to be propagted to the farmer nodes. .propagate(true) @@ -313,9 +316,9 @@ where /// Submits an unsigned extrinsic [`Call::submit_transaction_bundle`]. pub fn submit_transaction_bundle_unsigned( - bundle: Bundle, + opaque_bundle: OpaqueBundle, ) -> frame_support::pallet_prelude::DispatchResult { - let call = Call::submit_transaction_bundle { bundle }; + let call = Call::submit_transaction_bundle { opaque_bundle }; match SubmitTransaction::>::submit_unsigned_transaction(call.into()) { Ok(()) => log::info!( diff --git a/crates/sp-executor/src/lib.rs b/crates/sp-executor/src/lib.rs index 45d7018603..c38efaa371 100644 --- a/crates/sp-executor/src/lib.rs +++ b/crates/sp-executor/src/lib.rs @@ -19,27 +19,83 @@ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; -use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT}; +use sp_core::H256; +use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Hash as HashT, Header as HeaderT}; use sp_runtime::{OpaqueExtrinsic, RuntimeDebug}; use sp_std::vec::Vec; use sp_trie::StorageProof; -/// Dummy bundle header. -pub type BundleHeader = Vec; +/// Header of transaction bundle. +#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)] +pub struct BundleHeader { + /// The slot number. + pub slot_number: u64, + /// The merkle root of the extrinsics. + pub extrinsics_root: H256, +} + +impl BundleHeader { + /// Returns the hash of this header. + pub fn hash(&self) -> H256 { + BlakeTwo256::hash_of(self) + } +} /// Transaction bundle #[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)] -pub struct Bundle { +pub struct Bundle { /// The bundle header. pub header: BundleHeader, /// THe accompanying extrinsics. - pub opaque_transactions: Vec, + pub extrinsics: Vec, +} + +impl Bundle { + /// Returns the hash of this bundle. + pub fn hash(&self) -> H256 { + self.header.hash() + } +} + +// TODO: Replace with `sp_runtime::OpaqueExtrinsic` once Substrate is upgraded with +// https://github.com/paritytech/substrate/pull/10504 included +/// Encoded extrinsic. +#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)] +pub struct EncodedExtrinsic(Vec); + +impl From> for EncodedExtrinsic { + fn from(inner: Vec) -> Self { + Self(inner) + } } -impl Bundle { +/// Bundle with opaque extrinsics. +#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)] +pub struct OpaqueBundle { + /// The bundle header. + pub header: BundleHeader, + /// THe accompanying opaque extrinsics. + pub opaque_extrinsics: Vec, +} + +impl OpaqueBundle { /// Returns the hash of this bundle. - pub fn hash(&self) -> sp_core::H256 { - sp_runtime::traits::BlakeTwo256::hash(&self.header) + pub fn hash(&self) -> H256 { + self.header.hash() + } +} + +impl From> for OpaqueBundle { + fn from(bundle: Bundle) -> Self { + let Bundle { header, extrinsics } = bundle; + let opaque_extrinsics = extrinsics + .into_iter() + .map(|xt| xt.encode().into()) + .collect(); + Self { + header, + opaque_extrinsics, + } } } @@ -85,13 +141,13 @@ sp_api::decl_runtime_apis! { ) -> Option<()>; /// Submits the transaction bundle via an unsigned extrinsic. - fn submit_transaction_bundle_unsigned(bundle: Bundle) -> Option<()>; + fn submit_transaction_bundle_unsigned(opaque_bundle: OpaqueBundle) -> Option<()>; /// Submits the fraud proof via an unsigned extrinsic. fn submit_fraud_proof_unsigned(fraud_proof: FraudProof) -> Option<()>; /// Extract the bundles from extrinsics in a block. - fn extract_bundles(extrinsics: Vec) -> Vec; + fn extract_bundles(extrinsics: Vec) -> Vec; /// Returns the block hash given the block number. fn head_hash( diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index 63a6129f4b..d25d7c4362 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -38,7 +38,7 @@ use sp_consensus_subspace::{ SubspaceGenesisConfiguration, }; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; -use sp_executor::{Bundle, FraudProof}; +use sp_executor::{FraudProof, OpaqueBundle}; use sp_runtime::traits::{ AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Header as HeaderT, PostDispatchInfoOf, Zero, @@ -734,17 +734,17 @@ fn extract_block_object_mapping(block: Block) -> BlockObjectMapping { block_object_mapping } -fn extract_bundles(extrinsics: Vec) -> Vec { +fn extract_bundles(extrinsics: Vec) -> Vec { extrinsics .into_iter() .filter_map(|opaque_extrinsic| { match ::decode(&mut opaque_extrinsic.encode().as_slice()) { Ok(uxt) => { if let Call::Executor(pallet_executor::Call::submit_transaction_bundle { - bundle, + opaque_bundle, }) = uxt.function { - Some(bundle) + Some(opaque_bundle) } else { None } @@ -902,15 +902,15 @@ impl_runtime_apis! { Executor::submit_execution_receipt_unsigned(execution_receipt).ok() } - fn submit_transaction_bundle_unsigned(bundle: Bundle) -> Option<()> { - Executor::submit_transaction_bundle_unsigned(bundle).ok() + fn submit_transaction_bundle_unsigned(opaque_bundle: OpaqueBundle) -> Option<()> { + Executor::submit_transaction_bundle_unsigned(opaque_bundle).ok() } fn submit_fraud_proof_unsigned(fraud_proof: FraudProof) -> Option<()> { Executor::submit_fraud_proof_unsigned(fraud_proof).ok() } - fn extract_bundles(extrinsics: Vec) -> Vec { + fn extract_bundles(extrinsics: Vec) -> Vec { extract_bundles(extrinsics) } diff --git a/cumulus/client/cirrus-executor/Cargo.toml b/cumulus/client/cirrus-executor/Cargo.toml index 4801f9e01d..58b49e66cc 100644 --- a/cumulus/client/cirrus-executor/Cargo.toml +++ b/cumulus/client/cirrus-executor/Cargo.toml @@ -6,13 +6,14 @@ edition = "2021" [dependencies] # Substrate dependencies +sc-client-api = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sp-runtime = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sp-core = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sp-consensus = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sp-api = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sp-blockchain = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sp-trie = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } -sc-client-api = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } # Cumulus dependencies cumulus-client-consensus-common = { path = "../consensus/common" } @@ -20,6 +21,7 @@ cumulus-client-consensus-common = { path = "../consensus/common" } # Other dependencies codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } futures = { version = "0.3.1", features = ["compat"] } +futures-timer = "3.0.1" parking_lot = "0.10.2" tracing = "0.1.25" diff --git a/cumulus/client/cirrus-executor/src/lib.rs b/cumulus/client/cirrus-executor/src/lib.rs index 88e5f29ae1..8ec626af16 100644 --- a/cumulus/client/cirrus-executor/src/lib.rs +++ b/cumulus/client/cirrus-executor/src/lib.rs @@ -18,13 +18,14 @@ #![allow(clippy::all)] use sc_client_api::BlockBackend; +use sc_transaction_pool_api::InPoolTransaction; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_consensus::BlockStatus; use sp_core::traits::SpawnNamed; use sp_runtime::{ generic::BlockId, - traits::{Block as BlockT, Header as HeaderT, Zero}, + traits::{BlakeTwo256, Block as BlockT, Hash as HashT, Header as HeaderT, Zero}, SaturatedConversion, }; use sp_trie::StorageProof; @@ -38,27 +39,30 @@ use cirrus_node_primitives::{ BundleResult, Collation, CollationGenerationConfig, CollationResult, CollatorPair, ExecutorSlotInfo, HeadData, PersistedValidationData, ProcessorResult, }; -use sp_executor::{Bundle, ExecutionReceipt, FraudProof}; +use sp_executor::{Bundle, BundleHeader, ExecutionReceipt, FraudProof, OpaqueBundle}; use subspace_runtime_primitives::Hash as PHash; use codec::{Decode, Encode}; -use futures::FutureExt; -use std::sync::Arc; +use futures::{select, FutureExt}; +use std::{sync::Arc, time}; use tracing::Instrument; /// The logging target. const LOG_TARGET: &str = "cirrus::executor"; /// The implementation of the Cirrus `Executor`. -pub struct Executor { +pub struct Executor { block_status: Arc, parachain_consensus: Box>, runtime_api: Arc, client: Arc, overseer_handle: OverseerHandle, + transaction_pool: Arc, } -impl Clone for Executor { +impl Clone + for Executor +{ fn clone(&self) -> Self { Self { block_status: self.block_status.clone(), @@ -66,16 +70,18 @@ impl Clone for Executor { runtime_api: self.runtime_api.clone(), client: self.client.clone(), overseer_handle: self.overseer_handle.clone(), + transaction_pool: self.transaction_pool.clone(), } } } -impl Executor +impl Executor where Block: BlockT, Client: sp_blockchain::HeaderBackend, BS: BlockBackend, RA: ProvideRuntimeApi, + TransactionPool: sc_transaction_pool_api::TransactionPool, { /// Create a new instance. fn new( @@ -84,8 +90,16 @@ where parachain_consensus: Box>, client: Arc, overseer_handle: OverseerHandle, + transaction_pool: Arc, ) -> Self { - Self { block_status, runtime_api, parachain_consensus, client, overseer_handle } + Self { + block_status, + runtime_api, + parachain_consensus, + client, + overseer_handle, + transaction_pool, + } } /// Checks the status of the given block hash in the Parachain. @@ -253,29 +267,60 @@ where async fn produce_bundle(self, slot_info: ExecutorSlotInfo) -> Option { println!("TODO: solve some puzzle based on `slot_info` to be allowed to produce a bundle"); - let transactions = { - // selection policy: minimize the transaction equivocation. - println!("TODO: once elected, select unseen transactions from the transaction pool"); - b"some transactions".to_vec() + // TODO: ready at the best number of primary block? + let parent_number = self.client.info().best_number; + let mut t1 = self.transaction_pool.ready_at(parent_number).fuse(); + // TODO: proper timeout + let mut t2 = futures_timer::Delay::new(time::Duration::from_micros(100)).fuse(); + + let mut pending_iterator = select! { + res = t1 => res, + _ = t2 => { + tracing::warn!( + "Timeout fired waiting for transaction pool at {}, proceeding with production.", + parent_number, + ); + self.transaction_pool.ready() + } }; - let _transactions_root = b"merkle root of transactions".to_vec(); + // TODO: proper deadline + let pushing_duration = time::Duration::from_micros(500); + + let start = time::Instant::now(); + + // TODO: Select transactions properly from the transaction pool + // + // Selection policy: + // - minimize the transaction equivocation. + // - maximize the executor computation power. + let mut extrinsics = Vec::new(); + while let Some(pending_tx) = pending_iterator.next() { + if start.elapsed() >= pushing_duration { + break + } + let pending_tx_data = pending_tx.data().clone(); + extrinsics.push(pending_tx_data); + } + + let extrinsics_root = + BlakeTwo256::ordered_trie_root(extrinsics.iter().map(|xt| xt.encode()).collect()); let best_hash = self.client.info().best_hash; let _state_root = self.client.expect_header(BlockId::Hash(best_hash)).ok()?.state_root(); - Some(BundleResult { - bundle: Bundle { - header: slot_info.slot.to_be_bytes().to_vec(), - opaque_transactions: transactions, - }, - }) + let bundle = Bundle { + header: BundleHeader { slot_number: slot_info.slot.into(), extrinsics_root }, + extrinsics, + }; + + Some(BundleResult { opaque_bundle: bundle.into() }) } async fn process_bundles( self, primary_hash: PHash, - _bundles: Vec, + _bundles: Vec, ) -> Option { // TODO: // 1. convert the bundles to a full tx list @@ -311,7 +356,7 @@ where } /// Parameters for [`start_executor`]. -pub struct StartExecutorParams { +pub struct StartExecutorParams { pub client: Arc, pub runtime_api: Arc, pub block_status: Arc, @@ -320,10 +365,11 @@ pub struct StartExecutorParams { pub spawner: Spawner, pub key: CollatorPair, pub parachain_consensus: Box>, + pub transaction_pool: Arc, } /// Start the executor. -pub async fn start_executor( +pub async fn start_executor( StartExecutorParams { client, block_status, @@ -333,13 +379,16 @@ pub async fn start_executor( key, parachain_consensus, runtime_api, - }: StartExecutorParams, + transaction_pool, + }: StartExecutorParams, ) where Block: BlockT, BS: BlockBackend + Send + Sync + 'static, Spawner: SpawnNamed + Clone + Send + Sync + 'static, Client: HeaderBackend + Send + Sync + 'static, RA: ProvideRuntimeApi + Send + Sync + 'static, + TransactionPool: + sc_transaction_pool_api::TransactionPool + Send + Sync + 'static, { let executor = Executor::new( block_status, @@ -347,6 +396,7 @@ pub async fn start_executor( parachain_consensus, client, overseer_handle.clone(), + transaction_pool, ); let span = tracing::Span::current(); diff --git a/cumulus/client/cirrus-service/Cargo.toml b/cumulus/client/cirrus-service/Cargo.toml index 5ee198ba09..03536a3dd1 100644 --- a/cumulus/client/cirrus-service/Cargo.toml +++ b/cumulus/client/cirrus-service/Cargo.toml @@ -14,6 +14,7 @@ sc-client-api = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1 sc-service = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sc-telemetry = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sc-tracing = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sc-consensus-babe = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sc-consensus = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } sp-consensus = { git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" } diff --git a/cumulus/client/cirrus-service/src/lib.rs b/cumulus/client/cirrus-service/src/lib.rs index 75554b1f59..6bc0a96945 100644 --- a/cumulus/client/cirrus-service/src/lib.rs +++ b/cumulus/client/cirrus-service/src/lib.rs @@ -30,6 +30,7 @@ use sc_consensus::{ BlockImport, }; use sc_service::{Configuration, Role, TaskManager}; +use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_consensus::BlockOrigin; @@ -64,7 +65,7 @@ impl Deref for PrimaryFullNode { } /// Parameters given to [`start_executor`]. -pub struct StartExecutorParams<'a, Block: BlockT, BS, Client, Spawner, RClient, IQ> { +pub struct StartExecutorParams<'a, Block: BlockT, BS, Client, Spawner, RClient, IQ, TP> { pub block_status: Arc, pub client: Arc, pub announce_block: Arc>) + Send + Sync>, @@ -73,10 +74,11 @@ pub struct StartExecutorParams<'a, Block: BlockT, BS, Client, Spawner, RClient, pub task_manager: &'a mut TaskManager, pub parachain_consensus: Box>, pub import_queue: IQ, + pub transaction_pool: Arc, } /// Start an executor node. -pub async fn start_executor<'a, Block, BS, Client, Backend, Spawner, RClient, IQ>( +pub async fn start_executor<'a, Block, BS, Client, Backend, Spawner, RClient, IQ, TP>( StartExecutorParams { block_status, client, @@ -86,7 +88,8 @@ pub async fn start_executor<'a, Block, BS, Client, Backend, Spawner, RClient, IQ primary_chain_full_node, parachain_consensus, import_queue: _, - }: StartExecutorParams<'a, Block, BS, Client, Spawner, RClient, IQ>, + transaction_pool, + }: StartExecutorParams<'a, Block, BS, Client, Spawner, RClient, IQ, TP>, ) -> sc_service::error::Result<()> where Block: BlockT, @@ -105,6 +108,7 @@ where Spawner: SpawnNamed + Clone + Send + Sync + 'static, Backend: BackendT + 'static, IQ: ImportQueue + 'static, + TP: TransactionPool + 'static, { let consensus = cumulus_client_consensus_common::run_parachain_consensus( client.clone(), @@ -127,6 +131,7 @@ where spawner, key: primary_chain_full_node.collator_key.clone(), parachain_consensus, + transaction_pool, }) .await; diff --git a/cumulus/parachain-template/node/src/service.rs b/cumulus/parachain-template/node/src/service.rs index ab4d035afb..92adc416d2 100644 --- a/cumulus/parachain-template/node/src/service.rs +++ b/cumulus/parachain-template/node/src/service.rs @@ -294,7 +294,7 @@ where telemetry.as_ref().map(|t| t.handle()), &task_manager, &relay_chain_full_node, - transaction_pool, + transaction_pool.clone(), network, params.keystore_container.sync_keystore(), force_authoring, @@ -311,6 +311,7 @@ where spawner, parachain_consensus, import_queue, + transaction_pool, }; cirrus_client_service::start_executor(params).await?; diff --git a/polkadot/node/collation-generation/src/lib.rs b/polkadot/node/collation-generation/src/lib.rs index 8f265c40b3..b3f76c7943 100644 --- a/polkadot/node/collation-generation/src/lib.rs +++ b/polkadot/node/collation-generation/src/lib.rs @@ -365,8 +365,8 @@ async fn produce_bundle( ctx: &mut Context, sender: &mpsc::Sender, ) -> SubsystemResult<()> { - let bundle = match (config.bundler)(slot_info).await { - Some(bundle_result) => bundle_result.to_bundle(), + let opaque_bundle = match (config.bundler)(slot_info).await { + Some(bundle_result) => bundle_result.to_opaque_bundle(), None => { tracing::debug!(target: LOG_TARGET, "executor returned no bundle on bundling",); return Ok(()) @@ -382,7 +382,7 @@ async fn produce_bundle( if let Err(err) = task_sender .send(AllMessages::RuntimeApi(RuntimeApiMessage::Request( best_hash, - RuntimeApiRequest::SubmitTransactionBundle(bundle), + RuntimeApiRequest::SubmitTransactionBundle(opaque_bundle), ))) .await { diff --git a/polkadot/node/core/runtime-api/src/lib.rs b/polkadot/node/core/runtime-api/src/lib.rs index 886786d6d9..74211875e4 100644 --- a/polkadot/node/core/runtime-api/src/lib.rs +++ b/polkadot/node/core/runtime-api/src/lib.rs @@ -280,11 +280,11 @@ where RequestResult::SubmitExecutionReceipt(relay_parent, execution_receipt_hash) }); }, - Request::SubmitTransactionBundle(bundle) => { + Request::SubmitTransactionBundle(opaque_bundle) => { let api = client.runtime_api(); - let bundle_hash = bundle.hash(); + let bundle_hash = opaque_bundle.hash(); let res = api - .submit_transaction_bundle_unsigned(&BlockId::Hash(relay_parent), bundle) + .submit_transaction_bundle_unsigned(&BlockId::Hash(relay_parent), opaque_bundle) .map_err(|e| RuntimeApiError::from(format!("{:?}", e))); metrics.on_request(res.is_ok()); res.ok() diff --git a/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr b/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr index a34a10c73c..a66f2fa3e7 100644 --- a/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr +++ b/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr @@ -1,21 +1,21 @@ -error[E0119]: conflicting implementations of trait `polkadot_overseer_gen::SubsystemSender` for type `OverseerSubsystemSender` +error[E0119]: conflicting implementations of trait `std::convert::From` for type `AllMessages` --> $DIR/err-01-duplicate-consumer.rs:19:1 | 19 | #[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | first implementation here - | conflicting implementation for `OverseerSubsystemSender` + | conflicting implementation for `AllMessages` | = note: this error originates in the attribute macro `overlord` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0119]: conflicting implementations of trait `std::convert::From` for type `AllMessages` +error[E0119]: conflicting implementations of trait `polkadot_overseer_gen::SubsystemSender` for type `OverseerSubsystemSender` --> $DIR/err-01-duplicate-consumer.rs:19:1 | 19 | #[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | first implementation here - | conflicting implementation for `AllMessages` + | conflicting implementation for `OverseerSubsystemSender` | = note: this error originates in the attribute macro `overlord` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/polkadot/node/subsystem-types/src/messages.rs b/polkadot/node/subsystem-types/src/messages.rs index b8ac1462d9..ea1674fbe9 100644 --- a/polkadot/node/subsystem-types/src/messages.rs +++ b/polkadot/node/subsystem-types/src/messages.rs @@ -27,7 +27,7 @@ use futures::channel::oneshot; pub use sc_network::IfDisconnected; use cirrus_node_primitives::{BlockWeight, CollationGenerationConfig}; -use sp_executor::{Bundle, ExecutionReceipt, FraudProof}; +use sp_executor::{ExecutionReceipt, FraudProof, OpaqueBundle}; use sp_runtime::OpaqueExtrinsic; use subspace_runtime_primitives::{opaque::Header as BlockHeader, BlockNumber, Hash}; @@ -110,11 +110,11 @@ pub enum RuntimeApiRequest { /// Submit the execution receipt to primary chain. SubmitExecutionReceipt(ExecutionReceipt), /// Submit the transaction bundle to primary chain. - SubmitTransactionBundle(Bundle), + SubmitTransactionBundle(OpaqueBundle), /// Submit the fraud proof to primary chain. SubmitFraudProof(FraudProof), /// Extract the bundles from the extrinsics of a block. - ExtractBundles(Vec, RuntimeApiSender>), + ExtractBundles(Vec, RuntimeApiSender>), /// Get the pending head of executor chain. PendingHead(RuntimeApiSender>), } diff --git a/polkadot/node/subsystem-util/src/lib.rs b/polkadot/node/subsystem-util/src/lib.rs index f0dd976781..13b7a9e095 100644 --- a/polkadot/node/subsystem-util/src/lib.rs +++ b/polkadot/node/subsystem-util/src/lib.rs @@ -51,7 +51,7 @@ use futures::{ use pin_project::pin_project; use polkadot_node_jaeger as jaeger; use sp_core::traits::SpawnNamed; -use sp_executor::Bundle; +use sp_executor::OpaqueBundle; use sp_runtime::OpaqueExtrinsic; use std::{ collections::{hash_map::Entry, HashMap}, @@ -184,7 +184,7 @@ macro_rules! specialize_requests { specialize_requests! { fn request_pending_head() -> Option; PendingHead; - fn request_extract_bundles(extrinsics: Vec) -> Vec; ExtractBundles; + fn request_extract_bundles(extrinsics: Vec) -> Vec; ExtractBundles; } struct AbortOnDrop(future::AbortHandle); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 17ce332ff7..6acf759a6b 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,5 @@ [toolchain] -channel = "nightly" +# TODO: roll back to nightly on new wasmtime release, ref https://github.com/bytecodealliance/rustix/issues/142 +channel = "nightly-2021-12-14" targets = ["wasm32-unknown-unknown"] profile = "default"