Upgdate to latest polkadot & substrate (#263)

* Upgdate to latest polkadot & substrate

* Fix code formatting (cargo fmt)

* Fix unit tests
This commit is contained in:
Alexander Krupenkin
2020-12-10 16:28:02 +03:00
committed by GitHub
parent f327cd96dc
commit ea10fa8230
10 changed files with 630 additions and 527 deletions
Generated
+535 -460
View File
File diff suppressed because it is too large Load Diff
+6 -4
View File
@@ -72,7 +72,9 @@ pub struct Collator<Block: BlockT, PF, BI, BS, Backend, PBackend, PClient> {
polkadot_client: Arc<PClient>, polkadot_client: Arc<PClient>,
} }
impl<Block: BlockT, PF, BI, BS, Backend, PBackend, PClient> Clone for Collator<Block, PF, BI, BS, Backend, PBackend, PClient> { impl<Block: BlockT, PF, BI, BS, Backend, PBackend, PClient> Clone
for Collator<Block, PF, BI, BS, Backend, PBackend, PClient>
{
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
para_id: self.para_id.clone(), para_id: self.para_id.clone(),
@@ -88,7 +90,8 @@ impl<Block: BlockT, PF, BI, BS, Backend, PBackend, PClient> Clone for Collator<B
} }
} }
impl<Block, PF, BI, BS, Backend, PBackend, PApi, PClient> Collator<Block, PF, BI, BS, Backend, PBackend, PClient> impl<Block, PF, BI, BS, Backend, PBackend, PApi, PClient>
Collator<Block, PF, BI, BS, Backend, PBackend, PClient>
where where
Block: BlockT, Block: BlockT,
PF: Environment<Block> + 'static + Send, PF: Environment<Block> + 'static + Send,
@@ -144,8 +147,7 @@ where
/// ///
/// Returns `None` in case of an error. /// Returns `None` in case of an error.
fn retrieve_dmq_contents(&self, relay_parent: PHash) -> Option<DownwardMessagesType> { fn retrieve_dmq_contents(&self, relay_parent: PHash) -> Option<DownwardMessagesType> {
self self.polkadot_client
.polkadot_client
.runtime_api() .runtime_api()
.dmq_contents_with_context( .dmq_contents_with_context(
&BlockId::hash(relay_parent), &BlockId::hash(relay_parent),
+2 -2
View File
@@ -54,7 +54,7 @@ use futures::{
}; };
use log::trace; use log::trace;
use std::{marker::PhantomData, pin::Pin, sync::Arc, fmt}; use std::{fmt, marker::PhantomData, pin::Pin, sync::Arc};
use wait_on_relay_chain_block::WaitOnRelayChainBlock; use wait_on_relay_chain_block::WaitOnRelayChainBlock;
@@ -62,7 +62,7 @@ type BoxedError = Box<dyn std::error::Error + Send>;
#[derive(Debug)] #[derive(Debug)]
struct BlockAnnounceError(String); struct BlockAnnounceError(String);
impl std::error::Error for BlockAnnounceError { } impl std::error::Error for BlockAnnounceError {}
impl fmt::Display for BlockAnnounceError { impl fmt::Display for BlockAnnounceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+5 -5
View File
@@ -19,11 +19,11 @@ use cumulus_test_service::runtime::{Block, Header};
use futures::{executor::block_on, poll, task::Poll}; use futures::{executor::block_on, poll, task::Poll};
use polkadot_node_primitives::{SignedFullStatement, Statement}; use polkadot_node_primitives::{SignedFullStatement, Statement};
use polkadot_primitives::v1::{ use polkadot_primitives::v1::{
Block as PBlock, BlockNumber, CandidateCommitments, CandidateDescriptor, Block as PBlock, BlockNumber, CandidateCommitments, CandidateDescriptor, CandidateEvent,
CandidateEvent, CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash as PHash, CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash as PHash, HeadData, Id as ParaId,
HeadData, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, ParachainHost,
ParachainHost, PersistedValidationData, SessionIndex, SigningContext, ValidationCode, PersistedValidationData, SessionIndex, SessionInfo, SigningContext, ValidationCode,
ValidationData, ValidatorId, ValidatorIndex, SessionInfo, ValidationData, ValidatorId, ValidatorIndex,
}; };
use polkadot_test_client::{ use polkadot_test_client::{
Client as PClient, ClientBlockImportExt, DefaultTestClientBuilderExt, FullBackend as PBackend, Client as PClient, ClientBlockImportExt, DefaultTestClientBuilderExt, FullBackend as PBackend,
+2 -11
View File
@@ -263,14 +263,12 @@ mod tests {
dispatch::UnfilteredDispatchable, dispatch::UnfilteredDispatchable,
impl_outer_event, impl_outer_origin, parameter_types, impl_outer_event, impl_outer_origin, parameter_types,
traits::{OnFinalize, OnInitialize}, traits::{OnFinalize, OnInitialize},
weights::Weight,
}; };
use frame_system::{InitKind, RawOrigin}; use frame_system::{InitKind, RawOrigin};
use sp_core::H256; use sp_core::H256;
use sp_runtime::{ use sp_runtime::{
testing::Header, testing::Header,
traits::{BlakeTwo256, IdentityLookup}, traits::{BlakeTwo256, IdentityLookup},
Perbill,
}; };
use sp_version::RuntimeVersion; use sp_version::RuntimeVersion;
@@ -296,9 +294,6 @@ mod tests {
pub struct Test; pub struct Test;
parameter_types! { parameter_types! {
pub const BlockHashCount: u64 = 250; pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub Version: RuntimeVersion = RuntimeVersion { pub Version: RuntimeVersion = RuntimeVersion {
spec_name: sp_version::create_runtime_str!("test"), spec_name: sp_version::create_runtime_str!("test"),
impl_name: sp_version::create_runtime_str!("system-test"), impl_name: sp_version::create_runtime_str!("system-test"),
@@ -321,18 +316,14 @@ mod tests {
type Header = Header; type Header = Header;
type Event = TestEvent; type Event = TestEvent;
type BlockHashCount = BlockHashCount; type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight; type BlockLength = ();
type MaximumExtrinsicWeight = MaximumBlockWeight; type BlockWeights = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version; type Version = Version;
type PalletInfo = (); type PalletInfo = ();
type AccountData = (); type AccountData = ();
type OnNewAccount = (); type OnNewAccount = ();
type OnKilledAccount = (); type OnKilledAccount = ();
type DbWeight = (); type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type BaseCallFilter = (); type BaseCallFilter = ();
type SystemWeightInfo = (); type SystemWeightInfo = ();
} }
+37 -18
View File
@@ -27,7 +27,7 @@ use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata; use sp_core::OpaqueMetadata;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, IdentityLookup, Saturating}, traits::{BlakeTwo256, Block as BlockT, IdentityLookup},
transaction_validity::{TransactionSource, TransactionValidity}, transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, ApplyExtrinsicResult,
}; };
@@ -40,9 +40,13 @@ use sp_version::RuntimeVersion;
pub use frame_support::{ pub use frame_support::{
construct_runtime, parameter_types, construct_runtime, parameter_types,
traits::Randomness, traits::Randomness,
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight}, weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
DispatchClass, IdentityFee, Weight,
},
StorageValue, StorageValue,
}; };
use frame_system::limits::{BlockLength, BlockWeights};
pub use pallet_balances::Call as BalancesCall; pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall; pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
@@ -95,16 +99,38 @@ pub fn native_version() -> NativeVersion {
} }
} }
/// We assume that ~10% of the block weight is consumed by `on_initalize` handlers.
/// This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
parameter_types! { parameter_types! {
pub const BlockHashCount: BlockNumber = 250; pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
/// Assume 10% of weight for average on_initialize calls.
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION; pub const Version: RuntimeVersion = VERSION;
pub const ExtrinsicBaseWeight: Weight = 10_000_000; pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have some extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
} }
impl frame_system::Config for Runtime { impl frame_system::Config for Runtime {
@@ -130,12 +156,6 @@ impl frame_system::Config for Runtime {
type Origin = Origin; type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first). /// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount; type BlockHashCount = BlockHashCount;
/// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok.
type MaximumBlockWeight = MaximumBlockWeight;
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type MaximumBlockLength = MaximumBlockLength;
/// Portion of the block weight that is available to all normal transactions.
type AvailableBlockRatio = AvailableBlockRatio;
/// Runtime version. /// Runtime version.
type Version = Version; type Version = Version;
/// Converts a module to an index of this module in the runtime. /// Converts a module to an index of this module in the runtime.
@@ -144,11 +164,10 @@ impl frame_system::Config for Runtime {
type OnNewAccount = (); type OnNewAccount = ();
type OnKilledAccount = (); type OnKilledAccount = ();
type DbWeight = (); type DbWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type BlockExecutionWeight = ();
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
type BaseCallFilter = (); type BaseCallFilter = ();
type SystemWeightInfo = (); type SystemWeightInfo = ();
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
} }
parameter_types! { parameter_types! {
+4 -4
View File
@@ -263,8 +263,8 @@ impl<'a, B: BlockT> Externalities for WitnessExt<'a, B> {
self.inner.place_child_storage(child_info, key, value) self.inner.place_child_storage(child_info, key, value)
} }
fn kill_child_storage(&mut self, child_info: &ChildInfo) { fn kill_child_storage(&mut self, child_info: &ChildInfo, limit: Option<u32>) -> bool {
self.inner.kill_child_storage(child_info) self.inner.kill_child_storage(child_info, limit)
} }
fn clear_prefix(&mut self, prefix: &[u8]) { fn clear_prefix(&mut self, prefix: &[u8]) {
@@ -450,9 +450,9 @@ fn host_default_child_storage_clear(storage_key: &[u8], key: &[u8]) {
with_externalities(|ext| ext.place_child_storage(&child_info, key.to_vec(), None)) with_externalities(|ext| ext.place_child_storage(&child_info, key.to_vec(), None))
} }
fn host_default_child_storage_storage_kill(storage_key: &[u8]) { fn host_default_child_storage_storage_kill(storage_key: &[u8], limit: Option<u32>) -> bool {
let child_info = ChildInfo::new_default(storage_key); let child_info = ChildInfo::new_default(storage_key);
with_externalities(|ext| ext.kill_child_storage(&child_info)) with_externalities(|ext| ext.kill_child_storage(&child_info, limit))
} }
fn host_default_child_storage_exists(storage_key: &[u8], key: &[u8]) -> bool { fn host_default_child_storage_exists(storage_key: &[u8], key: &[u8]) -> bool {
+1 -5
View File
@@ -301,10 +301,6 @@ pub fn build_polkadot_full_node(
if is_light { if is_light {
Err("Light client not supported.".into()) Err("Light client not supported.".into())
} else { } else {
polkadot_service::build_full( polkadot_service::build_full(config, polkadot_service::IsCollator::Yes(collator_id), None)
config,
polkadot_service::IsCollator::Yes(collator_id),
None,
)
} }
} }
+37 -18
View File
@@ -26,7 +26,7 @@ use sp_api::{decl_runtime_apis, impl_runtime_apis};
use sp_core::OpaqueMetadata; use sp_core::OpaqueMetadata;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Saturating, Verify}, traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Verify},
transaction_validity::{TransactionSource, TransactionValidity}, transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature, ApplyExtrinsicResult, MultiSignature,
}; };
@@ -39,9 +39,13 @@ use sp_version::RuntimeVersion;
pub use frame_support::{ pub use frame_support::{
construct_runtime, parameter_types, construct_runtime, parameter_types,
traits::Randomness, traits::Randomness,
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight}, weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
DispatchClass, IdentityFee, Weight,
},
StorageValue, StorageValue,
}; };
use frame_system::limits::{BlockLength, BlockWeights};
pub use pallet_balances::Call as BalancesCall; pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall; pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
@@ -88,16 +92,38 @@ pub fn native_version() -> NativeVersion {
} }
} }
/// We assume that ~10% of the block weight is consumed by `on_initalize` handlers.
/// This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
parameter_types! { parameter_types! {
pub const BlockHashCount: BlockNumber = 250; pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
/// Assume 10% of weight for average on_initialize calls.
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION; pub const Version: RuntimeVersion = VERSION;
pub const ExtrinsicBaseWeight: Weight = 10_000_000; pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have some extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
} }
impl frame_system::Config for Runtime { impl frame_system::Config for Runtime {
@@ -123,12 +149,6 @@ impl frame_system::Config for Runtime {
type Origin = Origin; type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first). /// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount; type BlockHashCount = BlockHashCount;
/// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok.
type MaximumBlockWeight = MaximumBlockWeight;
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type MaximumBlockLength = MaximumBlockLength;
/// Portion of the block weight that is available to all normal transactions.
type AvailableBlockRatio = AvailableBlockRatio;
/// Runtime version. /// Runtime version.
type Version = Version; type Version = Version;
type PalletInfo = PalletInfo; type PalletInfo = PalletInfo;
@@ -136,11 +156,10 @@ impl frame_system::Config for Runtime {
type OnNewAccount = (); type OnNewAccount = ();
type OnKilledAccount = (); type OnKilledAccount = ();
type DbWeight = (); type DbWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type BlockExecutionWeight = ();
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
type BaseCallFilter = (); type BaseCallFilter = ();
type SystemWeightInfo = (); type SystemWeightInfo = ();
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
} }
parameter_types! { parameter_types! {
+1
View File
@@ -382,6 +382,7 @@ pub fn node_config(
transaction_pool: Default::default(), transaction_pool: Default::default(),
network: network_config, network: network_config,
keystore: KeystoreConfig::InMemory, keystore: KeystoreConfig::InMemory,
keystore_remote: Default::default(),
database: DatabaseConfig::RocksDb { database: DatabaseConfig::RocksDb {
path: root.join("db"), path: root.join("db"),
cache_size: 128, cache_size: 128,