Upstream Statemine v4 Changes (#649)

* bump runtime spec version

* remove applied runtime migrations

* bump transaction_version

necessary because of extrinsic API changes to pallet-xcm
https://github.com/paritytech/polkadot/pull/3693

* Fix Benchmarks for Statemine-V4 release (#639)

* register validators

* register_as_candidate & leave_intent fixed

* new_session benchmark fixed

* intent_leave_modified

* clean up

* clean up

* benchmark script updated

* update cargo.lock

* done

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Version bump (#648)

* Version bump

fix #646

* Revert "Version bump"

This reverts commit 07517e0e76a37a1dd67176fec0524d0211666635.

* Bump polkadot-collator version

* Update polkadot-parachains/Cargo.toml

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update deps

* Bump version to 4.0.0

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* cargo toml fix

* update deps and remove DisabledValidatorThreshold

* cargo +nightly fmt

* fix compile error

* fix client tests after Polkadot update

Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Alexander Popiak
2021-10-11 10:27:49 +02:00
committed by GitHub
parent f499617c01
commit eff56f60f3
11 changed files with 447 additions and 362 deletions
Generated
+332 -313
View File
File diff suppressed because it is too large Load Diff
+6 -2
View File
@@ -23,8 +23,8 @@ 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, SessionInfo, SigningContext, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex,
PersistedValidationData, ScrapedOnChainVotes, SessionIndex, SessionInfo, SigningContext,
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
};
use polkadot_test_client::{
Client as PClient, ClientBlockImportExt, DefaultTestClientBuilderExt, FullBackend as PBackend,
@@ -487,5 +487,9 @@ sp_api::mock_impl_runtime_apis! {
fn validation_code_by_hash(_: ValidationCodeHash) -> Option<ValidationCode> {
None
}
fn on_chain_votes() -> Option<ScrapedOnChainVotes<Hash>> {
None
}
}
}
+3
View File
@@ -15,8 +15,10 @@ targets = ['x86_64-unknown-linux-gnu']
[dependencies]
log = { version = "0.4.0", default-features = false }
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.3.0' }
rand = { version = "0.7.2", default-features = false }
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.119", default-features = false }
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master" }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master" }
sp-staking = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master" }
@@ -48,6 +50,7 @@ std = [
'codec/std',
'log/std',
'scale-info/std',
'rand/std',
'sp-runtime/std',
'sp-staking/std',
'sp-std/std',
+74 -7
View File
@@ -22,11 +22,12 @@ use crate::Pallet as CollatorSelection;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{
assert_ok,
codec::Decode,
traits::{Currency, EnsureOrigin, Get},
};
use frame_system::{EventRecord, RawOrigin};
use pallet_authorship::EventHandler;
use pallet_session::SessionManager;
use pallet_session::{self as session, SessionManager};
use sp_std::prelude::*;
pub type BalanceOf<T> =
@@ -51,9 +52,50 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
assert_eq!(event, &system_event);
}
fn create_funded_user<T: Config>(
string: &'static str,
n: u32,
balance_factor: u32,
) -> T::AccountId {
let user = account(string, n, SEED);
let balance = T::Currency::minimum_balance() * balance_factor.into();
let _ = T::Currency::make_free_balance_be(&user, balance);
user
}
fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
use rand::{RngCore, SeedableRng};
let keys = {
let mut keys = [0u8; 128];
if c > 0 {
let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);
rng.fill_bytes(&mut keys);
}
keys
};
Decode::decode(&mut &keys[..]).unwrap()
}
fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as session::Config>::Keys) {
(create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))
}
fn register_validators<T: Config + session::Config>(count: u32) {
let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();
for (who, keys) in validators {
<session::Module<T>>::set_keys(RawOrigin::Signed(who).into(), keys, vec![]).unwrap();
}
}
fn register_candidates<T: Config>(count: u32) {
let candidates = (0..count).map(|c| account("candidate", c, SEED)).collect::<Vec<_>>();
assert!(<CandidacyBond<T>>::get() > 0u32.into(), "Bond cannot be zero!");
for who in candidates {
T::Currency::make_free_balance_be(&who, <CandidacyBond<T>>::get() * 2u32.into());
<CollatorSelection<T>>::register_as_candidate(RawOrigin::Signed(who).into()).unwrap();
@@ -61,7 +103,7 @@ fn register_candidates<T: Config>(count: u32) {
}
benchmarks! {
where_clause { where T: pallet_authorship::Config }
where_clause { where T: pallet_authorship::Config + session::Config }
set_invulnerables {
let b in 1 .. T::MaxInvulnerables::get();
@@ -107,12 +149,20 @@ benchmarks! {
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
<DesiredCandidates<T>>::put(c + 1);
register_validators::<T>(c);
register_candidates::<T>(c);
let caller: T::AccountId = whitelisted_caller();
let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();
T::Currency::make_free_balance_be(&caller, bond.clone());
<session::Module<T>>::set_keys(
RawOrigin::Signed(caller.clone()).into(),
keys::<T>(c + 1),
vec![]
).unwrap();
}: _(RawOrigin::Signed(caller.clone()))
verify {
assert_last_event::<T>(Event::CandidateAdded(caller, bond / 2u32.into()).into());
@@ -120,9 +170,11 @@ benchmarks! {
// worse case is the last candidate leaving.
leave_intent {
let c in 1 .. T::MaxCandidates::get();
let c in (T::MinCandidates::get() + 1) .. T::MaxCandidates::get();
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
<DesiredCandidates<T>>::put(c);
register_validators::<T>(c);
register_candidates::<T>(c);
let leaving = <Candidates<T>>::get().last().unwrap().who.clone();
@@ -160,6 +212,8 @@ benchmarks! {
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
<DesiredCandidates<T>>::put(c);
frame_system::Pallet::<T>::set_block_number(0u32.into());
register_validators::<T>(c);
register_candidates::<T>(c);
let new_block: T::BlockNumber = 1800u32.into();
@@ -171,19 +225,32 @@ benchmarks! {
for i in 0..c {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), zero_block);
}
for i in 0..non_removals {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), new_block);
if non_removals > 0 {
for i in 0..non_removals {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), new_block);
}
} else {
for i in 0..c {
<LastAuthoredBlock<T>>::insert(candidates[i as usize].who.clone(), new_block);
}
}
let pre_length = <Candidates<T>>::get().len();
frame_system::Pallet::<T>::set_block_number(new_block);
assert!(<Candidates<T>>::get().len() == c as usize);
}: {
<CollatorSelection<T> as SessionManager<_>>::new_session(0)
} verify {
assert!(<Candidates<T>>::get().len() < pre_length);
if c > r && non_removals >= T::MinCandidates::get() {
assert!(<Candidates<T>>::get().len() < pre_length);
} else if c > r && non_removals < T::MinCandidates::get() {
assert!(<Candidates<T>>::get().len() == T::MinCandidates::get() as usize);
} else {
assert!(<Candidates<T>>::get().len() == pre_length);
}
}
}
+1 -2
View File
@@ -161,7 +161,7 @@ impl pallet_session::SessionHandler<u64> for TestSessionHandler {
SessionHandlerCollators::set(keys.into_iter().map(|(a, _)| *a).collect::<Vec<_>>())
}
fn on_before_session_ending() {}
fn on_disabled(_: usize) {}
fn on_disabled(_: u32) {}
}
parameter_types! {
@@ -179,7 +179,6 @@ impl pallet_session::Config for Test {
type SessionManager = CollatorSelection;
type SessionHandler = TestSessionHandler;
type Keys = MockSessionKeys;
type DisabledValidatorsThreshold = ();
type WeightInfo = ();
}
-2
View File
@@ -545,7 +545,6 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
}
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 100_000;
@@ -562,7 +561,6 @@ impl pallet_session::Config for Runtime {
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
}
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "polkadot-collator"
version = "0.1.0"
version = "4.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
build = "build.rs"
edition = "2018"
+4 -15
View File
@@ -31,7 +31,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill,
ApplyExtrinsicResult,
};
use sp_std::prelude::*;
@@ -90,10 +90,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("statemine"),
impl_name: create_runtime_str!("statemine"),
authoring_version: 1,
spec_version: 3,
spec_version: 4,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
transaction_version: 2,
};
/// The version information used to identify this runtime when compiled natively.
@@ -637,7 +637,6 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
}
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 100_000;
@@ -654,7 +653,6 @@ impl pallet_session::Config for Runtime {
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}
@@ -768,18 +766,9 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
OnRuntimeUpgrade,
(),
>;
pub struct OnRuntimeUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for OnRuntimeUpgrade {
fn on_runtime_upgrade() -> u64 {
frame_support::migrations::migrate_from_pallet_version_to_storage_version::<
AllPalletsWithSystem,
>(&RocksDbWeight::get())
}
}
impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
+1 -3
View File
@@ -31,7 +31,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill,
ApplyExtrinsicResult,
};
use sp_std::prelude::*;
@@ -600,7 +600,6 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
}
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 100_000;
@@ -617,7 +616,6 @@ impl pallet_session::Config for Runtime {
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}
+4 -15
View File
@@ -31,7 +31,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill,
ApplyExtrinsicResult,
};
use sp_std::prelude::*;
@@ -90,10 +90,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("westmint"),
impl_name: create_runtime_str!("westmint"),
authoring_version: 1,
spec_version: 3,
spec_version: 4,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
transaction_version: 2,
};
/// The version information used to identify this runtime when compiled natively.
@@ -599,7 +599,6 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
}
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 100_000;
@@ -616,7 +615,6 @@ impl pallet_session::Config for Runtime {
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}
@@ -752,18 +750,9 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
OnRuntimeUpgrade,
(),
>;
pub struct OnRuntimeUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for OnRuntimeUpgrade {
fn on_runtime_upgrade() -> u64 {
frame_support::migrations::migrate_from_pallet_version_to_storage_version::<
AllPalletsWithSystem,
>(&RocksDbWeight::get())
}
}
impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
+21 -2
View File
@@ -2,10 +2,15 @@
steps=50
repeat=20
statemineOutput=./polkadot-parachains/statemine-runtime/src/weights
statemintOutput=./polkadot-parachains/statemint-runtime/src/weights
statemineOutput=./polkadot-parachains/statemine/src/weights
statemintOutput=./polkadot-parachains/statemint/src/weights
westmintOutput=./polkadot-parachains/westmint/src/weights
statemineChain=statemine-dev
statemintChain=statemint-dev
westmintChain=westmint-dev
pallets=(
pallet_assets
pallet_balances
@@ -15,6 +20,7 @@ pallets=(
pallet_session
pallet_timestamp
pallet_utility
pallet_uniques
)
for p in ${pallets[@]}
@@ -28,6 +34,7 @@ do
--steps=$steps \
--repeat=$repeat \
--raw \
--header=./file_header.txt \
--output=$statemineOutput
./target/release/polkadot-collator benchmark \
@@ -39,6 +46,18 @@ do
--steps=$steps \
--repeat=$repeat \
--raw \
--header=./file_header.txt \
--output=$statemintOutput
./target/release/polkadot-collator benchmark \
--chain=$westmintChain \
--execution=wasm \
--wasm-execution=compiled \
--pallet=$p \
--extrinsic='*' \
--steps=$steps \
--repeat=$repeat \
--raw \
--header=./file_header.txt \
--output=$westmintOutput
done