diff --git a/ci/jobs/build-and-test.sh b/ci/jobs/build-and-test.sh deleted file mode 100644 index 89f85fe2..00000000 --- a/ci/jobs/build-and-test.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -euo pipefail -cd -- "$(dirname -- "${BASH_SOURCE[0]}")" -cd ../.. - -echo "Starting build and test with benchmarks!" diff --git a/ci/jobs/clippy.sh b/ci/jobs/clippy.sh deleted file mode 100755 index d71748c0..00000000 --- a/ci/jobs/clippy.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -euo pipefail -cd -- "$(dirname -- "${BASH_SOURCE[0]}")" -cd ../.. - -echo "Starting clippy!" -RUSTFLAGS="-D warnings" cargo clippy --all --features runtime-benchmarks \ No newline at end of file diff --git a/libs/common-types/src/tokens.rs b/libs/common-types/src/tokens.rs index d045a037..1dd71c2c 100644 --- a/libs/common-types/src/tokens.rs +++ b/libs/common-types/src/tokens.rs @@ -1,8 +1,10 @@ use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; +use sp_std::vec::Vec; +use frame_support::traits::ConstU32; use serde::{Deserialize, Serialize}; - +use sp_runtime::BoundedVec; #[derive( Clone, Copy, @@ -49,11 +51,12 @@ pub enum CurrencyId { pub enum ForeignAssetId { ETH, USDT, + ADA, } #[derive( Clone, - Copy, + // Copy, PartialOrd, Ord, PartialEq, @@ -70,6 +73,7 @@ pub enum ForeignAssetId { pub enum ForeignOwnedAccount { TRON([u8; 22]), ETH([u8; 20]), + ADA(BoundedVec>), } impl ForeignOwnedAccount { @@ -85,12 +89,17 @@ impl ForeignOwnedAccount { CurrencyId::MGX => false, CurrencyId::ForeignAsset(asset) => match &self { ForeignOwnedAccount::TRON(_) => match asset { - ForeignAssetId::ETH => false, ForeignAssetId::USDT => true, + default => false, }, ForeignOwnedAccount::ETH(_) => match asset { ForeignAssetId::ETH => true, ForeignAssetId::USDT => true, + default => false, + }, + ForeignOwnedAccount::ADA(_) => match asset { + ForeignAssetId::ADA => true, + default => false, }, }, } diff --git a/pallets/briefs/src/benchmarking.rs b/pallets/briefs/src/benchmarking.rs index 88e83fa5..c5322649 100644 --- a/pallets/briefs/src/benchmarking.rs +++ b/pallets/briefs/src/benchmarking.rs @@ -24,7 +24,12 @@ mod benchmarks { fn create_brief() { let (eoa, currency_id) = ForeignOwnedAccount::get_supported_currency_eoa_combo(); let brief_owners = get_max_brief_owners::(currency_id); - let caller: T::AccountId = brief_owners[0].clone(); + let caller = create_account_id::("caller", 1, currency_id); + assert_ok!(T::RMultiCurrency::deposit( + CurrencyId::Native, + &caller, + 1_000_000_000_000_000u128.saturated_into() + )); let applicant = create_account_id::("applicant", 1, currency_id); let budget = 10_000u32.into(); let initial_contribution = 5_000u32.into(); @@ -182,7 +187,7 @@ fn get_brief_owners(mut n: u32, currency: CurrencyId) -> BoundedBrief } fn get_max_brief_owners(currency_id: CurrencyId) -> BoundedBriefOwners { - let max_brief_owners: u32 = ::MaxBriefOwners::get(); + let max_brief_owners: u32 = ::MaxBriefOwners::get() - 1; get_brief_owners::(max_brief_owners, currency_id) } diff --git a/pallets/briefs/src/lib.rs b/pallets/briefs/src/lib.rs index fe6892a8..9d2d30db 100644 --- a/pallets/briefs/src/lib.rs +++ b/pallets/briefs/src/lib.rs @@ -162,6 +162,8 @@ pub mod pallet { EoaRequiredForForeignCurrencies, /// Currency is not supported for this external address. CurrencyAccountComboNotSupported, + /// You must be a fellow to start this work. + FellowshipRequired, } #[pallet::call] @@ -186,7 +188,8 @@ pub mod pallet { let who = ensure_signed(origin)?; if require_fellowship { - T::EnsureRole::ensure_role(&applicant, pallet_fellowship::Role::Freelancer, None)?; + T::EnsureRole::ensure_role(&applicant, pallet_fellowship::Role::Freelancer, None) + .map_err(|_| Error::::FellowshipRequired)?; } ensure!( @@ -200,7 +203,7 @@ pub mod pallet { Error::::EoaRequiredForForeignCurrencies ); } - if let Some(eoa) = external_owned_address { + if let Some(eoa) = external_owned_address.clone() { ensure!( eoa.ensure_supported_currency(currency_id), Error::::CurrencyAccountComboNotSupported diff --git a/pallets/briefs/src/tests.rs b/pallets/briefs/src/tests.rs index 56320f59..dad8db2a 100644 --- a/pallets/briefs/src/tests.rs +++ b/pallets/briefs/src/tests.rs @@ -29,7 +29,7 @@ fn create_brief_not_approved_applicant() { None, true, ), - BadOrigin + Error::::FellowshipRequired ); }); } diff --git a/pallets/briefs/src/weights.rs b/pallets/briefs/src/weights.rs index ddb169ec..03ebf07a 100644 --- a/pallets/briefs/src/weights.rs +++ b/pallets/briefs/src/weights.rs @@ -2,87 +2,79 @@ //! Autogenerated weights for `pallet_briefs` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `user`, CPU: `12th Gen Intel(R) Core(TM) i9-12900H` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("local")`, DB CACHE: 1024 +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("imbue-dev")`, DB CACHE: `1024` // Executed Command: -// ./target/debug/imbue +// ./target/release/imbue // benchmark // pallet -// --chain -// local -// --execution -// wasm -// --wasm-execution -// compiled -// --pallet -// pallet-briefs -// --extrinsic -// * -// --output -// weights.rs -// --steps -// 50 -// --repeat -// 20 +// --chain=imbue-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_briefs +// --extrinsic=* +// --output=./pallets/briefs/src/weights.rs +// --template=./scripts/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; +use crate::WeightInfoT; -/// Weight functions for `pallet_briefs`. +/// Weights for `pallet_briefs` using the Substrate node and recommended hardware. pub struct WeightInfo(PhantomData); -impl crate::WeightInfoT for WeightInfo { +impl WeightInfoT for WeightInfo { /// Storage: `ImbueBriefs::Briefs` (r:1 w:1) - /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1725), added: 4200, mode: `MaxEncodedLen`) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) /// Storage: `Deposits::TicketId` (r:1 w:1) /// Proof: `Deposits::TicketId` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `OrmlTokens::Accounts` (r:1 w:1) + /// Proof: `OrmlTokens::Accounts` (`max_values`: None, `max_size`: Some(106), added: 2581, mode: `MaxEncodedLen`) /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) /// Proof: `ImbueBriefs::BriefContributions` (`max_values`: None, `max_size`: Some(2649), added: 5124, mode: `MaxEncodedLen`) /// Storage: `ImbueBriefs::CounterForBriefs` (r:1 w:1) /// Proof: `ImbueBriefs::CounterForBriefs` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `Deposits::CurrentDeposits` (r:0 w:1) - /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) fn create_brief() -> Weight { // Proof Size summary in bytes: - // Measured: `334` + // Measured: `1042` // Estimated: `6114` - // Minimum execution time: 674_565_000 picoseconds. - Weight::from_parts(699_090_000, 0) - .saturating_add(Weight::from_parts(0, 6114)) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(6)) + // Minimum execution time: 122_948_000 picoseconds. + Weight::from_parts(140_489_000, 6114) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) } /// Storage: `ImbueBriefs::Briefs` (r:1 w:0) - /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1725), added: 4200, mode: `MaxEncodedLen`) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) /// Proof: `ImbueBriefs::BriefContributions` (`max_values`: None, `max_size`: Some(2649), added: 5124, mode: `MaxEncodedLen`) fn contribute_to_brief() -> Weight { // Proof Size summary in bytes: - // Measured: `2119` + // Measured: `2122` // Estimated: `6114` - // Minimum execution time: 388_641_000 picoseconds. - Weight::from_parts(404_811_000, 0) - .saturating_add(Weight::from_parts(0, 6114)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) + // Minimum execution time: 66_724_000 picoseconds. + Weight::from_parts(75_703_000, 6114) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: `ImbueBriefs::Briefs` (r:1 w:1) - /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1725), added: 4200, mode: `MaxEncodedLen`) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) /// Proof: `ImbueBriefs::BriefContributions` (`max_values`: None, `max_size`: Some(2649), added: 5124, mode: `MaxEncodedLen`) /// Storage: `Deposits::CurrentDeposits` (r:1 w:2) - /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `ImbueFellowship::Roles` (r:1 w:0) @@ -96,23 +88,22 @@ impl crate::WeightInfoT for WeightInfo { /// Storage: `ImbueBriefs::CounterForBriefs` (r:1 w:1) /// Proof: `ImbueBriefs::CounterForBriefs` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Projects` (r:0 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::IndividualVoteStore` (r:0 w:1) /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) fn commence_work() -> Weight { // Proof Size summary in bytes: - // Measured: `2607` + // Measured: `2610` // Estimated: `8799` - // Minimum execution time: 1_739_406_000 picoseconds. - Weight::from_parts(1_778_978_000, 0) - .saturating_add(Weight::from_parts(0, 8799)) - .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().writes(13)) + // Minimum execution time: 276_193_000 picoseconds. + Weight::from_parts(282_041_000, 8799) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) } /// Storage: `ImbueBriefs::Briefs` (r:1 w:1) - /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1725), added: 4200, mode: `MaxEncodedLen`) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) /// Storage: `Deposits::CurrentDeposits` (r:1 w:1) - /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) @@ -121,12 +112,103 @@ impl crate::WeightInfoT for WeightInfo { /// Proof: `ImbueBriefs::CounterForBriefs` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn cancel_brief() -> Weight { // Proof Size summary in bytes: - // Measured: `2353` + // Measured: `2356` // Estimated: `6114` - // Minimum execution time: 721_794_000 picoseconds. - Weight::from_parts(753_268_000, 0) - .saturating_add(Weight::from_parts(0, 6114)) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(5)) + // Minimum execution time: 117_915_000 picoseconds. + Weight::from_parts(126_700_000, 6114) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } } + +// For backwards compatibility and tests. +impl WeightInfoT for () { + /// Storage: `ImbueBriefs::Briefs` (r:1 w:1) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) + /// Storage: `Deposits::TicketId` (r:1 w:1) + /// Proof: `Deposits::TicketId` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `OrmlTokens::Accounts` (r:1 w:1) + /// Proof: `OrmlTokens::Accounts` (`max_values`: None, `max_size`: Some(106), added: 2581, mode: `MaxEncodedLen`) + /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) + /// Proof: `ImbueBriefs::BriefContributions` (`max_values`: None, `max_size`: Some(2649), added: 5124, mode: `MaxEncodedLen`) + /// Storage: `ImbueBriefs::CounterForBriefs` (r:1 w:1) + /// Proof: `ImbueBriefs::CounterForBriefs` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Deposits::CurrentDeposits` (r:0 w:1) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) + fn create_brief() -> Weight { + // Proof Size summary in bytes: + // Measured: `1042` + // Estimated: `6114` + // Minimum execution time: 122_948_000 picoseconds. + Weight::from_parts(140_489_000, 6114) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) + } + /// Storage: `ImbueBriefs::Briefs` (r:1 w:0) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) + /// Proof: `ImbueBriefs::BriefContributions` (`max_values`: None, `max_size`: Some(2649), added: 5124, mode: `MaxEncodedLen`) + fn contribute_to_brief() -> Weight { + // Proof Size summary in bytes: + // Measured: `2122` + // Estimated: `6114` + // Minimum execution time: 66_724_000 picoseconds. + Weight::from_parts(75_703_000, 6114) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `ImbueBriefs::Briefs` (r:1 w:1) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) + /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) + /// Proof: `ImbueBriefs::BriefContributions` (`max_values`: None, `max_size`: Some(2649), added: 5124, mode: `MaxEncodedLen`) + /// Storage: `Deposits::CurrentDeposits` (r:1 w:2) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::Roles` (r:1 w:0) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::JuryPointer` (r:1 w:1) + /// Proof: `ImbueFellowship::JuryPointer` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectCount` (r:1 w:1) + /// Proof: `ImbueProposals::ProjectCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Deposits::TicketId` (r:1 w:1) + /// Proof: `Deposits::TicketId` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `ImbueBriefs::CounterForBriefs` (r:1 w:1) + /// Proof: `ImbueBriefs::CounterForBriefs` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Projects` (r:0 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::IndividualVoteStore` (r:0 w:1) + /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) + fn commence_work() -> Weight { + // Proof Size summary in bytes: + // Measured: `2610` + // Estimated: `8799` + // Minimum execution time: 276_193_000 picoseconds. + Weight::from_parts(282_041_000, 8799) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + /// Storage: `ImbueBriefs::Briefs` (r:1 w:1) + /// Proof: `ImbueBriefs::Briefs` (`max_values`: None, `max_size`: Some(1830), added: 4305, mode: `MaxEncodedLen`) + /// Storage: `Deposits::CurrentDeposits` (r:1 w:1) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueBriefs::BriefContributions` (r:1 w:1) + /// Proof: `ImbueBriefs::BriefContributions` (`max_values`: None, `max_size`: Some(2649), added: 5124, mode: `MaxEncodedLen`) + /// Storage: `ImbueBriefs::CounterForBriefs` (r:1 w:1) + /// Proof: `ImbueBriefs::CounterForBriefs` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn cancel_brief() -> Weight { + // Proof Size summary in bytes: + // Measured: `2356` + // Estimated: `6114` + // Minimum execution time: 117_915_000 picoseconds. + Weight::from_parts(126_700_000, 6114) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } +} \ No newline at end of file diff --git a/pallets/disputes/src/lib.rs b/pallets/disputes/src/lib.rs index 31e250ea..98e266d0 100644 --- a/pallets/disputes/src/lib.rs +++ b/pallets/disputes/src/lib.rs @@ -62,7 +62,7 @@ pub mod pallet { /// The origin used to force cancel and pass disputes. type ForceOrigin: EnsureOrigin; /// External hooks to handle the completion of a dispute. - type DisputeHooks: DisputeHooks; + type DisputeHooks: DisputeHooks>; } /// Used to store the disputes that is being raised, given the dispute key it returns the Dispute @@ -145,8 +145,12 @@ pub mod pallet { let hook_weight = >::on_dispute_complete( - *dispute_id, dispute.specifiers.into_inner(), result + dispute.raised_by, + *dispute_id, + dispute.specifiers.into_inner(), + result, ); weight = weight.saturating_add(hook_weight); @@ -216,6 +220,7 @@ pub mod pallet { // Dont mind if this fails as the autofinalise will skip. }); T::DisputeHooks::on_dispute_complete( + dispute.raised_by, dispute_key, dispute.specifiers.into_inner(), DisputeResult::Failure, @@ -248,6 +253,7 @@ pub mod pallet { // Dont mind if this fails as the autofinalise will skip. }); T::DisputeHooks::on_dispute_complete( + dispute.raised_by, dispute_key, dispute.specifiers.into_inner(), DisputeResult::Success, @@ -413,6 +419,7 @@ pub mod pallet { // Dont need to return the weight here. let _ = T::DisputeHooks::on_dispute_complete( + dispute.raised_by, dispute_key, dispute.specifiers.into_inner(), result, diff --git a/pallets/disputes/src/mock.rs b/pallets/disputes/src/mock.rs index 049e2b98..af4ad327 100644 --- a/pallets/disputes/src/mock.rs +++ b/pallets/disputes/src/mock.rs @@ -118,8 +118,9 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities { ext } -impl crate::traits::DisputeHooks for Test { +impl crate::traits::DisputeHooks for Test { fn on_dispute_complete( + _account_id: AccountId, _dispute_key: u32, _specifics: Vec, _dispute_result: crate::pallet::DisputeResult, @@ -127,24 +128,3 @@ impl crate::traits::DisputeHooks for Test { ::default() } } - -impl crate::WeightInfoT for () { - fn vote_on_dispute() -> Weight { - ::default() - } - fn extend_dispute() -> Weight { - ::default() - } - fn raise_dispute() -> Weight { - ::default() - } - fn force_succeed_dispute() -> Weight { - ::default() - } - fn force_fail_dispute() -> Weight { - ::default() - } - fn calculate_winner() -> Weight { - ::default() - } -} diff --git a/pallets/disputes/src/traits.rs b/pallets/disputes/src/traits.rs index 1f033cf5..387e697b 100644 --- a/pallets/disputes/src/traits.rs +++ b/pallets/disputes/src/traits.rs @@ -18,10 +18,11 @@ pub trait DisputeRaiser { ) -> Result<(), DispatchError>; } -pub trait DisputeHooks { +pub trait DisputeHooks { /// On the completion of a dispute, this hooks is called. /// Returning only the key that has been handled and the result of the dispute. fn on_dispute_complete( + raised_by: AccountId, dispute_key: DisputeKey, specifics: Vec, dispute_result: crate::pallet::DisputeResult, diff --git a/pallets/disputes/src/weights.rs b/pallets/disputes/src/weights.rs index dd672737..4c5d311d 100644 --- a/pallets/disputes/src/weights.rs +++ b/pallets/disputes/src/weights.rs @@ -2,43 +2,35 @@ //! Autogenerated weights for `pallet_disputes` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `user`, CPU: `12th Gen Intel(R) Core(TM) i9-12900H` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("local")`, DB CACHE: 1024 +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("imbue-dev")`, DB CACHE: `1024` // Executed Command: -// ./target/debug/imbue +// ./target/release/imbue // benchmark // pallet -// --chain -// local -// --execution -// wasm -// --wasm-execution -// compiled -// --pallet -// pallet-disputes -// --extrinsic -// * -// --output -// weights.rs -// --steps -// 50 -// --repeat -// 20 +// --chain=imbue-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_disputes +// --extrinsic=* +// --output=./pallets/disputes/src/weights.rs +// --template=./scripts/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; +use crate::WeightInfoT; -/// Weight functions for `pallet_disputes`. +/// Weights for `pallet_disputes` using the Substrate node and recommended hardware. pub struct WeightInfo(PhantomData); -impl crate::WeightInfoT for WeightInfo { +impl WeightInfoT for WeightInfo { /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) @@ -47,11 +39,10 @@ impl crate::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `76` // Estimated: `10067` - // Minimum execution time: 152_261_000 picoseconds. - Weight::from_parts(153_191_000, 0) - .saturating_add(Weight::from_parts(0, 10067)) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(2)) + // Minimum execution time: 18_345_000 picoseconds. + Weight::from_parts(18_884_000, 10067) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) @@ -61,72 +52,155 @@ impl crate::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `250` // Estimated: `10067` - // Minimum execution time: 244_000_000 picoseconds. - Weight::from_parts(245_568_000, 0) - .saturating_add(Weight::from_parts(0, 10067)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) + // Minimum execution time: 34_536_000 picoseconds. + Weight::from_parts(37_078_000, 10067) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Projects` (r:1 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::ProjectsInDispute` (r:0 w:1) /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) fn vote_on_dispute() -> Weight { // Proof Size summary in bytes: // Measured: `292` - // Estimated: `39815` - // Minimum execution time: 337_396_000 picoseconds. - Weight::from_parts(344_127_000, 0) - .saturating_add(Weight::from_parts(0, 39815)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(4)) + // Estimated: `39920` + // Minimum execution time: 60_453_000 picoseconds. + Weight::from_parts(66_243_000, 39920) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Projects` (r:1 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::ProjectsInDispute` (r:0 w:1) /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) fn force_fail_dispute() -> Weight { // Proof Size summary in bytes: // Measured: `292` - // Estimated: `39815` - // Minimum execution time: 244_177_000 picoseconds. - Weight::from_parts(250_254_000, 0) - .saturating_add(Weight::from_parts(0, 39815)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(4)) + // Estimated: `39920` + // Minimum execution time: 42_624_000 picoseconds. + Weight::from_parts(48_443_000, 39920) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Projects` (r:1 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::ProjectsInDispute` (r:0 w:1) /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) fn force_succeed_dispute() -> Weight { // Proof Size summary in bytes: // Measured: `292` - // Estimated: `39815` - // Minimum execution time: 243_762_000 picoseconds. - Weight::from_parts(250_041_000, 0) - .saturating_add(Weight::from_parts(0, 39815)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(4)) + // Estimated: `39920` + // Minimum execution time: 45_635_000 picoseconds. + Weight::from_parts(56_736_000, 39920) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } fn calculate_winner() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_448_000 picoseconds. - Weight::from_parts(13_334_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 4_166_000 picoseconds. + Weight::from_parts(4_806_000, 0) } } + +// For backwards compatibility and tests. +impl WeightInfoT for () { + /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) + /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) + /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) + /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) + fn raise_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `76` + // Estimated: `10067` + // Minimum execution time: 18_345_000 picoseconds. + Weight::from_parts(18_884_000, 10067) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) + /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) + /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:2 w:2) + /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) + fn extend_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `250` + // Estimated: `10067` + // Minimum execution time: 34_536_000 picoseconds. + Weight::from_parts(37_078_000, 10067) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) + /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) + /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) + /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Projects` (r:1 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectsInDispute` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + fn vote_on_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `292` + // Estimated: `39920` + // Minimum execution time: 60_453_000 picoseconds. + Weight::from_parts(66_243_000, 39920) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) + /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) + /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) + /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Projects` (r:1 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectsInDispute` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + fn force_fail_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `292` + // Estimated: `39920` + // Minimum execution time: 42_624_000 picoseconds. + Weight::from_parts(48_443_000, 39920) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) + /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) + /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) + /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Projects` (r:1 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectsInDispute` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + fn force_succeed_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `292` + // Estimated: `39920` + // Minimum execution time: 45_635_000 picoseconds. + Weight::from_parts(56_736_000, 39920) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + fn calculate_winner() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_166_000 picoseconds. + Weight::from_parts(4_806_000, 0) + } +} \ No newline at end of file diff --git a/pallets/fellowship/src/lib.rs b/pallets/fellowship/src/lib.rs index 6791e02b..76b2008c 100644 --- a/pallets/fellowship/src/lib.rs +++ b/pallets/fellowship/src/lib.rs @@ -27,13 +27,12 @@ mod benchmarking; #[frame_support::pallet] pub mod pallet { use common_types::CurrencyId; - use frame_support::{pallet_prelude::*, BoundedBTreeMap}; + use frame_support::{pallet_prelude::*, weights::Weight, BoundedBTreeMap}; use frame_system::pallet_prelude::*; use orml_traits::{MultiCurrency, MultiReservableCurrency}; use sp_runtime::traits::Zero; use sp_std::{convert::TryInto, vec}; - use crate::traits::WeightInfoT; use crate::traits::{FellowshipHandle, FellowshipPermissions}; pub(crate) type AccountIdOf = ::AccountId; @@ -407,4 +406,14 @@ pub mod pallet { RemoveFromShortlist, None, } + + pub trait WeightInfoT { + fn add_to_fellowship() -> Weight; + fn force_add_fellowship() -> Weight; + fn leave_fellowship() -> Weight; + fn force_remove_and_slash_fellowship() -> Weight; + fn add_candidate_to_shortlist() -> Weight; + fn remove_candidate_from_shortlist() -> Weight; + fn pay_deposit_to_remove_pending_status() -> Weight; + } } diff --git a/pallets/fellowship/src/mock.rs b/pallets/fellowship/src/mock.rs index ed6abeec..e3cfe371 100644 --- a/pallets/fellowship/src/mock.rs +++ b/pallets/fellowship/src/mock.rs @@ -71,7 +71,7 @@ impl pallet_fellowship::Config for Test { type DepositCurrencyId = DepositCurrencyId; type SlashAccount = SlashAccount; type Permissions = crate::impls::VetterAndFreelancerAllPermissions; - type WeightInfo = (); + type WeightInfo = crate::weights::WeightInfo; } orml_traits::parameter_type_with_key! { @@ -121,28 +121,3 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities { }); ext } - -use frame_support::pallet_prelude::Weight; -impl crate::traits::WeightInfoT for () { - fn add_to_fellowship() -> Weight { - ::default() - } - fn force_add_fellowship() -> Weight { - ::default() - } - fn leave_fellowship() -> Weight { - ::default() - } - fn force_remove_and_slash_fellowship() -> Weight { - ::default() - } - fn add_candidate_to_shortlist() -> Weight { - ::default() - } - fn remove_candidate_from_shortlist() -> Weight { - ::default() - } - fn pay_deposit_to_remove_pending_status() -> Weight { - ::default() - } -} diff --git a/pallets/fellowship/src/traits.rs b/pallets/fellowship/src/traits.rs index 69b19495..62699166 100644 --- a/pallets/fellowship/src/traits.rs +++ b/pallets/fellowship/src/traits.rs @@ -1,6 +1,6 @@ use crate::{Rank, Role}; use codec::{FullCodec, FullEncode}; -use frame_support::{pallet_prelude::*, weights::Weight}; +use frame_support::pallet_prelude::*; use sp_runtime::DispatchError; use sp_std::vec::Vec; @@ -44,13 +44,3 @@ pub trait FellowshipPermissions { fn has_permission(role: Role, permission: Permission) -> bool; fn get_permissions(role: Role) -> Vec; } - -pub trait WeightInfoT { - fn add_to_fellowship() -> Weight; - fn force_add_fellowship() -> Weight; - fn leave_fellowship() -> Weight; - fn force_remove_and_slash_fellowship() -> Weight; - fn add_candidate_to_shortlist() -> Weight; - fn remove_candidate_from_shortlist() -> Weight; - fn pay_deposit_to_remove_pending_status() -> Weight; -} diff --git a/pallets/fellowship/src/weights.rs b/pallets/fellowship/src/weights.rs index b1a781e9..35790ac8 100644 --- a/pallets/fellowship/src/weights.rs +++ b/pallets/fellowship/src/weights.rs @@ -2,43 +2,35 @@ //! Autogenerated weights for `pallet_fellowship` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `user`, CPU: `12th Gen Intel(R) Core(TM) i9-12900H` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("local")`, DB CACHE: 1024 +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("imbue-dev")`, DB CACHE: `1024` // Executed Command: -// ./target/debug/imbue +// ./target/release/imbue // benchmark // pallet -// --chain -// local -// --execution -// wasm -// --wasm-execution -// compiled -// --pallet -// pallet-fellowship -// --extrinsic -// * -// --output -// weights.rs -// --steps -// 50 -// --repeat -// 20 +// --chain=imbue-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_fellowship +// --extrinsic=* +// --output=./pallets/fellowship/src/weights.rs +// --template=./scripts/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; +use crate::WeightInfoT; -/// Weight functions for `pallet_fellowship`. +/// Weights for `pallet_fellowship` using the Substrate node and recommended hardware. pub struct WeightInfo(PhantomData); -impl crate::traits::WeightInfoT for WeightInfo { +impl WeightInfoT for WeightInfo { /// Storage: `ImbueFellowship::Roles` (r:1 w:1) /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) @@ -51,11 +43,10 @@ impl crate::traits::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `145` // Estimated: `3593` - // Minimum execution time: 297_927_000 picoseconds. - Weight::from_parts(299_772_000, 0) - .saturating_add(Weight::from_parts(0, 3593)) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(4)) + // Minimum execution time: 39_145_000 picoseconds. + Weight::from_parts(46_416_000, 3593) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: `ImbueFellowship::Roles` (r:1 w:1) /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) @@ -63,11 +54,10 @@ impl crate::traits::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `42` // Estimated: `3516` - // Minimum execution time: 153_043_000 picoseconds. - Weight::from_parts(154_780_000, 0) - .saturating_add(Weight::from_parts(0, 3516)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 22_070_000 picoseconds. + Weight::from_parts(25_479_000, 3516) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `ImbueFellowship::Roles` (r:1 w:1) /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) @@ -83,11 +73,10 @@ impl crate::traits::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `410` // Estimated: `3593` - // Minimum execution time: 463_315_000 picoseconds. - Weight::from_parts(479_038_000, 0) - .saturating_add(Weight::from_parts(0, 3593)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(4)) + // Minimum execution time: 63_837_000 picoseconds. + Weight::from_parts(67_482_000, 3593) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: `ImbueFellowship::Roles` (r:1 w:1) /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) @@ -103,11 +92,10 @@ impl crate::traits::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `513` // Estimated: `6196` - // Minimum execution time: 894_392_000 picoseconds. - Weight::from_parts(915_373_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(5)) + // Minimum execution time: 129_010_000 picoseconds. + Weight::from_parts(165_370_000, 6196) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: `ImbueFellowship::Roles` (r:2 w:0) /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) @@ -121,11 +109,10 @@ impl crate::traits::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `289` // Estimated: `6886` - // Minimum execution time: 270_206_000 picoseconds. - Weight::from_parts(278_894_000, 0) - .saturating_add(Weight::from_parts(0, 6886)) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 38_347_000 picoseconds. + Weight::from_parts(39_290_000, 6886) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `ImbueFellowship::Roles` (r:1 w:0) /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) @@ -137,11 +124,10 @@ impl crate::traits::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `299` // Estimated: `6886` - // Minimum execution time: 205_598_000 picoseconds. - Weight::from_parts(207_340_000, 0) - .saturating_add(Weight::from_parts(0, 6886)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 30_543_000 picoseconds. + Weight::from_parts(31_317_000, 6886) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `ImbueFellowship::PendingFellows` (r:1 w:1) /// Proof: `ImbueFellowship::PendingFellows` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) @@ -155,10 +141,128 @@ impl crate::traits::WeightInfoT for WeightInfo { // Proof Size summary in bytes: // Measured: `259` // Estimated: `3593` - // Minimum execution time: 392_591_000 picoseconds. - Weight::from_parts(401_207_000, 0) - .saturating_add(Weight::from_parts(0, 3593)) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(4)) + // Minimum execution time: 58_983_000 picoseconds. + Weight::from_parts(65_555_000, 3593) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } } + +// For backwards compatibility and tests. +impl WeightInfoT for () { + /// Storage: `ImbueFellowship::Roles` (r:1 w:1) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::FellowToVetter` (r:0 w:1) + /// Proof: `ImbueFellowship::FellowToVetter` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::FellowshipReserves` (r:0 w:1) + /// Proof: `ImbueFellowship::FellowshipReserves` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) + fn add_to_fellowship() -> Weight { + // Proof Size summary in bytes: + // Measured: `145` + // Estimated: `3593` + // Minimum execution time: 39_145_000 picoseconds. + Weight::from_parts(46_416_000, 3593) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `ImbueFellowship::Roles` (r:1 w:1) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + fn force_add_fellowship() -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `3516` + // Minimum execution time: 22_070_000 picoseconds. + Weight::from_parts(25_479_000, 3516) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `ImbueFellowship::Roles` (r:1 w:1) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::PendingFellows` (r:1 w:1) + /// Proof: `ImbueFellowship::PendingFellows` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::FellowshipReserves` (r:1 w:0) + /// Proof: `ImbueFellowship::FellowshipReserves` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::FellowToVetter` (r:0 w:1) + /// Proof: `ImbueFellowship::FellowToVetter` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + fn leave_fellowship() -> Weight { + // Proof Size summary in bytes: + // Measured: `410` + // Estimated: `3593` + // Minimum execution time: 63_837_000 picoseconds. + Weight::from_parts(67_482_000, 3593) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `ImbueFellowship::Roles` (r:1 w:1) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::PendingFellows` (r:1 w:1) + /// Proof: `ImbueFellowship::PendingFellows` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::FellowshipReserves` (r:1 w:0) + /// Proof: `ImbueFellowship::FellowshipReserves` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::FellowToVetter` (r:0 w:1) + /// Proof: `ImbueFellowship::FellowToVetter` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + fn force_remove_and_slash_fellowship() -> Weight { + // Proof Size summary in bytes: + // Measured: `513` + // Estimated: `6196` + // Minimum execution time: 129_010_000 picoseconds. + Weight::from_parts(165_370_000, 6196) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + /// Storage: `ImbueFellowship::Roles` (r:2 w:0) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::ShortlistRound` (r:1 w:0) + /// Proof: `ImbueFellowship::ShortlistRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::CandidateShortlist` (r:1 w:1) + /// Proof: `ImbueFellowship::CandidateShortlist` (`max_values`: None, `max_size`: Some(3421), added: 5896, mode: `MaxEncodedLen`) + fn add_candidate_to_shortlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `289` + // Estimated: `6886` + // Minimum execution time: 38_347_000 picoseconds. + Weight::from_parts(39_290_000, 6886) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `ImbueFellowship::Roles` (r:1 w:0) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::ShortlistRound` (r:1 w:0) + /// Proof: `ImbueFellowship::ShortlistRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::CandidateShortlist` (r:1 w:1) + /// Proof: `ImbueFellowship::CandidateShortlist` (`max_values`: None, `max_size`: Some(3421), added: 5896, mode: `MaxEncodedLen`) + fn remove_candidate_from_shortlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `299` + // Estimated: `6886` + // Minimum execution time: 30_543_000 picoseconds. + Weight::from_parts(31_317_000, 6886) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `ImbueFellowship::PendingFellows` (r:1 w:1) + /// Proof: `ImbueFellowship::PendingFellows` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::Roles` (r:0 w:1) + /// Proof: `ImbueFellowship::Roles` (`max_values`: None, `max_size`: Some(51), added: 2526, mode: `MaxEncodedLen`) + /// Storage: `ImbueFellowship::FellowshipReserves` (r:0 w:1) + /// Proof: `ImbueFellowship::FellowshipReserves` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) + fn pay_deposit_to_remove_pending_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `259` + // Estimated: `3593` + // Minimum execution time: 58_983_000 picoseconds. + Weight::from_parts(65_555_000, 3593) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } +} \ No newline at end of file diff --git a/pallets/grants/src/benchmarking.rs b/pallets/grants/src/benchmarking.rs index eafa9410..ce780d5e 100644 --- a/pallets/grants/src/benchmarking.rs +++ b/pallets/grants/src/benchmarking.rs @@ -5,7 +5,7 @@ use super::*; use crate::test_utils::gen_grant_id; use crate::Pallet as Grants; use crate::{BoundedApprovers, BoundedPMilestones, Config}; -use common_types::{CurrencyId, TreasuryOrigin, ForeignOwnedAccount}; +use common_types::{CurrencyId, ForeignOwnedAccount, TreasuryOrigin}; use frame_benchmarking::v2::*; use frame_support::{assert_ok, traits::Get}; use frame_system::pallet_prelude::BlockNumberFor; diff --git a/pallets/grants/src/lib.rs b/pallets/grants/src/lib.rs index 54ee327b..33ed7d46 100644 --- a/pallets/grants/src/lib.rs +++ b/pallets/grants/src/lib.rs @@ -130,7 +130,7 @@ pub mod pallet { Error::::EoaRequiredForForeignCurrencies ); } - if let Some(eoa) = external_owned_address { + if let Some(eoa) = external_owned_address.clone() { ensure!( eoa.ensure_supported_currency(currency_id), Error::::CurrencyAccountComboNotSupported diff --git a/pallets/grants/src/weights.rs b/pallets/grants/src/weights.rs index 4a84dc3b..8a7811b2 100644 --- a/pallets/grants/src/weights.rs +++ b/pallets/grants/src/weights.rs @@ -2,43 +2,35 @@ //! Autogenerated weights for `pallet_grants` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `user`, CPU: `12th Gen Intel(R) Core(TM) i9-12900H` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("local")`, DB CACHE: 1024 +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("imbue-dev")`, DB CACHE: `1024` // Executed Command: -// ./target/debug/imbue +// ./target/release/imbue // benchmark // pallet -// --chain -// local -// --execution -// wasm -// --wasm-execution -// compiled -// --pallet -// pallet-grants -// --extrinsic -// * -// --output -// weights.rs -// --steps -// 50 -// --repeat -// 20 +// --chain=imbue-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_grants +// --extrinsic=* +// --output=./pallets/grants/src/weights.rs +// --template=./scripts/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; +use crate::WeightInfoT; -/// Weight functions for `pallet_grants`. +/// Weights for `pallet_grants` using the Substrate node and recommended hardware. pub struct WeightInfo(PhantomData); -impl crate::WeightInfoT for WeightInfo { +impl WeightInfoT for WeightInfo { /// Storage: `ImbueGrants::GrantsSubmitted` (r:1 w:1) /// Proof: `ImbueGrants::GrantsSubmitted` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::ProjectCount` (r:1 w:1) @@ -48,21 +40,49 @@ impl crate::WeightInfoT for WeightInfo { /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Deposits::CurrentDeposits` (r:0 w:1) - /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) /// Storage: `ImbueGrants::GrantsSubmittedBy` (r:0 w:1) /// Proof: `ImbueGrants::GrantsSubmittedBy` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Projects` (r:0 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::IndividualVoteStore` (r:0 w:1) /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) fn create_and_convert() -> Weight { // Proof Size summary in bytes: // Measured: `369` // Estimated: `3593` - // Minimum execution time: 1_038_238_000 picoseconds. - Weight::from_parts(1_072_638_000, 0) - .saturating_add(Weight::from_parts(0, 3593)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(8)) + // Minimum execution time: 173_015_000 picoseconds. + Weight::from_parts(187_411_000, 3593) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } } + +// For backwards compatibility and tests. +impl WeightInfoT for () { + /// Storage: `ImbueGrants::GrantsSubmitted` (r:1 w:1) + /// Proof: `ImbueGrants::GrantsSubmitted` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectCount` (r:1 w:1) + /// Proof: `ImbueProposals::ProjectCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Deposits::TicketId` (r:1 w:1) + /// Proof: `Deposits::TicketId` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Deposits::CurrentDeposits` (r:0 w:1) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) + /// Storage: `ImbueGrants::GrantsSubmittedBy` (r:0 w:1) + /// Proof: `ImbueGrants::GrantsSubmittedBy` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Projects` (r:0 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::IndividualVoteStore` (r:0 w:1) + /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) + fn create_and_convert() -> Weight { + // Proof Size summary in bytes: + // Measured: `369` + // Estimated: `3593` + // Minimum execution time: 173_015_000 picoseconds. + Weight::from_parts(187_411_000, 3593) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) + } +} \ No newline at end of file diff --git a/pallets/proposals/src/benchmarking.rs b/pallets/proposals/src/benchmarking.rs index be1f3a07..8005f347 100644 --- a/pallets/proposals/src/benchmarking.rs +++ b/pallets/proposals/src/benchmarking.rs @@ -220,7 +220,8 @@ mod benchmarks { project_key, milestone_keys.clone() )); - let _ = as DisputeHooks>::on_dispute_complete( + let _ = as DisputeHooks>>::on_dispute_complete( + bob.clone(), project_key, milestone_keys.into_inner(), DisputeResult::Success, diff --git a/pallets/proposals/src/impls/pallet_impls.rs b/pallets/proposals/src/impls/pallet_impls.rs index 6c126738..636212ce 100644 --- a/pallets/proposals/src/impls/pallet_impls.rs +++ b/pallets/proposals/src/impls/pallet_impls.rs @@ -337,8 +337,9 @@ impl Pallet { } } -impl DisputeHooks for Pallet { +impl DisputeHooks> for Pallet { fn on_dispute_complete( + raised_by: AccountIdOf, project_key: ProjectKey, specifics: Vec, dispute_result: pallet_disputes::pallet::DisputeResult, @@ -354,7 +355,11 @@ impl DisputeHooks for Pallet { // Shouldnt be needed but nice to have this check. // Will prevent someone calling both refund and withdraw on the same milestone. if milestone.transfer_status.is_none() { - milestone.can_refund = true; + if project.initiator == raised_by { + milestone.is_approved = true; + } else { + milestone.can_refund = true; + } } } } diff --git a/pallets/proposals/src/lib.rs b/pallets/proposals/src/lib.rs index ac350a70..31f5c666 100644 --- a/pallets/proposals/src/lib.rs +++ b/pallets/proposals/src/lib.rs @@ -344,14 +344,14 @@ pub mod pallet { TooManyMilestoneVotes, /// An internal error, a collection of votes for a milestone has been lost.s IndividualVoteNotFound, - /// Only a contributor can raise a dispute. - OnlyContributorsCanRaiseDispute, + /// Only a contributor can initiate a refund. + OnlyContributorsCanInitiateRefund, /// One of these milestones is already in a dispute. MilestonesAlreadyInDispute, /// You cannot raise a dispute on an approved milestone. CannotRaiseDisputeOnApprovedMilestone, - /// Only a contributor can initiate a refund. - OnlyContributorsCanInitiateRefund, + /// Only a contributor or initiator can initiate a refund. + NotPermittedToRaiseDispute, /// Only the ForeignAssetSigner can mint tokens RequireForeignAssetSigner, /// A Jury is required to create a project. @@ -456,9 +456,10 @@ pub mod pallet { Error::::MilestoneDoesNotExist ); ensure!( - project.contributions.contains_key(&who), - Error::::OnlyContributorsCanRaiseDispute + project.contributions.contains_key(&who) || &who == &project.initiator, + Error::::NotPermittedToRaiseDispute ); + ensure!( !ProjectsInDispute::::contains_key(project_key), Error::::MilestonesAlreadyInDispute @@ -472,7 +473,16 @@ pub mod pallet { if project.jury.len() == 1 { // https://github.com/ImbueNetwork/imbue/issues/270 - let _ = >::on_dispute_complete(project_key, milestone_keys.to_vec(), pallet_disputes::DisputeResult::Success); + let _ = , + >>::on_dispute_complete( + who, + project_key, + milestone_keys.to_vec(), + pallet_disputes::DisputeResult::Success, + ); } else { ::DisputeRaiser::raise_dispute( project_key, diff --git a/pallets/proposals/src/test_utils.rs b/pallets/proposals/src/test_utils.rs index 6803a5d9..f9995202 100644 --- a/pallets/proposals/src/test_utils.rs +++ b/pallets/proposals/src/test_utils.rs @@ -140,11 +140,12 @@ pub fn create_funded_user( /// Manually call the hook OnDisputeCompleteWith a predefined result for testing> pub fn complete_dispute( + dispute_raised_by: T::AccountId, project_key: ProjectKey, milestone_keys: Vec, result: pallet_disputes::DisputeResult, ) -> crate::Weight { - >::on_dispute_complete(project_key, milestone_keys, result) + >::on_dispute_complete(dispute_raised_by, project_key, milestone_keys, result) } pub fn assert_last_event(generic_event: ::RuntimeEvent) { diff --git a/pallets/proposals/src/tests/dispute_approvals.rs b/pallets/proposals/src/tests/dispute_approvals.rs new file mode 100644 index 00000000..87ef9c85 --- /dev/null +++ b/pallets/proposals/src/tests/dispute_approvals.rs @@ -0,0 +1,54 @@ +use crate::{mock::*, *}; +use frame_support::{assert_noop, assert_ok}; +use pallet_disputes::DisputeResult; +use test_utils::*; + +#[test] +fn initiator_dispute_complete_sets_milestones_to_approved() { + build_test_externality().execute_with(|| { + let per_contribution = 100000u128; + let contributions = get_contributions::(vec![BOB, CHARLIE], per_contribution); + let milestones = get_milestones(10); + let jury = vec![JURY_1, JURY_2]; + let initiator = ALICE; + + let project_key = create_and_fund_project::( + ALICE, + contributions, + milestones.clone(), + CurrencyId::Native, + jury, + ) + .unwrap(); + let milestone_keys: BoundedVec::MaxMilestonesPerProject> = (1u32 + ..milestones.len() as u32) + .collect::>() + .try_into() + .unwrap(); + + assert_ok!(Proposals::raise_dispute( + RuntimeOrigin::signed(initiator), + project_key, + milestone_keys.clone() + )); + + let _ = complete_dispute::( + initiator, + project_key, + milestone_keys.into_inner(), + DisputeResult::Success, + ); + + let project = Projects::::get(project_key).unwrap(); + + for milestone in project.milestones.iter().for_each(|(key, milestone)|{ + if milestone_keys.contains(&key) { + assert!(milestone.is_approved, "dispute success for initiator should approve milestones.") + } else { + assert!(!milestone.is_approved, "other milestones should be left unapproved.") + } + }) + }) +} + + diff --git a/pallets/proposals/src/tests/disputes.rs b/pallets/proposals/src/tests/disputes.rs index 87a76afe..1c34d360 100644 --- a/pallets/proposals/src/tests/disputes.rs +++ b/pallets/proposals/src/tests/disputes.rs @@ -5,7 +5,7 @@ use pallet_disputes::DisputeResult; use test_utils::*; #[test] -fn raise_dispute_not_contributor() { +fn raise_dispute_not_contributor_or_initiator() { build_test_externality().execute_with(|| { let contributions = get_contributions::(vec![BOB, CHARLIE], 1_000_000u128); let milestones = get_milestones(10); @@ -27,7 +27,7 @@ fn raise_dispute_not_contributor() { assert_noop!( Proposals::raise_dispute(RuntimeOrigin::signed(JOHN), project_key, milestone_keys), - Error::::OnlyContributorsCanRaiseDispute + Error::::NotPermittedToRaiseDispute ); }) } @@ -206,6 +206,7 @@ fn on_dispute_complete_success_removes_dispute_status() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -240,6 +241,7 @@ fn on_dispute_complete_failure_removes_dispute_status() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Failure, @@ -275,6 +277,7 @@ fn dispute_success_does_not_cancel_project() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -312,6 +315,7 @@ fn dispute_success_approves_milestone_for_refund_but_only_ones_specified() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -485,6 +489,7 @@ fn failed_dispute_tests() { dispute_milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, dispute_milestone_keys.into_inner(), DisputeResult::Failure, @@ -525,6 +530,7 @@ fn assert_can_recall_dispute_after_success() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -564,6 +570,7 @@ fn assert_can_recall_dispute_after_failure() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Failure, @@ -627,3 +634,61 @@ fn raise_dispute_with_single_jury_auto_completes() { }); }) } + +#[test] +fn raise_dispute_as_initiator_success() { + build_test_externality().execute_with(|| { + let contributions = get_contributions::(vec![BOB, CHARLIE], 1_000_000u128); + let milestones = get_milestones(10); + let jury = vec![JURY_1, JURY_2]; + + let project_key = create_and_fund_project::( + ALICE, + contributions, + milestones.clone(), + CurrencyId::Native, + jury, + ) + .unwrap(); + + let dispute_milestone_keys: BoundedVec::MaxMilestonesPerProject> = + (0u32..milestones.len() as u32) + .collect::>() + .try_into() + .unwrap(); + assert_ok!(Proposals::raise_dispute( + RuntimeOrigin::signed(ALICE), + project_key, + dispute_milestone_keys + )); + }) +} + +#[test] +fn raise_dispute_as_contributor_success() { + build_test_externality().execute_with(|| { + let contributions = get_contributions::(vec![BOB, CHARLIE], 1_000_000u128); + let milestones = get_milestones(10); + let jury = vec![JURY_1, JURY_2]; + + let project_key = create_and_fund_project::( + ALICE, + contributions, + milestones.clone(), + CurrencyId::Native, + jury, + ) + .unwrap(); + + let dispute_milestone_keys: BoundedVec::MaxMilestonesPerProject> = + (0u32..milestones.len() as u32) + .collect::>() + .try_into() + .unwrap(); + assert_ok!(Proposals::raise_dispute( + RuntimeOrigin::signed(BOB), + project_key, + dispute_milestone_keys + )); + }) +} diff --git a/pallets/proposals/src/tests/refunds.rs b/pallets/proposals/src/tests/refunds.rs index bca95eec..8633aa7f 100644 --- a/pallets/proposals/src/tests/refunds.rs +++ b/pallets/proposals/src/tests/refunds.rs @@ -29,6 +29,7 @@ fn you_can_actually_refund_after_dispute_success() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -63,6 +64,7 @@ fn refund_assert_milestone_state_change() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -116,6 +118,7 @@ fn refund_not_contributor() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -153,6 +156,7 @@ fn refund_deletes_project_when_all_funds_are_refunded() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -198,6 +202,7 @@ fn withdraw_then_refund_no_double_spend() { milestone_keys.clone(), ); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -268,6 +273,7 @@ fn refund_then_withdraw_no_double_spend() { milestone_keys.clone(), ); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -322,6 +328,7 @@ fn refund_check_refund_amount() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, @@ -383,6 +390,7 @@ fn refund_takes_imbue_fee() { milestone_keys.clone() )); let _ = complete_dispute::( + BOB, project_key, milestone_keys.into_inner(), DisputeResult::Success, diff --git a/pallets/proposals/src/weights.rs b/pallets/proposals/src/weights.rs index db9727fe..ed533ee3 100644 --- a/pallets/proposals/src/weights.rs +++ b/pallets/proposals/src/weights.rs @@ -2,45 +2,37 @@ //! Autogenerated weights for `pallet_proposals` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `user`, CPU: `12th Gen Intel(R) Core(TM) i9-12900H` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("local")`, DB CACHE: 1024 +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("imbue-dev")`, DB CACHE: `1024` // Executed Command: -// ./target/debug/imbue +// ./target/release/imbue // benchmark // pallet -// --chain -// local -// --execution -// wasm -// --wasm-execution -// compiled -// --pallet -// pallet-proposals -// --extrinsic -// * -// --output -// weights.rs -// --steps -// 50 -// --repeat -// 20 +// --chain=imbue-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_proposals +// --extrinsic=* +// --output=./pallets/proposals/src/weights.rs +// --template=./scripts/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; +use crate::WeightInfoT; -/// Weight functions for `pallet_proposals`. +/// Weights for `pallet_proposals` using the Substrate node and recommended hardware. pub struct WeightInfo(PhantomData); -impl crate::WeightInfoT for WeightInfo { +impl WeightInfoT for WeightInfo { /// Storage: `ImbueProposals::Projects` (r:1 w:0) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::RoundsExpiring` (r:1 w:1) /// Proof: `ImbueProposals::RoundsExpiring` (`max_values`: None, `max_size`: Some(111), added: 2586, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::IndividualVoteStore` (r:1 w:1) @@ -49,18 +41,19 @@ impl crate::WeightInfoT for WeightInfo { /// Proof: `ImbueProposals::MilestoneVotes` (`max_values`: None, `max_size`: Some(375), added: 2850, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Rounds` (r:0 w:1) /// Proof: `ImbueProposals::Rounds` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectInVoting` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectInVoting` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) fn submit_milestone() -> Weight { // Proof Size summary in bytes: - // Measured: `568` - // Estimated: `39815` - // Minimum execution time: 345_914_000 picoseconds. - Weight::from_parts(354_103_000, 0) - .saturating_add(Weight::from_parts(0, 39815)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(4)) + // Measured: `889` + // Estimated: `39920` + // Minimum execution time: 61_006_000 picoseconds. + Weight::from_parts(68_916_000, 39920) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: `ImbueProposals::Projects` (r:1 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Rounds` (r:1 w:1) /// Proof: `ImbueProposals::Rounds` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::IndividualVoteStore` (r:1 w:1) @@ -69,33 +62,33 @@ impl crate::WeightInfoT for WeightInfo { /// Proof: `ImbueProposals::MilestoneVotes` (`max_values`: None, `max_size`: Some(375), added: 2850, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::RoundsExpiring` (r:0 w:1) /// Proof: `ImbueProposals::RoundsExpiring` (`max_values`: None, `max_size`: Some(111), added: 2586, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectInVoting` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectInVoting` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) fn vote_on_milestone() -> Weight { // Proof Size summary in bytes: - // Measured: `711` - // Estimated: `39815` - // Minimum execution time: 460_847_000 picoseconds. - Weight::from_parts(472_559_000, 0) - .saturating_add(Weight::from_parts(0, 39815)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(5)) + // Measured: `1069` + // Estimated: `39920` + // Minimum execution time: 94_587_000 picoseconds. + Weight::from_parts(112_360_000, 39920) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: `ImbueProposals::Projects` (r:1 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Deposits::CurrentDeposits` (r:1 w:1) - /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::CompletedProjects` (r:1 w:1) /// Proof: `ImbueProposals::CompletedProjects` (`max_values`: None, `max_size`: Some(262184), added: 264659, mode: `MaxEncodedLen`) fn withdraw() -> Weight { // Proof Size summary in bytes: - // Measured: `1120` + // Measured: `1503` // Estimated: `265649` - // Minimum execution time: 1_638_213_000 picoseconds. - Weight::from_parts(1_677_055_000, 0) - .saturating_add(Weight::from_parts(0, 265649)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(6)) + // Minimum execution time: 252_196_000 picoseconds. + Weight::from_parts(300_488_000, 265649) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: `ImbueProposals::RoundsExpiring` (r:1 w:1) /// Proof: `ImbueProposals::RoundsExpiring` (`max_values`: None, `max_size`: Some(111), added: 2586, mode: `MaxEncodedLen`) @@ -105,18 +98,19 @@ impl crate::WeightInfoT for WeightInfo { /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::Rounds` (r:0 w:1) /// Proof: `ImbueProposals::Rounds` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectInVoting` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectInVoting` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) fn on_initialize() -> Weight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `20036` - // Minimum execution time: 147_964_000 picoseconds. - Weight::from_parts(151_147_000, 0) - .saturating_add(Weight::from_parts(0, 20036)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(4)) + // Minimum execution time: 20_005_000 picoseconds. + Weight::from_parts(22_550_000, 20036) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: `ImbueProposals::Projects` (r:1 w:0) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `ImbueProposals::ProjectsInDispute` (r:1 w:1) /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) @@ -125,26 +119,136 @@ impl crate::WeightInfoT for WeightInfo { /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) fn raise_dispute() -> Weight { // Proof Size summary in bytes: - // Measured: `4797` - // Estimated: `39815` - // Minimum execution time: 346_461_000 picoseconds. - Weight::from_parts(356_015_000, 0) - .saturating_add(Weight::from_parts(0, 39815)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(3)) + // Measured: `5118` + // Estimated: `39920` + // Minimum execution time: 83_336_000 picoseconds. + Weight::from_parts(85_489_000, 39920) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: `ImbueProposals::Projects` (r:1 w:1) - /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36350), added: 38825, mode: `MaxEncodedLen`) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:52 w:52) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn refund() -> Weight { // Proof Size summary in bytes: - // Measured: `11381` + // Measured: `12011` // Estimated: `136346` - // Minimum execution time: 23_947_016_000 picoseconds. - Weight::from_parts(24_080_686_000, 0) - .saturating_add(Weight::from_parts(0, 136346)) - .saturating_add(T::DbWeight::get().reads(53)) - .saturating_add(T::DbWeight::get().writes(53)) + // Minimum execution time: 3_089_534_000 picoseconds. + Weight::from_parts(3_135_786_000, 136346) + .saturating_add(T::DbWeight::get().reads(53_u64)) + .saturating_add(T::DbWeight::get().writes(53_u64)) } } + +// For backwards compatibility and tests. +impl WeightInfoT for () { + /// Storage: `ImbueProposals::Projects` (r:1 w:0) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::RoundsExpiring` (r:1 w:1) + /// Proof: `ImbueProposals::RoundsExpiring` (`max_values`: None, `max_size`: Some(111), added: 2586, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::IndividualVoteStore` (r:1 w:1) + /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::MilestoneVotes` (r:1 w:1) + /// Proof: `ImbueProposals::MilestoneVotes` (`max_values`: None, `max_size`: Some(375), added: 2850, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Rounds` (r:0 w:1) + /// Proof: `ImbueProposals::Rounds` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectInVoting` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectInVoting` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + fn submit_milestone() -> Weight { + // Proof Size summary in bytes: + // Measured: `889` + // Estimated: `39920` + // Minimum execution time: 61_006_000 picoseconds. + Weight::from_parts(68_916_000, 39920) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + /// Storage: `ImbueProposals::Projects` (r:1 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Rounds` (r:1 w:1) + /// Proof: `ImbueProposals::Rounds` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::IndividualVoteStore` (r:1 w:1) + /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::MilestoneVotes` (r:1 w:1) + /// Proof: `ImbueProposals::MilestoneVotes` (`max_values`: None, `max_size`: Some(375), added: 2850, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::RoundsExpiring` (r:0 w:1) + /// Proof: `ImbueProposals::RoundsExpiring` (`max_values`: None, `max_size`: Some(111), added: 2586, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectInVoting` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectInVoting` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + fn vote_on_milestone() -> Weight { + // Proof Size summary in bytes: + // Measured: `1069` + // Estimated: `39920` + // Minimum execution time: 94_587_000 picoseconds. + Weight::from_parts(112_360_000, 39920) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `ImbueProposals::Projects` (r:1 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Deposits::CurrentDeposits` (r:1 w:1) + /// Proof: `Deposits::CurrentDeposits` (`max_values`: None, `max_size`: Some(66), added: 2541, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::CompletedProjects` (r:1 w:1) + /// Proof: `ImbueProposals::CompletedProjects` (`max_values`: None, `max_size`: Some(262184), added: 264659, mode: `MaxEncodedLen`) + fn withdraw() -> Weight { + // Proof Size summary in bytes: + // Measured: `1503` + // Estimated: `265649` + // Minimum execution time: 252_196_000 picoseconds. + Weight::from_parts(300_488_000, 265649) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `ImbueProposals::RoundsExpiring` (r:1 w:1) + /// Proof: `ImbueProposals::RoundsExpiring` (`max_values`: None, `max_size`: Some(111), added: 2586, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::MilestoneVotes` (r:1 w:1) + /// Proof: `ImbueProposals::MilestoneVotes` (`max_values`: None, `max_size`: Some(375), added: 2850, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::IndividualVoteStore` (r:1 w:1) + /// Proof: `ImbueProposals::IndividualVoteStore` (`max_values`: None, `max_size`: Some(16571), added: 19046, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::Rounds` (r:0 w:1) + /// Proof: `ImbueProposals::Rounds` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectInVoting` (r:0 w:1) + /// Proof: `ImbueProposals::ProjectInVoting` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + fn on_initialize() -> Weight { + // Proof Size summary in bytes: + // Measured: `97` + // Estimated: `20036` + // Minimum execution time: 20_005_000 picoseconds. + Weight::from_parts(22_550_000, 20036) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + /// Storage: `ImbueProposals::Projects` (r:1 w:0) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `ImbueProposals::ProjectsInDispute` (r:1 w:1) + /// Proof: `ImbueProposals::ProjectsInDispute` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Storage: `ImbueDisputes::Disputes` (r:1 w:1) + /// Proof: `ImbueDisputes::Disputes` (`max_values`: None, `max_size`: Some(6602), added: 9077, mode: `MaxEncodedLen`) + /// Storage: `ImbueDisputes::DisputesFinaliseOn` (r:1 w:1) + /// Proof: `ImbueDisputes::DisputesFinaliseOn` (`max_values`: None, `max_size`: Some(221), added: 2696, mode: `MaxEncodedLen`) + fn raise_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `5118` + // Estimated: `39920` + // Minimum execution time: 83_336_000 picoseconds. + Weight::from_parts(85_489_000, 39920) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `ImbueProposals::Projects` (r:1 w:1) + /// Proof: `ImbueProposals::Projects` (`max_values`: None, `max_size`: Some(36455), added: 38930, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:52 w:52) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn refund() -> Weight { + // Proof Size summary in bytes: + // Measured: `12011` + // Estimated: `136346` + // Minimum execution time: 3_089_534_000 picoseconds. + Weight::from_parts(3_135_786_000, 136346) + .saturating_add(RocksDbWeight::get().reads(53_u64)) + .saturating_add(RocksDbWeight::get().writes(53_u64)) + } +} \ No newline at end of file diff --git a/runtime/imbue-kusama/Cargo.toml b/runtime/imbue-kusama/Cargo.toml index 7af2a092..1031662f 100644 --- a/runtime/imbue-kusama/Cargo.toml +++ b/runtime/imbue-kusama/Cargo.toml @@ -91,7 +91,7 @@ orml-unknown-tokens = { git = "https://github.com/open-web3-stack/open-runtime-m # Used for runtime benchmarking frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", optional = true } frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", optional = true } -hex-literal = { version = "0.3.4", optional = true } +hex-literal = { version = "0.3.4"} # Local Dependencies common-traits = { path = "../../libs/common-traits", default-features = false } @@ -275,7 +275,6 @@ runtime-benchmarks = [ 'frame-benchmarking/runtime-benchmarks', 'frame-support/runtime-benchmarks', 'frame-system-benchmarking/runtime-benchmarks', - "hex-literal", 'pallet-balances/runtime-benchmarks', 'pallet-briefs/runtime-benchmarks', 'pallet-collective/runtime-benchmarks', diff --git a/runtime/imbue-kusama/src/lib.rs b/runtime/imbue-kusama/src/lib.rs index aa522013..b2ef4b33 100644 --- a/runtime/imbue-kusama/src/lib.rs +++ b/runtime/imbue-kusama/src/lib.rs @@ -101,7 +101,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("imbue"), impl_name: create_runtime_str!("imbue"), authoring_version: 2, - spec_version: 1_100_002, + spec_version: 1_100_003, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -1327,6 +1327,8 @@ type AccountIdOf = ::AccountId; pub struct PointerBasedJurySelector(T); impl pallet_fellowship::traits::SelectJury> for PointerBasedJurySelector +where + T: frame_system::Config, { type JurySize = MaxJurySize; fn select_jury() -> frame_support::BoundedVec, Self::JurySize> { @@ -1354,6 +1356,29 @@ impl pallet_fellowship::traits::SelectJury::put(pointer_with_bound); - out + + if out.len() == 0 { + vec![ + sp_runtime::AccountId32::new(hex_literal::hex![ + "4294eb45758b4b92b01ceffe209bbcfeb26c973d5c0e21ac6c9cfbb99201b334" + ]), + sp_runtime::AccountId32::new(hex_literal::hex![ + "328d9a97c6f7f0fbbc60be2faba4c36cd4e5d3cfcb316393b384ee1a45433034" + ]), + sp_runtime::AccountId32::new(hex_literal::hex![ + "3e064fcfd9f02b99dda26226d3d6b2d68032b1c990e7a350cd01747271356f4c" + ]), + sp_runtime::AccountId32::new(hex_literal::hex![ + "82bf733f44a840f0a5c1935a002d4e541d81298fad6d1da8124073485983860e" + ]), + sp_runtime::AccountId32::new(hex_literal::hex![ + "5a1616831e4508abf2eced2670199ab7a00e9e2bbcfc04655ba7ed138af8787d" + ]), + ] + .try_into() + .unwrap_or_default() + } else { + out + } } } diff --git a/scripts/frame-weight-template.hbs b/scripts/frame-weight-template.hbs index 16e71c46..83107d69 100644 --- a/scripts/frame-weight-template.hbs +++ b/scripts/frame-weight-template.hbs @@ -1,11 +1,11 @@ {{header}} -//! Autogenerated weights for {{pallet}} +//! Autogenerated weights for `{{pallet}}` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} //! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` //! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}` //! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` -//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} +//! WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: `{{cmd.db_cache}}` // Executed Command: {{#each args as |arg|}} @@ -15,28 +15,15 @@ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] +#![allow(missing_docs)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; +use core::marker::PhantomData; +use crate::WeightInfoT; -/// Weight functions needed for {{pallet}}. -pub trait WeightInfo { - {{#each benchmarks as |benchmark|}} - fn {{benchmark.name~}} - ( - {{~#each benchmark.components as |c| ~}} - {{c.name}}: u32, {{/each~}} - ) -> Weight; - {{/each}} -} - -/// Weights for {{pallet}} using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -{{#if (eq pallet "frame_system")}} -impl WeightInfo for SubstrateWeight { -{{else}} -impl WeightInfo for SubstrateWeight { -{{/if}} +/// Weights for `{{pallet}}` using the Substrate node and recommended hardware. +pub struct WeightInfo(PhantomData); +impl WeightInfoT for WeightInfo { {{#each benchmarks as |benchmark|}} {{#each benchmark.comments as |comment|}} /// {{comment}} @@ -77,8 +64,8 @@ impl WeightInfo for SubstrateWeight { {{/each}} } -// For backwards compatibility and tests -impl WeightInfo for () { +// For backwards compatibility and tests. +impl WeightInfoT for () { {{#each benchmarks as |benchmark|}} {{#each benchmark.comments as |comment|}} /// {{comment}} diff --git a/scripts/pallet_index.rs b/scripts/pallet_index.rs deleted file mode 100644 index 79c29295..00000000 --- a/scripts/pallet_index.rs +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -use walkdir::WalkDir; // "2.3.2" -use regex::Regex; // "1.7.0" - -// Call with `substrate/frame` as the only argument. -fn main() { - let folder = std::env::args().nth(1).unwrap(); - let re = Regex::new(r"^(\s+)#\[pallet::weight\(").expect("Regex is known good"); - let mut modified_files = 0; - let mut modified_calls = 0; - - for f in WalkDir::new(folder).into_iter().filter_map(|e| e.ok()) { - if f.metadata().unwrap().is_file() { - // Only process Rust files: - if !f.path().to_str().unwrap().ends_with(".rs") { - continue; - } - // Exclude the pallet-ui tests: - if f.path().to_str().unwrap().contains("pallet_ui") { - continue; - } - - let content = std::fs::read_to_string(f.path()).unwrap(); - let mut new_lines = Vec::with_capacity(content.lines().count()); - let mut call_index = 0; - - for (i, line) in content.lines().enumerate() { - let m = re.captures(line); - if let Some(m) = m { - // Skip if there is already a call index before or after: - if i > 0 && content.lines().nth(i - 1).unwrap().contains("pallet::call_index") { - continue; - } - if i +1 < content.lines().count() && content.lines().nth(i + 1).unwrap().contains("pallet::call_index") { - continue; - } - - println!("{}:{} index {}", f.path().display(), i, call_index); - new_lines.push(format!("{}#[pallet::call_index({})]", m.get(1).unwrap().as_str(), call_index)); - call_index += 1; - } - new_lines.push(line.to_string()); - } - - if call_index > 0 { - std::fs::write(f.path(), new_lines.join("\n")).unwrap(); - println!("Inserted {} indices for {}", call_index, f.path().display()); - modified_files += 1; - modified_calls += call_index; - } - } - } - println!("Modified {} files and {} calls in total", modified_files, modified_calls); -} - diff --git a/scripts/run_benchmarks.sh b/scripts/run_benchmarks.sh new file mode 100755 index 00000000..0014ae74 --- /dev/null +++ b/scripts/run_benchmarks.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -eou pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")" +cd ../ +cargo build --release --locked --features runtime-benchmarks + +IMBUE=./target/release/imbue + +EXCLUDED_PALLETS=( + "frame_benchmarking" + "frame_system" + "pallet_balances" + "pallet_timestamp" +) + +ALL_PALLETS=($( + $IMBUE benchmark pallet --list --chain=imbue-dev |\ + tail -n+2 |\ + cut -d',' -f1 |\ + sort |\ + uniq +)); + +PALLETS=($({ printf '%s\n' "${ALL_PALLETS[@]}" "${EXCLUDED_PALLETS[@]}"; } | sort | uniq -u)) + +echo "Benchmarking ${#PALLETS[@]} Imbue pallets." +for PALLET in "${PALLETS[@]}"; do + + FOLDER="$(echo "${PALLET#*_}" | tr '_' '-')"; + WEIGHT_FILE="./pallets/${FOLDER}/src/weights.rs" + echo "Benchmarking $PALLET with weight file $WEIGHT_FILE"; + + $IMBUE benchmark pallet \ + --chain="imbue-dev" \ + --steps=50 \ + --repeat=20 \ + --pallet="$PALLET" \ + --extrinsic="*" \ + --output="$WEIGHT_FILE" \ + --template="./scripts/frame-weight-template.hbs" 2>&1 + +done +exit 0 \ No newline at end of file