From 5d0907d9fce6214cb34a5921ea0cdd7da3daf589 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Mon, 15 Feb 2021 16:15:24 +1300 Subject: [PATCH 01/10] emit event on remark --- frame/system/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index e521a082a91ca..6f48070084f86 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -292,12 +292,12 @@ pub mod pallet { /// /// # /// - `O(1)` - /// - Base Weight: 0.665 µs, independent of remark length. - /// - No DB operations. + /// - 1 event. /// # - #[pallet::weight(T::SystemWeightInfo::remark(_remark.len() as u32))] - pub(crate) fn remark(origin: OriginFor, _remark: Vec) -> DispatchResultWithPostInfo { + #[pallet::weight(T::SystemWeightInfo::remark(remark.len() as u32))] + pub(crate) fn remark(origin: OriginFor, remark: Vec) -> DispatchResultWithPostInfo { ensure_signed(origin)?; + Self::deposit_event(Event::Remarked(remark)); Ok(().into()) } @@ -466,6 +466,8 @@ pub mod pallet { NewAccount(T::AccountId), /// An \[account\] was reaped. KilledAccount(T::AccountId), + /// On on-chain \[remark\] happened. + Remarked(Vec), } /// Old name generated by `decl_event`. From bc3e674d24504510f1394054d88b929673cf3ed0 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Sat, 20 Feb 2021 16:49:22 +1300 Subject: [PATCH 02/10] update to use remark_with_event --- frame/system/benchmarking/src/lib.rs | 6 ++++++ frame/system/src/lib.rs | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/frame/system/benchmarking/src/lib.rs b/frame/system/benchmarking/src/lib.rs index 9ff749950ab5e..0cee7ef2fd003 100644 --- a/frame/system/benchmarking/src/lib.rs +++ b/frame/system/benchmarking/src/lib.rs @@ -44,6 +44,12 @@ benchmarks! { let caller = whitelisted_caller(); }: _(RawOrigin::Signed(caller), remark_message) + remark_with_event { + let b in 0 .. *T::BlockLength::get().max.get(DispatchClass::Normal) as u32; + let remark_message = vec![1; b as usize]; + let caller = whitelisted_caller(); + }: _(RawOrigin::Signed(caller), remark_message) + set_heap_pages { }: _(RawOrigin::Root, Default::default()) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 6f48070084f86..c053132413e93 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -292,12 +292,10 @@ pub mod pallet { /// /// # /// - `O(1)` - /// - 1 event. /// # #[pallet::weight(T::SystemWeightInfo::remark(remark.len() as u32))] - pub(crate) fn remark(origin: OriginFor, remark: Vec) -> DispatchResultWithPostInfo { + pub(crate) fn remark(origin: OriginFor, _remark: Vec) -> DispatchResultWithPostInfo { ensure_signed(origin)?; - Self::deposit_event(Event::Remarked(remark)); Ok(().into()) } @@ -450,6 +448,19 @@ pub mod pallet { storage::unhashed::kill_prefix(&prefix); Ok(().into()) } + + /// Make some on-chain remark and emit event. + /// + /// # + /// - `O(1)` + /// - 1 event. + /// # + #[pallet::weight(T::SystemWeightInfo::remark(remark.len() as u32))] + pub(crate) fn remark_with_event(origin: OriginFor, remark: Vec) -> DispatchResultWithPostInfo { + ensure_signed(origin)?; + Self::deposit_event(Event::Remarked(remark)); + Ok(().into()) + } } /// Event for the System pallet. From 17c80d7efe78c9b3673a1b04c39ba1fd773d75da Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Sat, 20 Feb 2021 16:53:36 +1300 Subject: [PATCH 03/10] manually updating weight file --- frame/system/src/lib.rs | 2 +- frame/system/src/weights.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index c053132413e93..a31622a3fca08 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -455,7 +455,7 @@ pub mod pallet { /// - `O(1)` /// - 1 event. /// # - #[pallet::weight(T::SystemWeightInfo::remark(remark.len() as u32))] + #[pallet::weight(T::SystemWeightInfo::remark_with_event(remark.len() as u32))] pub(crate) fn remark_with_event(origin: OriginFor, remark: Vec) -> DispatchResultWithPostInfo { ensure_signed(origin)?; Self::deposit_event(Event::Remarked(remark)); diff --git a/frame/system/src/weights.rs b/frame/system/src/weights.rs index f28e90b34c38b..47f7b65c31db3 100644 --- a/frame/system/src/weights.rs +++ b/frame/system/src/weights.rs @@ -50,6 +50,7 @@ pub trait WeightInfo { fn kill_storage(i: u32, ) -> Weight; fn kill_prefix(p: u32, ) -> Weight; fn suicide() -> Weight; + fn remark_with_event(b: u32, ) -> Weight; } /// Weights for frame_system using the Substrate node and recommended hardware. @@ -85,6 +86,9 @@ impl WeightInfo for SubstrateWeight { fn suicide() -> Weight { (37_209_000 as Weight) } + fn remark_with_event(_b: u32, ) -> Weight { + (1_973_000 as Weight) + } } // For backwards compatibility and tests @@ -119,4 +123,7 @@ impl WeightInfo for () { fn suicide() -> Weight { (37_209_000 as Weight) } + fn remark_with_event(_b: u32, ) -> Weight { + (1_973_000 as Weight) + } } From a3b660398c2f0906e6e0c1d3aafd1fc85b713962 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Sat, 20 Feb 2021 16:56:52 +1300 Subject: [PATCH 04/10] fix --- frame/system/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index a31622a3fca08..f27cf7e3e3476 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -293,7 +293,7 @@ pub mod pallet { /// # /// - `O(1)` /// # - #[pallet::weight(T::SystemWeightInfo::remark(remark.len() as u32))] + #[pallet::weight(T::SystemWeightInfo::remark(_remark.len() as u32))] pub(crate) fn remark(origin: OriginFor, _remark: Vec) -> DispatchResultWithPostInfo { ensure_signed(origin)?; Ok(().into()) From 31bb3018e1274c23eeb2fce76c14596e10886085 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Thu, 25 Feb 2021 17:29:03 +1300 Subject: [PATCH 05/10] add origin to Remarked --- frame/system/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index f27cf7e3e3476..472639af4f86e 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -457,8 +457,8 @@ pub mod pallet { /// # #[pallet::weight(T::SystemWeightInfo::remark_with_event(remark.len() as u32))] pub(crate) fn remark_with_event(origin: OriginFor, remark: Vec) -> DispatchResultWithPostInfo { - ensure_signed(origin)?; - Self::deposit_event(Event::Remarked(remark)); + let who = ensure_signed(origin)?; + Self::deposit_event(Event::Remarked(who, remark)); Ok(().into()) } } @@ -477,8 +477,8 @@ pub mod pallet { NewAccount(T::AccountId), /// An \[account\] was reaped. KilledAccount(T::AccountId), - /// On on-chain \[remark\] happened. - Remarked(Vec), + /// On on-chain remark happened. \[origin, remark\] + Remarked(T::AccountId, Vec), } /// Old name generated by `decl_event`. From ed2940081b37b6293ef10648bdf0883ee785f127 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Thu, 25 Feb 2021 21:33:10 +1300 Subject: [PATCH 06/10] trigger CI From fab54e674242d096cd07c11eebf6e74a79286fb4 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Fri, 26 Feb 2021 22:22:10 +1300 Subject: [PATCH 07/10] emit Hash instead of remark --- frame/system/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 472639af4f86e..f1797d95edcc0 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -458,14 +458,15 @@ pub mod pallet { #[pallet::weight(T::SystemWeightInfo::remark_with_event(remark.len() as u32))] pub(crate) fn remark_with_event(origin: OriginFor, remark: Vec) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - Self::deposit_event(Event::Remarked(who, remark)); + let hash = T::Hashing::hash(&remark[..]); + Self::deposit_event(Event::Remarked(who, hash)); Ok(().into()) } } /// Event for the System pallet. #[pallet::event] - #[pallet::metadata(T::AccountId = "AccountId")] + #[pallet::metadata(T::AccountId = "AccountId", T::Hash = "Hash")] pub enum Event { /// An extrinsic completed successfully. \[info\] ExtrinsicSuccess(DispatchInfo), @@ -477,8 +478,8 @@ pub mod pallet { NewAccount(T::AccountId), /// An \[account\] was reaped. KilledAccount(T::AccountId), - /// On on-chain remark happened. \[origin, remark\] - Remarked(T::AccountId, Vec), + /// On on-chain remark happened. \[origin, remark_hash\] + Remarked(T::AccountId, T::Hash), } /// Old name generated by `decl_event`. From b83441a8caa68afb9e1939f361aacc6477a9a809 Mon Sep 17 00:00:00 2001 From: Parity Benchmarking Bot Date: Sat, 27 Feb 2021 19:53:06 +0000 Subject: [PATCH 08/10] cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=frame_system --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/system/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/system/src/weights.rs | 54 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/frame/system/src/weights.rs b/frame/system/src/weights.rs index 525bf0a068059..57007498ce4bd 100644 --- a/frame/system/src/weights.rs +++ b/frame/system/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for frame_system //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-02-23, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2021-02-27, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -45,85 +45,89 @@ use sp_std::marker::PhantomData; /// Weight functions needed for frame_system. pub trait WeightInfo { fn remark(b: u32, ) -> Weight; + fn remark_with_event(b: u32, ) -> Weight; fn set_heap_pages() -> Weight; fn set_changes_trie_config() -> Weight; fn set_storage(i: u32, ) -> Weight; fn kill_storage(i: u32, ) -> Weight; fn kill_prefix(p: u32, ) -> Weight; - fn remark_with_event(b: u32, ) -> Weight; } /// Weights for frame_system using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { +impl WeightInfo for SubstrateWeight { fn remark(_b: u32, ) -> Weight { - (1_279_000 as Weight) + (1_296_000 as Weight) + } + fn remark_with_event(b: u32, ) -> Weight { + (13_474_000 as Weight) + // Standard Error: 0 + .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) } fn set_heap_pages() -> Weight { - (2_167_000 as Weight) + (2_024_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_changes_trie_config() -> Weight { - (10_117_000 as Weight) + (10_551_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn set_storage(i: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((608_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((612_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } fn kill_storage(i: u32, ) -> Weight { - (3_199_000 as Weight) + (562_000 as Weight) // Standard Error: 0 - .saturating_add((450_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((442_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } fn kill_prefix(p: u32, ) -> Weight { - (8_966_000 as Weight) + (10_499_000 as Weight) // Standard Error: 1_000 - .saturating_add((845_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((840_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } - fn remark_with_event(_b: u32, ) -> Weight { - (1_973_000 as Weight) - } } // For backwards compatibility and tests impl WeightInfo for () { fn remark(_b: u32, ) -> Weight { - (1_279_000 as Weight) + (1_296_000 as Weight) + } + fn remark_with_event(b: u32, ) -> Weight { + (13_474_000 as Weight) + // Standard Error: 0 + .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) } fn set_heap_pages() -> Weight { - (2_167_000 as Weight) + (2_024_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn set_changes_trie_config() -> Weight { - (10_117_000 as Weight) + (10_551_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn set_storage(i: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((608_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((612_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } fn kill_storage(i: u32, ) -> Weight { - (3_199_000 as Weight) + (562_000 as Weight) // Standard Error: 0 - .saturating_add((450_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((442_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } fn kill_prefix(p: u32, ) -> Weight { - (8_966_000 as Weight) + (10_499_000 as Weight) // Standard Error: 1_000 - .saturating_add((845_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((840_000 as Weight).saturating_mul(p as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } - fn remark_with_event(_b: u32, ) -> Weight { - (1_973_000 as Weight) - } } From ab88a33bc571035ff806eb5509cd62b9fc8795f9 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Sat, 27 Feb 2021 16:15:40 -0400 Subject: [PATCH 09/10] Update frame/system/src/weights.rs --- frame/system/src/weights.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/system/src/weights.rs b/frame/system/src/weights.rs index 57007498ce4bd..c961b47e53eaf 100644 --- a/frame/system/src/weights.rs +++ b/frame/system/src/weights.rs @@ -55,7 +55,7 @@ pub trait WeightInfo { /// Weights for frame_system using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { +impl WeightInfo for SubstrateWeight { fn remark(_b: u32, ) -> Weight { (1_296_000 as Weight) } From 200d71b1f87e5dcd3d91c529992d0503b404fa4f Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Sat, 27 Feb 2021 17:43:05 -0400 Subject: [PATCH 10/10] Update frame/system/src/lib.rs --- frame/system/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index f1797d95edcc0..124c437c44bfa 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -452,7 +452,7 @@ pub mod pallet { /// Make some on-chain remark and emit event. /// /// # - /// - `O(1)` + /// - `O(b)` where b is the length of the remark. /// - 1 event. /// # #[pallet::weight(T::SystemWeightInfo::remark_with_event(remark.len() as u32))]