Skip to content

Commit

Permalink
PRTU 1.5 - enabling governance + weights (#755)
Browse files Browse the repository at this point in the history
* prtu1_5 - enabling governace + weights

* updated weights

* use weights in runtime
  • Loading branch information
mikiquantum authored Apr 1, 2022
1 parent 6093cca commit 828d998
Show file tree
Hide file tree
Showing 18 changed files with 1,142 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

15 changes: 12 additions & 3 deletions runtime/centrifuge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "centrifuge-runtime"
version = "0.10.2"
version = "0.10.3"
authors = ["Centrifuge <[email protected]>"]
edition = "2018"
build = "build.rs"
Expand Down Expand Up @@ -191,14 +191,23 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-session-benchmarking",
"pallet-multisig/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"hex-literal",
"pallet-fees/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-system-benchmarking",
"frame-system/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"chainbridge/runtime-benchmarks",
"pallet-migration-manager/runtime-benchmarks",
Expand Down
116 changes: 60 additions & 56 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("centrifuge"),
impl_name: create_runtime_str!("centrifuge"),
authoring_version: 1,
spec_version: 1002,
spec_version: 1003,
impl_version: 1,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
Expand Down Expand Up @@ -137,14 +137,18 @@ impl Contains<Call> for BaseFilter {
c,
// Calls from Sudo
Call::Sudo(..)
// Calls for runtime upgrade
| Call::System(frame_system::Call::set_code{..})
| Call::System(frame_system::Call::set_code_without_checks{..})
| Call::System{..}
// Calls that are present in each block
| Call::ParachainSystem(
cumulus_pallet_parachain_system::Call::set_validation_data{..}
)
| Call::Timestamp(pallet_timestamp::Call::set{..})
// Enable Governance
| Call::Democracy{..} | Call::Council{..} | Call::Elections{..}
| Call::Identity{..}
| Call::Proxy{..}
| Call::Utility{..}
| Call::Multisig{..}
)
}
}
Expand Down Expand Up @@ -221,7 +225,7 @@ impl pallet_timestamp::Config for Runtime {
type Moment = Moment;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = pallet_timestamp::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_timestamp::SubstrateWeight<Runtime>;
}

// money stuff
Expand Down Expand Up @@ -337,7 +341,7 @@ impl pallet_multisig::Config for Runtime {
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_multisig::SubstrateWeight<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -416,7 +420,7 @@ impl pallet_proxy::Config for Runtime {
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = MaxProxies;
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_proxy::SubstrateWeight<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
Expand All @@ -427,7 +431,7 @@ impl pallet_utility::Config for Runtime {
type Event = Event;
type Call = Call;
type PalletsOrigin = OriginCaller;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_utility::SubstrateWeight<Runtime>;
}

parameter_types! {
Expand All @@ -446,7 +450,7 @@ impl pallet_scheduler::Config for Runtime {
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_scheduler::SubstrateWeight<Runtime>;
type PreimageProvider = Preimage;
type NoPreimagePostponement = NoPreimagePostponement;
}
Expand All @@ -458,13 +462,13 @@ parameter_types! {
}

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

parameter_types! {
Expand Down Expand Up @@ -493,7 +497,7 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type MaxProposals = CouncilMaxProposals;
type MaxMembers = CouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_collective::SubstrateWeight<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -614,7 +618,7 @@ impl pallet_democracy::Config for Runtime {
type Scheduler = Scheduler;
type PalletsOrigin = OriginCaller;
type MaxVotes = MaxVotes;
type WeightInfo = pallet_democracy::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_democracy::SubstrateWeight<Runtime>;
type MaxProposals = MaxProposals;
}

Expand All @@ -640,7 +644,7 @@ impl pallet_identity::Config for Runtime {
type ForceOrigin = EnsureRootOr<EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>>;
type RegistrarOrigin =
EnsureRootOr<EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>>;
type WeightInfo = pallet_identity::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_identity::SubstrateWeight<Runtime>;
}

parameter_types! {
Expand All @@ -652,7 +656,7 @@ impl pallet_vesting::Config for Runtime {
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_vesting::SubstrateWeight<Runtime>;
const MAX_VESTING_SCHEDULES: u32 = 3;
}

Expand Down Expand Up @@ -817,9 +821,7 @@ pub type SignedExtra = (
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
// Disable paying the fees for now
// TODO(nuno|miki): We need to enable this before we push the sudo removal one
// pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
Expand All @@ -833,27 +835,8 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
SchedulerMigrationV3,
>;

// Migration for scheduler pallet to move from a plain Call to a CallOrHash.
pub struct SchedulerMigrationV3;
impl frame_support::traits::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()
}
}

#[cfg(not(feature = "disable-runtime-api"))]
impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
Expand Down Expand Up @@ -964,6 +947,37 @@ impl_runtime_apis! {

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {

fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_multisig, Multisig);
list_benchmark!(list, extra, pallet_proxy, Proxy);
list_benchmark!(list, extra, pallet_utility, Utility);
list_benchmark!(list, extra, pallet_scheduler, Scheduler);
list_benchmark!(list, extra, pallet_collective, Council);
list_benchmark!(list, extra, pallet_democracy, Democracy);
list_benchmark!(list, extra, pallet_identity, Identity);
list_benchmark!(list, extra, pallet_vesting, Vesting);
list_benchmark!(list, extra, pallet_preimage, Preimage);
list_benchmark!(list, extra, pallet_fees, Fees);
list_benchmark!(list, extra, pallet_migration_manager, Migration);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
}

fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString>{
Expand All @@ -990,33 +1004,23 @@ impl_runtime_apis! {
let params = (&config, &whitelist);

add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_proxy, Proxy);
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_scheduler, Scheduler);
add_benchmark!(params, batches, pallet_collective, Council);
add_benchmark!(params, batches, pallet_democracy, Democracy);
add_benchmark!(params, batches, pallet_identity, Identity);
add_benchmark!(params, batches, pallet_vesting, Vesting);
add_benchmark!(params, batches, pallet_preimage, Preimage);
add_benchmark!(params, batches, pallet_fees, Fees);
add_benchmark!(params, batches, pallet_migration_manager, Migration);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}

fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_fees, Fees);
list_benchmark!(list, extra, pallet_migration_manager, Migration);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
}
}
}
struct CheckInherents;
Expand Down
16 changes: 8 additions & 8 deletions runtime/centrifuge/src/weights/frame_system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Autogenerated weights for frame_system
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-03-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2022-04-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("centrifuge-dev"), DB CACHE: 1024
// Executed Command:
Expand Down Expand Up @@ -40,23 +40,23 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
}
fn set_heap_pages() -> Weight {
(8_000_000 as Weight)
(6_212_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn set_storage(i: u32) -> Weight {
(0 as Weight) // Standard Error: 3_000
.saturating_add((1_101_000 as Weight).saturating_mul(i as Weight))
(0 as Weight) // Standard Error: 2_000
.saturating_add((1_006_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
}
fn kill_storage(i: u32) -> Weight {
(0 as Weight) // Standard Error: 5_000
.saturating_add((731_000 as Weight).saturating_mul(i as Weight))
(0 as Weight) // Standard Error: 2_000
.saturating_add((686_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
}
fn kill_prefix(p: u32) -> Weight {
(50_440_000 as Weight) // Standard Error: 18_000
.saturating_add((1_911_000 as Weight).saturating_mul(p as Weight))
(0 as Weight) // Standard Error: 2_000
.saturating_add((1_462_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
}
}
10 changes: 10 additions & 0 deletions runtime/centrifuge/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@
// GNU General Public License for more details.
pub mod frame_system;
pub mod pallet_balances;
pub mod pallet_collective;
pub mod pallet_democracy;
pub mod pallet_fees;
pub mod pallet_identity;
pub mod pallet_migration_manager;
pub mod pallet_multisig;
pub mod pallet_preimage;
pub mod pallet_proxy;
pub mod pallet_scheduler;
pub mod pallet_timestamp;
pub mod pallet_utility;
pub mod pallet_vesting;
Loading

0 comments on commit 828d998

Please sign in to comment.