Update Substrate & Polkadot (#84)

This commit is contained in:
Bastian Köcher
2020-04-29 14:23:18 +02:00
committed by GitHub
parent 06a36a6650
commit 5f008af15f
15 changed files with 398 additions and 406 deletions
+312 -282
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -11,7 +11,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-b
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
+18 -26
View File
@@ -18,17 +18,18 @@
use cumulus_runtime::ParachainBlockData;
use sc_client::Client;
use sp_consensus::{
BlockImport, BlockImportParams, BlockOrigin, Environment, Error as ConsensusError,
ForkChoiceStrategy, Proposal, Proposer, RecordProof,
};
use sp_inherents::InherentDataProviders;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, HashFor};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sc_client_api::{StateBackend, UsageProvider, Finalizer, BlockchainEvents};
use polkadot_collator::{
BuildParachainContext, InvalidHead, Network as CollatorNetwork, ParachainContext,
PolkadotClient,
RuntimeApiCollection,
};
use polkadot_primitives::{
parachain::{self, BlockData, GlobalValidationSchedule, LocalValidationData, Id as ParaId},
@@ -234,17 +235,17 @@ where
}
/// Implements `BuildParachainContext` to build a collator instance.
pub struct CollatorBuilder<Block: BlockT, PF, BI, Backend, Executor, Runtime> {
pub struct CollatorBuilder<Block: BlockT, PF, BI, Backend, Client> {
proposer_factory: PF,
inherent_data_providers: InherentDataProviders,
block_import: BI,
para_id: ParaId,
client: Arc<Client<Backend, Executor, Block, Runtime>>,
_marker: PhantomData<Block>,
client: Arc<Client>,
_marker: PhantomData<(Block, Backend)>,
}
impl<Block: BlockT, PF, BI, Backend, Executor, Runtime>
CollatorBuilder<Block, PF, BI, Backend, Executor, Runtime>
impl<Block: BlockT, PF, BI, Backend, Client>
CollatorBuilder<Block, PF, BI, Backend, Client>
{
/// Create a new instance of self.
pub fn new(
@@ -252,7 +253,7 @@ impl<Block: BlockT, PF, BI, Backend, Executor, Runtime>
inherent_data_providers: InherentDataProviders,
block_import: BI,
para_id: ParaId,
client: Arc<Client<Backend, Executor, Block, Runtime>>,
client: Arc<Client>,
) -> Self {
Self {
proposer_factory,
@@ -268,8 +269,8 @@ impl<Block: BlockT, PF, BI, Backend, Executor, Runtime>
type TransactionFor<E, Block> =
<<E as Environment<Block>>::Proposer as Proposer<Block>>::Transaction;
impl<Block: BlockT, PF, BI, Backend, Executor, Runtime> BuildParachainContext
for CollatorBuilder<Block, PF, BI, Backend, Executor, Runtime>
impl<Block: BlockT, PF, BI, Backend, Client> BuildParachainContext
for CollatorBuilder<Block, PF, BI, Backend, Client>
where
PF: Environment<Block> + Send + 'static,
BI: BlockImport<Block, Error = sp_consensus::Error, Transaction = TransactionFor<PF, Block>>
@@ -277,31 +278,22 @@ where
+ Sync
+ 'static,
Backend: sc_client_api::Backend<Block> + 'static,
Executor: sc_client_api::CallExecutor<Block> + Send + Sync + 'static,
Runtime: Send + Sync + 'static,
Client: Finalizer<Block, Backend> + UsageProvider<Block> + Send + Sync + 'static,
{
type ParachainContext = Collator<Block, PF, BI>;
fn build<B, E, R, Spawner, Extrinsic>(
fn build<PClient, Spawner, Extrinsic>(
self,
polkadot_client: Arc<PolkadotClient<B, E, R>>,
polkadot_client: Arc<PClient>,
spawner: Spawner,
network: impl CollatorNetwork + Clone + 'static,
) -> Result<Self::ParachainContext, ()>
where
PolkadotClient<B, E, R>: sp_api::ProvideRuntimeApi<PBlock>,
<PolkadotClient<B, E, R> as sp_api::ProvideRuntimeApi<PBlock>>::Api:
polkadot_service::RuntimeApiCollection<Extrinsic>,
E: sc_client::CallExecutor<PBlock> + Clone + Send + Sync + 'static,
PClient: ProvideRuntimeApi<PBlock> + Send + Sync + BlockchainEvents<PBlock> + 'static,
PClient::Api: RuntimeApiCollection<Extrinsic>,
<PClient::Api as ApiExt<PBlock>>::StateBackend: StateBackend<HashFor<PBlock>>,
Spawner: Spawn + Clone + Send + Sync + 'static,
Extrinsic: codec::Codec + Send + Sync + 'static,
<<PolkadotClient<B, E, R> as sp_api::ProvideRuntimeApi<PBlock>>::Api as sp_api::ApiExt<
PBlock,
>>::StateBackend: sp_api::StateBackend<sp_runtime::traits::BlakeTwo256>,
R: Send + Sync + 'static,
B: sc_client_api::Backend<PBlock> + 'static,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
B::State: sp_api::StateBackend<sp_runtime::traits::BlakeTwo256>,
{
let follow =
match cumulus_consensus::follow_polkadot(self.para_id, self.client, polkadot_client) {
-1
View File
@@ -7,7 +7,6 @@ edition = "2018"
[dependencies]
# substrate deps
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
+15 -23
View File
@@ -14,10 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use std::sync::Arc;
use std::{marker::PhantomData, sync::Arc};
use sc_client::Client;
use sc_client_api::{Backend, CallExecutor, TransactionFor};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::Result as ClientResult;
@@ -34,19 +32,17 @@ use sp_runtime::{
};
/// A verifier that just checks the inherents.
struct Verifier<B, E, Block: BlockT, RA> {
client: Arc<Client<B, E, Block, RA>>,
struct Verifier<Client, Block> {
client: Arc<Client>,
inherent_data_providers: InherentDataProviders,
_marker: PhantomData<Block>,
}
impl<B, E, Block, RA> VerifierT<Block> for Verifier<B, E, Block, RA>
impl<Client, Block> VerifierT<Block> for Verifier<Client, Block>
where
Block: BlockT,
B: Backend<Block> + 'static,
E: CallExecutor<Block> + 'static + Clone + Send + Sync,
RA: Send + Sync,
Client<B, E, Block, RA>: ProvideRuntimeApi<Block> + Send + Sync,
<Client<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
Client: ProvideRuntimeApi<Block> + Send + Sync,
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
{
fn verify(
&mut self,
@@ -101,25 +97,21 @@ where
}
/// Start an import queue for a Cumulus collator that does not uses any special authoring logic.
pub fn import_queue<B, E, Block: BlockT, I, RA>(
client: Arc<Client<B, E, Block, RA>>,
pub fn import_queue<Client, Block: BlockT, I>(
client: Arc<Client>,
block_import: I,
inherent_data_providers: InherentDataProviders,
) -> ClientResult<BasicQueue<Block, TransactionFor<B, Block>>>
) -> ClientResult<BasicQueue<Block, I::Transaction>>
where
B: Backend<Block> + 'static,
I: BlockImport<Block, Error = ConsensusError, Transaction = TransactionFor<B, Block>>
+ Send
+ Sync
+ 'static,
E: CallExecutor<Block> + Clone + Send + Sync + 'static,
RA: Send + Sync + 'static,
Client<B, E, Block, RA>: ProvideRuntimeApi<Block> + Send + Sync + 'static,
<Client<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
I: BlockImport<Block, Error = ConsensusError> + Send + Sync + 'static,
I::Transaction: Send,
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static,
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
{
let verifier = Verifier {
client,
inherent_data_providers,
_marker: PhantomData,
};
Ok(BasicQueue::new(
+31 -52
View File
@@ -14,11 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use sc_client::{BlockchainEvents, Client};
use sc_client_api::{
backend::{Backend, Finalizer, StateBackend, StateBackendFor},
CallExecutor,
};
use sc_client_api::{Backend, Finalizer, UsageProvider};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{Error as ClientError, Result as ClientResult};
use sp_consensus::{Error as ConsensusError, SelectChain as SelectChainT};
@@ -40,16 +36,6 @@ use std::{marker::PhantomData, sync::Arc};
pub mod import_queue;
/// Helper for the local client.
pub trait LocalClient {
/// The block type of the local client.
type Block: BlockT;
/// Finalize the given block.
/// Returns `false` if the block is not known.
fn finalize(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool>;
}
/// Errors that can occur while following the polkadot relay-chain.
#[derive(Debug)]
pub enum Error {
@@ -87,15 +73,38 @@ pub trait PolkadotClient: Clone + 'static {
) -> ClientResult<Option<Vec<u8>>>;
}
/// Finalize the given block in the Parachain.
fn finalize_block<T, Block, B>(client: &T, hash: Block::Hash) -> ClientResult<bool>
where
Block: BlockT,
T: Finalizer<Block, B> + UsageProvider<Block>,
B: Backend<Block>,
{
// don't finalize the same block multiple times.
if client.usage_info().chain.finalized_hash != hash {
match client.finalize_block(BlockId::hash(hash), None, true) {
Ok(()) => Ok(true),
Err(e) => match e {
ClientError::UnknownBlock(_) => Ok(false),
_ => Err(e),
},
}
} else {
Ok(true)
}
}
/// Spawns a future that follows the Polkadot relay chain for the given parachain.
pub fn follow_polkadot<L, P>(
pub fn follow_polkadot<L, P, Block, B>(
para_id: ParaId,
local: Arc<L>,
polkadot: P,
) -> ClientResult<impl Future<Output = ()> + Send + Unpin>
where
L: LocalClient + Send + Sync,
Block: BlockT,
L: Finalizer<Block, B> + UsageProvider<Block> + Send + Sync,
P: PolkadotClient,
B: Backend<Block>,
{
let finalized_heads = polkadot.finalized_heads(para_id)?;
@@ -104,13 +113,12 @@ where
finalized_heads
.map(|head_data| {
<<L::Block as BlockT>::Header>::decode(&mut &head_data[..])
<<Block as BlockT>::Header>::decode(&mut &head_data[..])
.map_err(|_| Error::InvalidHeadData)
})
.try_for_each(move |p_head| {
future::ready(
local
.finalize(p_head.hash())
finalize_block(&*local, p_head.hash())
.map_err(Error::Client)
.map(|_| ()),
)
@@ -122,39 +130,10 @@ where
.map(|_| ()))
}
impl<B, E, Block, RA> LocalClient for Client<B, E, Block, RA>
impl<T> PolkadotClient for Arc<T>
where
B: Backend<Block>,
E: CallExecutor<Block>,
Block: BlockT,
{
type Block = Block;
fn finalize(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool> {
// don't finalize the same block multiple times.
if self.chain_info().finalized_hash != hash {
match self.finalize_block(BlockId::hash(hash), None, true) {
Ok(()) => Ok(true),
Err(e) => match e {
ClientError::UnknownBlock(_) => Ok(false),
_ => Err(e),
},
}
} else {
Ok(true)
}
}
}
impl<B, E, RA> PolkadotClient for Arc<Client<B, E, PBlock, RA>>
where
B: Backend<PBlock> + Send + Sync + 'static,
E: CallExecutor<PBlock> + Send + Sync + 'static,
Client<B, E, PBlock, RA>: ProvideRuntimeApi<PBlock> + Send + Sync + 'static,
<Client<B, E, PBlock, RA> as ProvideRuntimeApi<PBlock>>::Api:
ParachainHost<PBlock, Error = ClientError>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
StateBackendFor<B, PBlock>: StateBackend<sp_runtime::traits::BlakeTwo256>,
T: sc_client_api::BlockchainEvents<PBlock> + ProvideRuntimeApi<PBlock> + 'static + Send + Sync,
<T as ProvideRuntimeApi<PBlock>>::Api: ParachainHost<PBlock, Error = ClientError>,
{
type Error = ClientError;
+3 -3
View File
@@ -26,7 +26,7 @@ use cumulus_primitives::{
};
use frame_support::{
decl_module, storage,
weights::{MINIMUM_WEIGHT, SimpleDispatchInfo, WeighData, Weight},
weights::{DispatchClass, Weight},
};
use frame_system::ensure_none;
use sp_inherents::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent};
@@ -42,7 +42,7 @@ decl_module! {
/// Executes the given downward messages by calling the message handlers.
///
/// The origin of this call needs to be `None` as this is an inherent.
#[weight = SimpleDispatchInfo::FixedMandatory(10)]
#[weight = (10, DispatchClass::Mandatory)]
fn execute_downward_messages(origin, messages: Vec<()>) {
ensure_none(origin)?;
messages.iter().for_each(T::DownwardMessageHandlers::handle_downward_message);
@@ -51,7 +51,7 @@ decl_module! {
fn on_initialize() -> Weight {
storage::unhashed::kill(well_known_keys::UPWARD_MESSAGES);
SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT).weigh_data(())
0
}
}
}
-1
View File
@@ -7,7 +7,6 @@ edition = "2018"
[dependencies]
# substrate deps
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
+1 -1
View File
@@ -57,7 +57,6 @@ fn call_validate_block(
WasmExecutionMethod::Interpreted,
Some(1024),
sp_io::SubstrateHostFunctions::host_functions(),
false,
1,
);
@@ -67,6 +66,7 @@ fn call_validate_block(
"validate_block",
&params,
&mut ext_ext,
sp_core::traits::MissingHostFunctions::Disallow,
)
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
.map(|v| Header::decode(&mut &v.head_data.0[..]).expect("Decode `Header`."))
+2
View File
@@ -5,6 +5,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
test-client = { package = "substrate-test-client", git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
runtime = { package = "cumulus-test-runtime", path = "../runtime" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
+8 -7
View File
@@ -21,6 +21,7 @@ use runtime::{
genesismap::{additional_storage_with_genesis, GenesisConfig},
Block,
};
use sc_service::client;
use sp_core::{sr25519, storage::Storage, ChangesTrieConfiguration};
use sp_keyring::{AccountKeyring, Sr25519Keyring};
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
@@ -42,17 +43,17 @@ pub use local_executor::LocalExecutor;
pub type Backend = test_client::Backend<Block>;
/// Test client executor.
pub type Executor =
sc_client::LocalCallExecutor<Backend, sc_executor::NativeExecutor<LocalExecutor>>;
pub type Executor = client::LocalCallExecutor<Backend, sc_executor::NativeExecutor<LocalExecutor>>;
/// Test client builder for Cumulus
pub type TestClientBuilder = test_client::TestClientBuilder<Block, Executor, Backend, GenesisParameters>;
pub type TestClientBuilder =
test_client::TestClientBuilder<Block, Executor, Backend, GenesisParameters>;
/// LongestChain type for the test runtime/client.
pub type LongestChain = test_client::sc_client::LongestChain<Backend, Block>;
pub type LongestChain = sc_consensus::LongestChain<Backend, Block>;
/// Test client type with `LocalExecutor` and generic Backend.
pub type Client = sc_client::Client<Backend, Executor, Block, runtime::RuntimeApi>;
pub type Client = client::Client<Backend, Executor, Block, runtime::RuntimeApi>;
/// Parameters of test-client builder with test-runtime.
#[derive(Default)]
@@ -71,7 +72,7 @@ impl test_client::GenesisInit for GenesisParameters {
};
let mut storage = genesis_config(changes_trie_config).genesis_map();
let child_roots = storage.children.iter().map(|(sk, child_content)| {
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root =
<<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
@@ -82,7 +83,7 @@ impl test_client::GenesisInit for GenesisParameters {
<<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().chain(child_roots).collect(),
);
let block: runtime::Block = sc_client::genesis::construct_genesis_block(state_root);
let block: runtime::Block = client::genesis::construct_genesis_block(state_root);
storage.top.extend(additional_storage_with_genesis(&block));
storage
+1 -1
View File
@@ -28,13 +28,13 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-bra
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "0.8.0-alpha.5" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
+3 -2
View File
@@ -134,6 +134,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;
pub const ExtrinsicBaseWeight: Weight = 10_000_000;
}
impl frame_system::Trait for Runtime {
@@ -173,6 +174,8 @@ impl frame_system::Trait for Runtime {
type OnNewAccount = ();
type OnKilledAccount = Balances;
type DbWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type BlockExecutionWeight = ();
}
parameter_types! {
@@ -201,7 +204,6 @@ parameter_types! {
pub const ExistentialDeposit: u128 = 500;
pub const TransferFee: u128 = 0;
pub const CreationFee: u128 = 0;
pub const TransactionBaseFee: u128 = 0;
pub const TransactionByteFee: u128 = 1;
}
@@ -218,7 +220,6 @@ impl pallet_balances::Trait for Runtime {
impl pallet_transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = ();
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
type FeeMultiplierUpdate = ();
+3 -5
View File
@@ -23,11 +23,9 @@ use sc_cli::{
CliConfiguration, Error, ImportParams, KeystoreParams, NetworkParams, Result, SharedParams,
SubstrateCli,
};
use sc_client::genesis;
use sc_service::client::genesis;
use sc_network::config::TransportConfig;
use sc_service::{
config::{NetworkConfiguration, NodeKeyConfig, PrometheusConfig},
};
use sc_service::config::{NetworkConfiguration, NodeKeyConfig, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::{
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
@@ -129,7 +127,7 @@ pub fn run() -> Result<()> {
let storage = (&chain_spec::get_chain_spec()).build_storage()?;
let child_roots = storage.children.iter().map(|(sk, child_content)| {
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root =
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
+1 -1
View File
@@ -48,7 +48,7 @@ macro_rules! new_full_start {
parachain_runtime::RuntimeApi,
crate::service::Executor,
>($config)?
.with_select_chain(|_config, backend| Ok(sc_client::LongestChain::new(backend.clone())))?
.with_select_chain(|_config, backend| Ok(sc_consensus::LongestChain::new(backend.clone())))?
.with_transaction_pool(|config, client, _fetcher, prometheus_registry| {
let pool_api = Arc::new(sc_transaction_pool::FullChainApi::new(client.clone()));
let pool = sc_transaction_pool::BasicPool::new(config, pool_api, prometheus_registry);