diff --git a/Cargo.lock b/Cargo.lock index d7d6682..d7dc159 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8361,6 +8361,7 @@ dependencies = [ "pallet-emission0", "pallet-governance-api", "pallet-torus0", + "pallet-torus0-api", "parity-scale-codec", "polkadot-sdk", "scale-info", diff --git a/pallets/governance/Cargo.toml b/pallets/governance/Cargo.toml index e52392d..05560c3 100644 --- a/pallets/governance/Cargo.toml +++ b/pallets/governance/Cargo.toml @@ -20,6 +20,8 @@ runtime-benchmarks = [ "polkadot-sdk/runtime-benchmarks", "pallet-torus0/runtime-benchmarks", "pallet-emission0/runtime-benchmarks", + + "pallet-torus0-api/runtime-benchmarks", ] try-runtime = [ "polkadot-sdk/try-runtime", @@ -42,6 +44,7 @@ pallet-torus0.workspace = true pallet-emission0.workspace = true pallet-governance-api.workspace = true +pallet-torus0-api.workspace = true [dev-dependencies] test-utils.workspace = true diff --git a/pallets/governance/src/benchmarks.rs b/pallets/governance/src/benchmarks.rs new file mode 100644 index 0000000..fcb7275 --- /dev/null +++ b/pallets/governance/src/benchmarks.rs @@ -0,0 +1,196 @@ +use pallet_torus0_api::Torus0Api; +use polkadot_sdk::{ + frame_benchmarking::{account, benchmarks}, + frame_system::{self, RawOrigin}, + sp_std::vec, +}; + +use crate::*; + +fn create_application(module_key: &T::AccountId) { + let config = crate::GlobalGovernanceConfig::::get(); + let cost = config.agent_application_cost; + let _ = ::Currency::deposit_creating(&module_key, cost); + + let min_data_len = T::MinApplicationDataLength::get(); + let data = vec![0; min_data_len as usize]; + + application::submit_application::(module_key.clone(), module_key.clone(), data) + .expect("failed to submit application"); +} + +benchmarks! { + add_curator { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + }: _(RawOrigin::Root, module_key) + + remove_curator { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + crate::roles::manage_role::>(module_key.clone(), true, crate::Error::::AlreadyCurator) + .expect("failed to add curator"); + }: _(RawOrigin::Root, module_key) + + add_allocator { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + }: _(RawOrigin::Root, module_key) + + remove_allocator { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + crate::roles::manage_role::>(module_key.clone(), true, crate::Error::::AlreadyCurator) + .expect("failed to add allocator"); + }: _(RawOrigin::Root, module_key) + + add_to_whitelist { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + crate::roles::manage_role::>(module_key.clone(), true, crate::Error::::AlreadyCurator) + .expect("failed to add curator"); + }: _(RawOrigin::Signed(module_key.clone()), module_key.clone()) + + remove_from_whitelist { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + crate::roles::manage_role::>(module_key.clone(), true, crate::Error::::AlreadyCurator) + .expect("failed to add curator"); + whitelist::add_to_whitelist::(module_key.clone()) + .expect("failed to add to whitelist"); + }: _(RawOrigin::Signed(module_key.clone()), module_key.clone()) + + submit_application { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + + let config = crate::GlobalGovernanceConfig::::get(); + let cost = config.agent_application_cost; + let _ = ::Currency::deposit_creating( + &module_key, + cost, + ); + + let min_data_len = T::MinApplicationDataLength::get(); + let data = vec![0; min_data_len as usize]; + }: _(RawOrigin::Signed(module_key.clone()), module_key.clone(), data) + + accept_application { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + + crate::roles::manage_role::>(module_key.clone(), true, crate::Error::::AlreadyCurator) + .expect("failed to add curator"); + + create_application::(&module_key); + }: _(RawOrigin::Signed(module_key.clone()), 0) + + deny_application { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + + crate::roles::manage_role::>(module_key.clone(), true, crate::Error::::AlreadyCurator) + .expect("failed to add curator"); + + create_application::(&module_key); + }: _(RawOrigin::Signed(module_key.clone()), 0) + + penalize_agent { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + + crate::roles::manage_role::>(module_key.clone(), true, crate::Error::::AlreadyCurator) + .expect("failed to add curator"); + + as Torus0Api< + T::AccountId, + <::Currency as Currency>::Balance, + <::Currency as Currency>::NegativeImbalance, + >>::force_register_agent( + &module_key, + vec![], + vec![], + vec![], + ).expect("failed to register agent"); + + }: _(RawOrigin::Signed(module_key.clone()), module_key.clone(), 50) + + add_global_params_proposal { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + + let params = proposal::GlobalParamsData { + min_name_length: 2, + max_name_length: T::MaxAgentNameLengthConstraint::get() as u16 - 1, + max_allowed_agents: 1, + max_allowed_weights: 1, + min_stake_per_weight: 0, + min_weight_control_fee: 1, + min_staking_fee: 1, + dividends_participation_weight: Percent::zero(), + proposal_cost: 0, + }; + let data = vec![0]; + + let config = crate::GlobalGovernanceConfig::::get(); + let cost = config.proposal_cost; + let _ = ::Currency::deposit_creating(&module_key, cost); + + }: _(RawOrigin::Signed(module_key.clone()), params, data) + + add_global_custom_proposal { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + let data = vec![0]; + + let config = crate::GlobalGovernanceConfig::::get(); + let cost = config.proposal_cost; + let _ = ::Currency::deposit_creating(&module_key, cost); + + }: _(RawOrigin::Signed(module_key.clone()), data) + + add_dao_treasury_transfer_proposal { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + let data = vec![0]; + + let config = crate::GlobalGovernanceConfig::::get(); + let cost = config.proposal_cost; + let _ = ::Currency::deposit_creating(&module_key, cost); + + }: _(RawOrigin::Signed(module_key.clone()), 0, module_key.clone(), data) + + vote_proposal { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + let data = vec![0]; + + let config = crate::GlobalGovernanceConfig::::get(); + let cost = config.proposal_cost; + let _ = ::Currency::deposit_creating(&module_key, cost); + + proposal::add_global_custom_proposal::(module_key.clone(), data) + .expect("failed to create proposal"); + + pallet_torus0::StakingTo::::set(&module_key, &module_key, Some(1)); + + voting::disable_delegation::(module_key.clone()) + .expect("failed to disable delegation"); + + }: _(RawOrigin::Signed(module_key.clone()), 0, true) + + remove_vote_proposal { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + let data = vec![0]; + + let config = crate::GlobalGovernanceConfig::::get(); + let cost = config.proposal_cost; + let _ = ::Currency::deposit_creating(&module_key, cost); + + proposal::add_global_custom_proposal::(module_key.clone(), data) + .expect("failed to create proposal"); + + pallet_torus0::StakingTo::::set(&module_key, &module_key, Some(1)); + + voting::disable_delegation::(module_key.clone()) + .expect("failed to disable delegation"); + + voting::add_vote::(module_key.clone(), 0, true) + .expect("failed to add vote"); + + }: _(RawOrigin::Signed(module_key.clone()), 0) + + enable_vote_delegation { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + }: _(RawOrigin::Signed(module_key)) + + disable_vote_delegation { + let module_key: T::AccountId = account("ModuleKey", 0, 2); + }: _(RawOrigin::Signed(module_key)) +} diff --git a/pallets/governance/src/lib.rs b/pallets/governance/src/lib.rs index 84a3c23..1b191de 100644 --- a/pallets/governance/src/lib.rs +++ b/pallets/governance/src/lib.rs @@ -8,6 +8,10 @@ pub mod roles; pub mod voting; pub mod whitelist; +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarks; +pub mod weights; + use crate::application::AgentApplication; use crate::config::GovernanceConfiguration; use crate::proposal::Proposal; @@ -32,6 +36,7 @@ use polkadot_sdk::sp_std::vec::Vec; pub mod pallet { #![allow(clippy::too_many_arguments)] use proposal::GlobalParamsData; + use weights::WeightInfo; use super::*; @@ -130,6 +135,8 @@ pub mod pallet { + IsType<::RuntimeEvent>; type Currency: Currency + Send + Sync; + + type WeightInfo: WeightInfo; } #[pallet::pallet] @@ -154,63 +161,63 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::add_curator(), DispatchClass::Normal, Pays::Yes))] pub fn add_curator(origin: OriginFor, key: AccountIdOf) -> DispatchResult { ensure_root(origin)?; roles::manage_role::>(key, true, Error::::AlreadyCurator) } #[pallet::call_index(1)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::remove_curator(), DispatchClass::Normal, Pays::Yes))] pub fn remove_curator(origin: OriginFor, key: AccountIdOf) -> DispatchResult { ensure_root(origin)?; roles::manage_role::>(key, false, Error::::NotAllocator) } #[pallet::call_index(2)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::add_allocator(), DispatchClass::Normal, Pays::Yes))] pub fn add_allocator(origin: OriginFor, key: AccountIdOf) -> DispatchResult { ensure_root(origin)?; roles::manage_role::>(key, true, Error::::AlreadyAllocator) } #[pallet::call_index(3)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::remove_allocator(), DispatchClass::Normal, Pays::Yes))] pub fn remove_allocator(origin: OriginFor, key: AccountIdOf) -> DispatchResult { ensure_root(origin)?; roles::manage_role::>(key, false, Error::::NotAllocator) } #[pallet::call_index(4)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::add_to_whitelist(), DispatchClass::Normal, Pays::Yes))] pub fn add_to_whitelist(origin: OriginFor, key: AccountIdOf) -> DispatchResult { roles::ensure_curator::(origin)?; whitelist::add_to_whitelist::(key) } #[pallet::call_index(5)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::remove_from_whitelist(), DispatchClass::Normal, Pays::Yes))] pub fn remove_from_whitelist(origin: OriginFor, key: AccountIdOf) -> DispatchResult { roles::ensure_curator::(origin)?; whitelist::remove_from_whitelist::(key) } #[pallet::call_index(6)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::accept_application(), DispatchClass::Normal, Pays::Yes))] pub fn accept_application(origin: OriginFor, application_id: u32) -> DispatchResult { roles::ensure_curator::(origin)?; application::accept_application::(application_id) } #[pallet::call_index(7)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::deny_application(), DispatchClass::Normal, Pays::Yes))] pub fn deny_application(origin: OriginFor, application_id: u32) -> DispatchResult { roles::ensure_curator::(origin)?; application::deny_application::(application_id) } #[pallet::call_index(8)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::penalize_agent(), DispatchClass::Normal, Pays::Yes))] pub fn penalize_agent( origin: OriginFor, agent_key: AccountIdOf, @@ -221,7 +228,7 @@ pub mod pallet { } #[pallet::call_index(9)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::submit_application(), DispatchClass::Normal, Pays::Yes))] pub fn submit_application( origin: OriginFor, agent_key: AccountIdOf, @@ -232,7 +239,7 @@ pub mod pallet { } #[pallet::call_index(10)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::add_global_params_proposal(), DispatchClass::Normal, Pays::Yes))] pub fn add_global_params_proposal( origin: OriginFor, data: GlobalParamsData, @@ -243,7 +250,7 @@ pub mod pallet { } #[pallet::call_index(11)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::add_global_custom_proposal(), DispatchClass::Normal, Pays::Yes))] pub fn add_global_custom_proposal( origin: OriginFor, metadata: Vec, @@ -253,7 +260,7 @@ pub mod pallet { } #[pallet::call_index(12)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::add_dao_treasury_transfer_proposal(), DispatchClass::Normal, Pays::Yes))] pub fn add_dao_treasury_transfer_proposal( origin: OriginFor, value: BalanceOf, @@ -270,7 +277,7 @@ pub mod pallet { } #[pallet::call_index(13)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::vote_proposal(), DispatchClass::Normal, Pays::Yes))] pub fn vote_proposal( origin: OriginFor, proposal_id: u64, @@ -281,21 +288,21 @@ pub mod pallet { } #[pallet::call_index(14)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::remove_vote_proposal(), DispatchClass::Normal, Pays::Yes))] pub fn remove_vote_proposal(origin: OriginFor, proposal_id: u64) -> DispatchResult { let voter = ensure_signed(origin)?; voting::remove_vote::(voter, proposal_id) } #[pallet::call_index(15)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::enable_vote_delegation(), DispatchClass::Normal, Pays::Yes))] pub fn enable_vote_delegation(origin: OriginFor) -> DispatchResult { let delegator = ensure_signed(origin)?; voting::enable_delegation::(delegator) } #[pallet::call_index(16)] - #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight((::WeightInfo::disable_vote_delegation(), DispatchClass::Normal, Pays::Yes))] pub fn disable_vote_delegation(origin: OriginFor) -> DispatchResult { let delegator = ensure_signed(origin)?; voting::disable_delegation::(delegator) diff --git a/pallets/governance/src/weights.rs b/pallets/governance/src/weights.rs new file mode 100644 index 0000000..329c7ea --- /dev/null +++ b/pallets/governance/src/weights.rs @@ -0,0 +1,525 @@ + +//! Autogenerated weights for `pallet_governance` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 +//! DATE: 2025-01-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Luizs-MacBook-Pro.local`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` + +// Executed Command: +// target/release/torus-node +// benchmark +// pallet +// --chain +// dev +// --pallet +// pallet_governance +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// pallets/governance/src/weights.rs +// --template=./.maintain/frame-weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use polkadot_sdk::{ + frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}, + *, +}; +use core::marker::PhantomData; + +/// Weight functions needed for `pallet_governance`. +pub trait WeightInfo { + fn add_curator() -> Weight; + fn remove_curator() -> Weight; + fn add_allocator() -> Weight; + fn remove_allocator() -> Weight; + fn add_to_whitelist() -> Weight; + fn remove_from_whitelist() -> Weight; + fn submit_application() -> Weight; + fn accept_application() -> Weight; + fn deny_application() -> Weight; + fn penalize_agent() -> Weight; + fn add_global_params_proposal() -> Weight; + fn add_global_custom_proposal() -> Weight; + fn add_dao_treasury_transfer_proposal() -> Weight; + fn vote_proposal() -> Weight; + fn remove_vote_proposal() -> Weight; + fn enable_vote_delegation() -> Weight; + fn disable_vote_delegation() -> Weight; +} + +/// Weights for `pallet_governance` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `Governance::Curators` (r:1 w:1) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn add_curator() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `3497` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(5_000_000, 3497) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:1) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn remove_curator() -> Weight { + // Proof Size summary in bytes: + // Measured: `60` + // Estimated: `3497` + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(6_000_000, 3497) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Allocators` (r:1 w:1) + /// Proof: `Governance::Allocators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn add_allocator() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `3497` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(5_000_000, 3497) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Allocators` (r:1 w:1) + /// Proof: `Governance::Allocators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn remove_allocator() -> Weight { + // Proof Size summary in bytes: + // Measured: `62` + // Estimated: `3497` + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(6_000_000, 3497) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::Whitelist` (r:1 w:1) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn add_to_whitelist() -> Weight { + // Proof Size summary in bytes: + // Measured: `60` + // Estimated: `3497` + // Minimum execution time: 9_000_000 picoseconds. + Weight::from_parts(10_000_000, 3497) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::Whitelist` (r:1 w:1) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Torus0::Agents` (r:1 w:0) + /// Proof: `Torus0::Agents` (`max_values`: None, `max_size`: Some(849), added: 3324, mode: `MaxEncodedLen`) + fn remove_from_whitelist() -> Weight { + // Proof Size summary in bytes: + // Measured: `124` + // Estimated: `4314` + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(14_000_000, 4314) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Whitelist` (r:1 w:0) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplicationId` (r:1 w:1) + /// Proof: `Governance::AgentApplicationId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplications` (r:0 w:1) + /// Proof: `Governance::AgentApplications` (`max_values`: None, `max_size`: Some(354), added: 2829, mode: `MaxEncodedLen`) + fn submit_application() -> Weight { + // Proof Size summary in bytes: + // Measured: `146` + // Estimated: `3593` + // Minimum execution time: 29_000_000 picoseconds. + Weight::from_parts(30_000_000, 3593) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplications` (r:1 w:1) + /// Proof: `Governance::AgentApplications` (`max_values`: None, `max_size`: Some(354), added: 2829, mode: `MaxEncodedLen`) + /// Storage: `Governance::Whitelist` (r:1 w:1) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn accept_application() -> Weight { + // Proof Size summary in bytes: + // Measured: `262` + // Estimated: `3819` + // Minimum execution time: 37_000_000 picoseconds. + Weight::from_parts(38_000_000, 3819) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplications` (r:1 w:1) + /// Proof: `Governance::AgentApplications` (`max_values`: None, `max_size`: Some(354), added: 2829, mode: `MaxEncodedLen`) + fn deny_application() -> Weight { + // Proof Size summary in bytes: + // Measured: `210` + // Estimated: `3819` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(14_000_000, 3819) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Torus0::Agents` (r:1 w:1) + /// Proof: `Torus0::Agents` (`max_values`: None, `max_size`: Some(849), added: 3324, mode: `MaxEncodedLen`) + fn penalize_agent() -> Weight { + // Proof Size summary in bytes: + // Measured: `170` + // Estimated: `4314` + // Minimum execution time: 10_000_000 picoseconds. + Weight::from_parts(11_000_000, 4314) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn add_global_params_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `152` + // Estimated: `3593` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(28_000_000, 3593) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn add_global_custom_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `152` + // Estimated: `3593` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(28_000_000, 3593) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn add_dao_treasury_transfer_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `152` + // Estimated: `3593` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(29_000_000, 3593) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + /// Storage: `Torus0::StakedBy` (r:1 w:0) + /// Proof: `Torus0::StakedBy` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Torus0::StakingTo` (r:2 w:0) + /// Proof: `Torus0::StakingTo` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Governance::NotDelegatingVotingPower` (r:1 w:0) + /// Proof: `Governance::NotDelegatingVotingPower` (`max_values`: Some(1), `max_size`: Some(4294967295), added: 494, mode: `MaxEncodedLen`) + fn vote_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `316` + // Estimated: `6100` + // Minimum execution time: 22_000_000 picoseconds. + Weight::from_parts(23_000_000, 6100) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn remove_vote_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `3464` + // Minimum execution time: 10_000_000 picoseconds. + Weight::from_parts(11_000_000, 3464) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::NotDelegatingVotingPower` (r:1 w:1) + /// Proof: `Governance::NotDelegatingVotingPower` (`max_values`: Some(1), `max_size`: Some(4294967295), added: 494, mode: `MaxEncodedLen`) + fn enable_vote_delegation() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `1484` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(4_000_000, 1484) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::NotDelegatingVotingPower` (r:1 w:1) + /// Proof: `Governance::NotDelegatingVotingPower` (`max_values`: Some(1), `max_size`: Some(4294967295), added: 494, mode: `MaxEncodedLen`) + fn disable_vote_delegation() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `1484` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(4_000_000, 1484) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `Governance::Curators` (r:1 w:1) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn add_curator() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `3497` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(5_000_000, 3497) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:1) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn remove_curator() -> Weight { + // Proof Size summary in bytes: + // Measured: `60` + // Estimated: `3497` + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(6_000_000, 3497) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Allocators` (r:1 w:1) + /// Proof: `Governance::Allocators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn add_allocator() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `3497` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(5_000_000, 3497) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Allocators` (r:1 w:1) + /// Proof: `Governance::Allocators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn remove_allocator() -> Weight { + // Proof Size summary in bytes: + // Measured: `62` + // Estimated: `3497` + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(6_000_000, 3497) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::Whitelist` (r:1 w:1) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + fn add_to_whitelist() -> Weight { + // Proof Size summary in bytes: + // Measured: `60` + // Estimated: `3497` + // Minimum execution time: 9_000_000 picoseconds. + Weight::from_parts(10_000_000, 3497) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::Whitelist` (r:1 w:1) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Torus0::Agents` (r:1 w:0) + /// Proof: `Torus0::Agents` (`max_values`: None, `max_size`: Some(849), added: 3324, mode: `MaxEncodedLen`) + fn remove_from_whitelist() -> Weight { + // Proof Size summary in bytes: + // Measured: `124` + // Estimated: `4314` + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(14_000_000, 4314) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Whitelist` (r:1 w:0) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplicationId` (r:1 w:1) + /// Proof: `Governance::AgentApplicationId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplications` (r:0 w:1) + /// Proof: `Governance::AgentApplications` (`max_values`: None, `max_size`: Some(354), added: 2829, mode: `MaxEncodedLen`) + fn submit_application() -> Weight { + // Proof Size summary in bytes: + // Measured: `146` + // Estimated: `3593` + // Minimum execution time: 29_000_000 picoseconds. + Weight::from_parts(30_000_000, 3593) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplications` (r:1 w:1) + /// Proof: `Governance::AgentApplications` (`max_values`: None, `max_size`: Some(354), added: 2829, mode: `MaxEncodedLen`) + /// Storage: `Governance::Whitelist` (r:1 w:1) + /// Proof: `Governance::Whitelist` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn accept_application() -> Weight { + // Proof Size summary in bytes: + // Measured: `262` + // Estimated: `3819` + // Minimum execution time: 37_000_000 picoseconds. + Weight::from_parts(38_000_000, 3819) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Governance::AgentApplications` (r:1 w:1) + /// Proof: `Governance::AgentApplications` (`max_values`: None, `max_size`: Some(354), added: 2829, mode: `MaxEncodedLen`) + fn deny_application() -> Weight { + // Proof Size summary in bytes: + // Measured: `210` + // Estimated: `3819` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(14_000_000, 3819) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Curators` (r:1 w:0) + /// Proof: `Governance::Curators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `Torus0::Agents` (r:1 w:1) + /// Proof: `Torus0::Agents` (`max_values`: None, `max_size`: Some(849), added: 3324, mode: `MaxEncodedLen`) + fn penalize_agent() -> Weight { + // Proof Size summary in bytes: + // Measured: `170` + // Estimated: `4314` + // Minimum execution time: 10_000_000 picoseconds. + Weight::from_parts(11_000_000, 4314) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn add_global_params_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `152` + // Estimated: `3593` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(28_000_000, 3593) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn add_global_custom_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `152` + // Estimated: `3593` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(28_000_000, 3593) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `Governance::GlobalGovernanceConfig` (r:1 w:0) + /// Proof: `Governance::GlobalGovernanceConfig` (`max_values`: Some(1), `max_size`: Some(73), added: 568, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn add_dao_treasury_transfer_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `152` + // Estimated: `3593` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(29_000_000, 3593) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + /// Storage: `Torus0::StakedBy` (r:1 w:0) + /// Proof: `Torus0::StakedBy` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Torus0::StakingTo` (r:2 w:0) + /// Proof: `Torus0::StakingTo` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Governance::NotDelegatingVotingPower` (r:1 w:0) + /// Proof: `Governance::NotDelegatingVotingPower` (`max_values`: Some(1), `max_size`: Some(4294967295), added: 494, mode: `MaxEncodedLen`) + fn vote_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `316` + // Estimated: `6100` + // Minimum execution time: 22_000_000 picoseconds. + Weight::from_parts(23_000_000, 6100) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::Proposals` (r:1 w:1) + /// Proof: `Governance::Proposals` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`) + fn remove_vote_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `3464` + // Minimum execution time: 10_000_000 picoseconds. + Weight::from_parts(11_000_000, 3464) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::NotDelegatingVotingPower` (r:1 w:1) + /// Proof: `Governance::NotDelegatingVotingPower` (`max_values`: Some(1), `max_size`: Some(4294967295), added: 494, mode: `MaxEncodedLen`) + fn enable_vote_delegation() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `1484` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(4_000_000, 1484) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Governance::NotDelegatingVotingPower` (r:1 w:1) + /// Proof: `Governance::NotDelegatingVotingPower` (`max_values`: Some(1), `max_size`: Some(4294967295), added: 494, mode: `MaxEncodedLen`) + fn disable_vote_delegation() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `1484` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(4_000_000, 1484) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} diff --git a/runtime/src/benchmarks.rs b/runtime/src/benchmarks.rs index f9dab46..bc64147 100644 --- a/runtime/src/benchmarks.rs +++ b/runtime/src/benchmarks.rs @@ -5,4 +5,5 @@ polkadot_sdk::frame_benchmarking::define_benchmarks!( [pallet_timestamp, Timestamp] [pallet_sudo, Sudo] [pallet_emission0, Emission0] + [pallet_governance, Governance] ); diff --git a/runtime/src/configs.rs b/runtime/src/configs.rs index a4d3fc6..aaddf97 100644 --- a/runtime/src/configs.rs +++ b/runtime/src/configs.rs @@ -393,6 +393,8 @@ impl pallet_governance::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + + type WeightInfo = pallet_governance::weights::SubstrateWeight; } parameter_types! { diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index d2028cd..ca0d488 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -225,6 +225,8 @@ impl pallet_governance::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + + type WeightInfo = pallet_governance::weights::SubstrateWeight; } impl pallet_balances::Config for Test {