Skip to content

Commit

Permalink
Upgdate to latest polkadot & substrate (paritytech#263)
Browse files Browse the repository at this point in the history
* Upgdate to latest polkadot & substrate

* Fix code formatting (cargo fmt)

* Fix unit tests
  • Loading branch information
akru authored Dec 10, 2020
1 parent f327cd9 commit ea10fa8
Show file tree
Hide file tree
Showing 10 changed files with 629 additions and 526 deletions.
993 changes: 534 additions & 459 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ pub struct Collator<Block: BlockT, PF, BI, BS, Backend, PBackend, 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 {
Self {
para_id: self.para_id.clone(),
Expand All @@ -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
Block: BlockT,
PF: Environment<Block> + 'static + Send,
Expand Down Expand Up @@ -144,8 +147,7 @@ where
///
/// Returns `None` in case of an error.
fn retrieve_dmq_contents(&self, relay_parent: PHash) -> Option<DownwardMessagesType> {
self
.polkadot_client
self.polkadot_client
.runtime_api()
.dmq_contents_with_context(
&BlockId::hash(relay_parent),
Expand Down
4 changes: 2 additions & 2 deletions network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ use futures::{
};
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;

type BoxedError = Box<dyn std::error::Error + Send>;

#[derive(Debug)]
struct BlockAnnounceError(String);
impl std::error::Error for BlockAnnounceError { }
impl std::error::Error for BlockAnnounceError {}

impl fmt::Display for BlockAnnounceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
10 changes: 5 additions & 5 deletions network/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use cumulus_test_service::runtime::{Block, Header};
use futures::{executor::block_on, poll, task::Poll};
use polkadot_node_primitives::{SignedFullStatement, Statement};
use polkadot_primitives::v1::{
Block as PBlock, BlockNumber, CandidateCommitments, CandidateDescriptor,
CandidateEvent, CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash as PHash,
HeadData, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
ParachainHost, PersistedValidationData, SessionIndex, SigningContext, ValidationCode,
ValidationData, ValidatorId, ValidatorIndex, SessionInfo,
Block as PBlock, BlockNumber, CandidateCommitments, CandidateDescriptor, CandidateEvent,
CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash as PHash, HeadData, Id as ParaId,
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, ParachainHost,
PersistedValidationData, SessionIndex, SessionInfo, SigningContext, ValidationCode,
ValidationData, ValidatorId, ValidatorIndex,
};
use polkadot_test_client::{
Client as PClient, ClientBlockImportExt, DefaultTestClientBuilderExt, FullBackend as PBackend,
Expand Down
13 changes: 2 additions & 11 deletions parachain-upgrade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,12 @@ mod tests {
dispatch::UnfilteredDispatchable,
impl_outer_event, impl_outer_origin, parameter_types,
traits::{OnFinalize, OnInitialize},
weights::Weight,
};
use frame_system::{InitKind, RawOrigin};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Perbill,
};
use sp_version::RuntimeVersion;

Expand All @@ -296,9 +294,6 @@ mod tests {
pub struct Test;
parameter_types! {
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 {
spec_name: sp_version::create_runtime_str!("test"),
impl_name: sp_version::create_runtime_str!("system-test"),
Expand All @@ -321,18 +316,14 @@ mod tests {
type Header = Header;
type Event = TestEvent;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type BlockLength = ();
type BlockWeights = ();
type Version = Version;
type PalletInfo = ();
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type BaseCallFilter = ();
type SystemWeightInfo = ();
}
Expand Down
55 changes: 37 additions & 18 deletions rococo-parachains/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, IdentityLookup, Saturating},
traits::{BlakeTwo256, Block as BlockT, IdentityLookup},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand All @@ -40,9 +40,13 @@ use sp_version::RuntimeVersion;
pub use frame_support::{
construct_runtime, parameter_types,
traits::Randomness,
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
DispatchClass, IdentityFee, Weight,
},
StorageValue,
};
use frame_system::limits::{BlockLength, BlockWeights};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -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! {
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 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 {
Expand All @@ -130,12 +156,6 @@ impl frame_system::Config for Runtime {
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
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.
type Version = Version;
/// Converts a module to an index of this module in the runtime.
Expand All @@ -144,11 +164,10 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type DbWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type BlockExecutionWeight = ();
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
type BaseCallFilter = ();
type SystemWeightInfo = ();
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
}

parameter_types! {
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ impl<'a, B: BlockT> Externalities for WitnessExt<'a, B> {
self.inner.place_child_storage(child_info, key, value)
}

fn kill_child_storage(&mut self, child_info: &ChildInfo) {
self.inner.kill_child_storage(child_info)
fn kill_child_storage(&mut self, child_info: &ChildInfo, limit: Option<u32>) -> bool {
self.inner.kill_child_storage(child_info, limit)
}

fn clear_prefix(&mut self, prefix: &[u8]) {
Expand Down Expand Up @@ -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))
}

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);
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 {
Expand Down
6 changes: 1 addition & 5 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,6 @@ pub fn build_polkadot_full_node(
if is_light {
Err("Light client not supported.".into())
} else {
polkadot_service::build_full(
config,
polkadot_service::IsCollator::Yes(collator_id),
None,
)
polkadot_service::build_full(config, polkadot_service::IsCollator::Yes(collator_id), None)
}
}
55 changes: 37 additions & 18 deletions test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_api::{decl_runtime_apis, impl_runtime_apis};
use sp_core::OpaqueMetadata;
use sp_runtime::{
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},
ApplyExtrinsicResult, MultiSignature,
};
Expand All @@ -39,9 +39,13 @@ use sp_version::RuntimeVersion;
pub use frame_support::{
construct_runtime, parameter_types,
traits::Randomness,
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
DispatchClass, IdentityFee, Weight,
},
StorageValue,
};
use frame_system::limits::{BlockLength, BlockWeights};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -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! {
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 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 {
Expand All @@ -123,24 +149,17 @@ impl frame_system::Config for Runtime {
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
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.
type Version = Version;
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type DbWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type BlockExecutionWeight = ();
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
type BaseCallFilter = ();
type SystemWeightInfo = ();
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ pub fn node_config(
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::InMemory,
keystore_remote: Default::default(),
database: DatabaseConfig::RocksDb {
path: root.join("db"),
cache_size: 128,
Expand Down

0 comments on commit ea10fa8

Please sign in to comment.