Skip to content

Commit

Permalink
fix: Preimage registrar and Scheduler integration
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli committed Jan 31, 2022
1 parent a9439cb commit 9606ae6
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions runtimes/peregrine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pallet-collective = {git = "https://github.com/paritytech/substrate", default-fe
pallet-democracy = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-indices = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-membership = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-preimage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-randomness-collective-flip = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
Expand Down Expand Up @@ -117,6 +118,7 @@ runtime-benchmarks = [
"pallet-indices/runtime-benchmarks",
"pallet-inflation/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
Expand Down Expand Up @@ -156,6 +158,7 @@ std = [
"pallet-indices/std",
"pallet-inflation/std",
"pallet-membership/std",
"pallet-preimage/try-runtime",
"pallet-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
Expand Down
94 changes: 87 additions & 7 deletions runtimes/peregrine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use frame_support::{
construct_runtime, parameter_types,
traits::EqualPrivilegeOnly,
traits::{EnsureOneOf, EqualPrivilegeOnly, OnRuntimeUpgrade},
weights::{constants::RocksDbWeight, Weight},
};
use frame_system::{EnsureOneOf, EnsureRoot};
use frame_system::EnsureRoot;
use sp_api::impl_runtime_apis;
use sp_core::{
u32_trait::{_1, _2, _3, _5},
Expand All @@ -42,7 +42,7 @@ use sp_runtime::{
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Permill, Perquintill,
};
use sp_std::prelude::*;
use sp_std::{cmp::Ordering, prelude::*};
use sp_version::RuntimeVersion;

use runtime_common::{
Expand Down Expand Up @@ -288,9 +288,55 @@ impl kilt_launch::Config for Runtime {
type PalletId = pallet_id::Launch;
}

parameter_types! {
pub const PreimageMaxSize: u32 = 4096 * 1024;
// FIXME: Handle together with other deposits
pub const PreimageBaseDeposit: Balance = KILT;
pub const PreimageByteDeposit: Balance = KILT;
}

impl pallet_preimage::Config for Runtime {
type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
type Event = Event;
type Currency = Balances;
type ManagerOrigin = EnsureRoot<AccountId>;
type MaxSize = PreimageMaxSize;
type BaseDeposit = PreimageBaseDeposit;
type ByteDeposit = PreimageByteDeposit;
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
pub const NoPreimagePostponement: Option<u32> = Some(10);
}

type ScheduleOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>,
>;

/// Used the compare the privilege of an origin inside the scheduler.
pub struct OriginPrivilegeCmp;

impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {
if left == right {
return Some(Ordering::Equal);
}

match (left, right) {
// Root is greater than anything.
(OriginCaller::system(frame_system::RawOrigin::Root), _) => Some(Ordering::Greater),
// Check which one has more yes votes.
(
OriginCaller::Council(pallet_collective::RawOrigin::Members(l_yes_votes, l_count)),
OriginCaller::Council(pallet_collective::RawOrigin::Members(r_yes_votes, r_count)),
) => Some((l_yes_votes * r_count).cmp(&(r_yes_votes * l_count))),
// For every other origin we don't care, as they are not used for `ScheduleOrigin`.
_ => None,
}
}
}

impl pallet_scheduler::Config for Runtime {
Expand All @@ -299,10 +345,12 @@ impl pallet_scheduler::Config for Runtime {
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type ScheduleOrigin = ScheduleOrigin;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = weights::pallet_scheduler::WeightInfo<Runtime>;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type OriginPrivilegeCmp = OriginPrivilegeCmp;
type PreimageProvider = Preimage;
type NoPreimagePostponement = NoPreimagePostponement;
}

parameter_types! {
Expand Down Expand Up @@ -727,6 +775,11 @@ construct_runtime! {
// System scheduler.
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 42,

// Proxy pallet = 43

// Preimage registrar
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 44,

// KILT Pallets. Start indices 60 to leave room
KiltLaunch: kilt_launch = 60,
Ctype: ctype = 61,
Expand Down Expand Up @@ -813,8 +866,33 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signatu
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;
/// Executive: handles dispatch to the various modules.
pub type Executive =
frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllPalletsWithSystem>;
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
SchedulerMigrationV3,
>;

// Migration for scheduler pallet to move from a plain Call to a CallOrHash.
pub struct SchedulerMigrationV3;

impl OnRuntimeUpgrade for SchedulerMigrationV3 {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
Scheduler::migrate_v2_to_v3()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
Scheduler::pre_migrate_to_v3()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
Scheduler::post_migrate_to_v3()
}
}

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
Expand Down Expand Up @@ -943,6 +1021,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, pallet_democracy, Democracy);
list_benchmark!(list, extra, pallet_indices, Indices);
list_benchmark!(list, extra, pallet_membership, TechnicalMembership);
list_benchmark!(list, extra, pallet_preimage, Preimage);
list_benchmark!(list, extra, pallet_scheduler, Scheduler);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_treasury, Treasury);
Expand Down Expand Up @@ -1006,6 +1085,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_democracy, Democracy);
add_benchmark!(params, batches, pallet_indices, Indices);
add_benchmark!(params, batches, pallet_membership, TechnicalMembership);
add_benchmark!(params, batches, pallet_preimage, Preimage);
add_benchmark!(params, batches, pallet_scheduler, Scheduler);
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
Expand Down
134 changes: 134 additions & 0 deletions runtimes/peregrine/src/weights/pallet_preimage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// KILT Blockchain – https://botlabs.org
// Copyright (C) 2019-2022 BOTLabs GmbH

// The KILT Blockchain is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The KILT Blockchain is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// If you feel like getting in touch with us, you can do so at info@botlabs.org

//! Autogenerated weights for `pallet_preimage`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-01-29, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024

// Executed Command:
// target/release/polkadot
// benchmark
// --chain=kusama-dev
// --steps=50
// --repeat=20
// --pallet=pallet_preimage
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/kusama/src/weights/pallet_preimage.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for `pallet_preimage`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_preimage::WeightInfo for WeightInfo<T> {
// Storage: Preimage PreimageFor (r:1 w:1)
// Storage: Preimage StatusFor (r:1 w:1)
fn note_preimage(s: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 0
.saturating_add((3_000 as Weight).saturating_mul(s as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Preimage PreimageFor (r:1 w:1)
// Storage: Preimage StatusFor (r:1 w:0)
fn note_requested_preimage(s: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 0
.saturating_add((3_000 as Weight).saturating_mul(s as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Preimage PreimageFor (r:1 w:1)
// Storage: Preimage StatusFor (r:1 w:0)
fn note_no_deposit_preimage(s: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 0
.saturating_add((3_000 as Weight).saturating_mul(s as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
// Storage: Preimage PreimageFor (r:0 w:1)
fn unnote_preimage() -> Weight {
(53_005_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
// Storage: Preimage PreimageFor (r:0 w:1)
fn unnote_no_deposit_preimage() -> Weight {
(34_770_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
fn request_preimage() -> Weight {
(49_075_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
fn request_no_deposit_preimage() -> Weight {
(32_039_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
fn request_unnoted_preimage() -> Weight {
(19_571_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
fn request_requested_preimage() -> Weight {
(6_704_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
// Storage: Preimage PreimageFor (r:0 w:1)
fn unrequest_preimage() -> Weight {
(34_923_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
// Storage: Preimage PreimageFor (r:0 w:1)
fn unrequest_unnoted_preimage() -> Weight {
(19_088_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Preimage StatusFor (r:1 w:1)
fn unrequest_multi_referenced_preimage() -> Weight {
(6_633_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
4 changes: 4 additions & 0 deletions runtimes/spiritnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pallet-collective = {git = "https://github.com/paritytech/substrate", default-fe
pallet-democracy = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-indices = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-membership = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-preimage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-randomness-collective-flip = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.16"}
Expand Down Expand Up @@ -116,6 +117,7 @@ runtime-benchmarks = [
"pallet-indices/runtime-benchmarks",
"pallet-inflation/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
Expand Down Expand Up @@ -155,6 +157,7 @@ std = [
"pallet-indices/std",
"pallet-inflation/std",
"pallet-membership/std",
"pallet-preimage/std",
"pallet-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
Expand Down Expand Up @@ -203,6 +206,7 @@ try-runtime = [
"pallet-democracy/try-runtime",
"pallet-indices/try-runtime",
"pallet-membership/try-runtime",
"pallet-preimage/try-runtime",
"pallet-randomness-collective-flip/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
Expand Down
Loading

0 comments on commit 9606ae6

Please sign in to comment.