forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Pov-Limit pallet * use Perbill & fixes * fixes * reads & writes * update docs * tests * calculate weight * fmt * benchmark * logic fix * naming fix * caclulate computation weight limit * make the Hasher generic * make the code compile * generate weight * fix on_idle * fix * fix * make reading generic * fix? * fixes * remove warning * fix * hasher fix :D * change value * test * actual weight and expected weight are the same * update * fix * add events * remove useless line * using actual hashing algorithm * better readability * fix nits * Update Signed-off-by: Oliver Tale-Yazdi <[email protected]> * add migration * hardcode proof_size in weights.rs * format * fixes * Fix weight * docs * fix * Update frame/pov-limit/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/pov-limit/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * empty on_ilde & update weight.rs * remove migration & fix benchmark * remove migration from migrations * initialize_pallet * use blake2 * Update frame/pov-limit/Cargo.toml Co-authored-by: Bastian Köcher <[email protected]> * Update frame/pov-limit/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/pov-limit/Cargo.toml Co-authored-by: Bastian Köcher <[email protected]> * rename pallet * make the wasters non-generic * rename to glutton * fix * small fixes & run benchmark * increase left over ref-time in tests * Update frame/glutton/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * or values * fix * generate weight * Update frame/glutton/Cargo.toml Co-authored-by: Oliver Tale-Yazdi <[email protected]> * fix nits * Adjustments Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * fix * Update weights Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Tweak constants Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Update weights Signed-off-by: Oliver Tale-Yazdi <[email protected]> * remove genesis config * passing tests * More precise results Signed-off-by: Oliver Tale-Yazdi <[email protected]> * update node-executor test * Calculate number of iterations in advance Signed-off-by: Oliver Tale-Yazdi <[email protected]> * increase criteria * Final fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Update frame/glutton/src/tests.rs Co-authored-by: Kian Paimani <[email protected]> * Update frame/glutton/src/lib.rs Co-authored-by: Kian Paimani <[email protected]> * Update frame/glutton/src/lib.rs Co-authored-by: Kian Paimani <[email protected]> * fix typos * Update frame/glutton/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/glutton/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * expand/shrink * fmt * Revert "Update frame/glutton/src/lib.rs" This reverts commit 98a237a. Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Use CountedStorageMap Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add benchmark Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Use manual map counter Something with the R/W count in the benchmarking result did not add up. Need to investigate but for now just using a manual counter. Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Use new template Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Doc+typos Signed-off-by: Oliver Tale-Yazdi <[email protected]> * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_glutton * Apply suggestions from code review Co-authored-by: Koute <[email protected]> * Add minimal README Signed-off-by: Oliver Tale-Yazdi <[email protected]> * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_glutton --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Koute <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,113 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[package] | ||
name = "pallet-glutton" | ||
version = "4.0.0-dev" | ||
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
homepage = "https://substrate.io" | ||
repository = "https://github.com/paritytech/substrate/" | ||
description = "FRAME pallet for pushing a chain to its weight limits" | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
blake2 = { version = "0.10.4", default-features = false } | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } | ||
log = { version = "0.4.14", default-features = false } | ||
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" } | ||
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } | ||
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } | ||
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" } | ||
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" } | ||
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" } | ||
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" } | ||
|
||
[dev-dependencies] | ||
pallet-balances = { version = "4.0.0-dev", path = "../balances" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"blake2/std", | ||
"codec/std", | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
] | ||
try-runtime = ["frame-support/try-runtime"] | ||
|
||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# WARNING | ||
|
||
Do not use on value-bearing chains. This pallet is **only** intended for usage on test-chains. | ||
|
||
# Glutton Pallet | ||
|
||
The `Glutton` pallet gets the name from its property to consume vast amounts of resources. It can be used to push para-chains and their relay-chains to the limits. This is good for testing out theoretical limits in a practical way. | ||
|
||
The `Glutton` can be set to consume a fraction of the available unused weight of a chain. It accomplishes this by utilizing the `on_idle` hook and consuming a specific ration of the remaining weight. The rations can be set via `set_compute` and `set_storage`. Initially the `Glutton` needs to be initialized once with `initialize_pallet`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Glutton pallet benchmarking. | ||
//! | ||
//! Has to be compiled and run twice to calibrate on new hardware. | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
use super::*; | ||
|
||
use frame_benchmarking::benchmarks; | ||
use frame_support::{pallet_prelude::*, weights::constants::*}; | ||
use frame_system::RawOrigin as SystemOrigin; | ||
|
||
use crate::Pallet as Glutton; | ||
use frame_system::Pallet as System; | ||
|
||
benchmarks! { | ||
initialize_pallet_grow { | ||
let n in 0 .. 1_000; | ||
}: { | ||
Glutton::<T>::initialize_pallet(SystemOrigin::Root.into(), n, None).unwrap() | ||
} verify { | ||
assert_eq!(TrashDataCount::<T>::get(), n); | ||
} | ||
|
||
initialize_pallet_shrink { | ||
let n in 0 .. 1_000; | ||
|
||
Glutton::<T>::initialize_pallet(SystemOrigin::Root.into(), n, None).unwrap(); | ||
}: { | ||
Glutton::<T>::initialize_pallet(SystemOrigin::Root.into(), 0, Some(n)).unwrap() | ||
} verify { | ||
assert_eq!(TrashDataCount::<T>::get(), 0); | ||
} | ||
|
||
waste_ref_time_iter { | ||
let i in 0..100_000; | ||
}: { | ||
Glutton::<T>::waste_ref_time_iter(vec![0u8; 64], i); | ||
} | ||
|
||
waste_proof_size_some { | ||
let i in 0..5_000; | ||
|
||
(0..5000).for_each(|i| TrashData::<T>::insert(i, [i as u8; 1024])); | ||
}: { | ||
(0..i).for_each(|i| { | ||
TrashData::<T>::get(i); | ||
}) | ||
} | ||
|
||
// For manual verification only. | ||
on_idle_high_proof_waste { | ||
(0..5000).for_each(|i| TrashData::<T>::insert(i, [i as u8; 1024])); | ||
let _ = Glutton::<T>::set_compute(SystemOrigin::Root.into(), Perbill::from_percent(100)); | ||
let _ = Glutton::<T>::set_storage(SystemOrigin::Root.into(), Perbill::from_percent(100)); | ||
}: { | ||
let weight = Glutton::<T>::on_idle(System::<T>::block_number(), Weight::from_parts(WEIGHT_REF_TIME_PER_MILLIS * 100, WEIGHT_PROOF_SIZE_PER_MB * 5)); | ||
} | ||
|
||
// For manual verification only. | ||
on_idle_low_proof_waste { | ||
(0..5000).for_each(|i| TrashData::<T>::insert(i, [i as u8; 1024])); | ||
let _ = Glutton::<T>::set_compute(SystemOrigin::Root.into(), Perbill::from_percent(100)); | ||
let _ = Glutton::<T>::set_storage(SystemOrigin::Root.into(), Perbill::from_percent(100)); | ||
}: { | ||
let weight = Glutton::<T>::on_idle(System::<T>::block_number(), Weight::from_parts(WEIGHT_REF_TIME_PER_MILLIS * 100, WEIGHT_PROOF_SIZE_PER_KB * 20)); | ||
} | ||
|
||
empty_on_idle { | ||
}: { | ||
// Enough weight do do nothing. | ||
Glutton::<T>::on_idle(System::<T>::block_number(), T::WeightInfo::empty_on_idle()); | ||
} | ||
|
||
set_compute { | ||
}: _(SystemOrigin::Root, Perbill::from_percent(50)) | ||
|
||
set_storage { | ||
}: _(SystemOrigin::Root, Perbill::from_percent(50)) | ||
|
||
impl_benchmark_test_suite!(Glutton, crate::mock::new_test_ext(), crate::mock::Test); | ||
} |
Oops, something went wrong.