Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Glutton pallet #12833

Merged
merged 103 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
9de0eee
Pov-Limit pallet
Szegoo Dec 3, 2022
7c0b552
use Perbill & fixes
Szegoo Dec 6, 2022
1a50132
fixes
Szegoo Dec 6, 2022
0e79cd3
reads & writes
Szegoo Dec 6, 2022
24ac38a
update docs
Szegoo Dec 6, 2022
fa70f0f
tests
Szegoo Dec 6, 2022
c1ecfe4
calculate weight
Szegoo Dec 7, 2022
b99945d
Merge branch 'master' into pov-limit
Szegoo Dec 7, 2022
25153a1
fmt
Szegoo Dec 8, 2022
27868bd
benchmark
Szegoo Dec 8, 2022
54f3117
logic fix
Szegoo Dec 8, 2022
91178fb
naming fix
Szegoo Dec 8, 2022
3565ff1
caclulate computation weight limit
Szegoo Dec 13, 2022
24edc74
Merge branch 'paritytech:master' into pov-limit
Szegoo Dec 13, 2022
9f48aba
make the Hasher generic
Szegoo Dec 13, 2022
f2abdfa
make the code compile
Szegoo Dec 13, 2022
36b049c
generate weight
Szegoo Dec 13, 2022
79c7816
fix on_idle
Szegoo Dec 14, 2022
b3f72d5
fix
Szegoo Dec 14, 2022
810bcd6
Merge branch 'paritytech:master' into pov-limit
Szegoo Dec 15, 2022
3f8a005
fix
Szegoo Dec 15, 2022
114404f
make reading generic
Szegoo Dec 15, 2022
90fe1ba
fix?
Szegoo Dec 15, 2022
17ef8d2
fixes
Szegoo Dec 16, 2022
28e03d7
remove warning
Szegoo Dec 16, 2022
bb83203
fix
Szegoo Dec 16, 2022
33a5a74
hasher fix :D
Szegoo Dec 16, 2022
a8ee2f5
change value
Szegoo Dec 16, 2022
6f1a430
test
Szegoo Dec 16, 2022
60ae9e1
actual weight and expected weight are the same
Szegoo Dec 18, 2022
00110cf
update
Szegoo Dec 18, 2022
ccdd60c
fix
Szegoo Dec 18, 2022
d1f7ea5
add events
Szegoo Dec 18, 2022
3d05e36
remove useless line
Szegoo Dec 18, 2022
9f12092
using actual hashing algorithm
Szegoo Dec 20, 2022
039bc21
better readability
Szegoo Dec 21, 2022
b24304b
fix nits
Szegoo Dec 21, 2022
980c24f
Update
ggwpez Dec 21, 2022
2802eb7
Merge remote-tracking branch 'szegoo/pov-limit' into pov-limit
ggwpez Dec 21, 2022
543bf11
add migration
Szegoo Dec 21, 2022
06d15eb
hardcode proof_size in weights.rs
Szegoo Dec 22, 2022
0faa4fe
format
Szegoo Dec 22, 2022
58e64a1
fixes
Szegoo Dec 22, 2022
90f8273
Fix weight
Szegoo Dec 22, 2022
e803cf9
Merge branch 'paritytech:master' into pov-limit
Szegoo Dec 29, 2022
7ee0054
docs
Szegoo Jan 1, 2023
aad6d29
fix
Szegoo Jan 1, 2023
932b4f7
Update frame/pov-limit/src/lib.rs
Szegoo Jan 3, 2023
5733118
Update frame/pov-limit/src/lib.rs
Szegoo Jan 3, 2023
dc0e8fd
empty on_ilde & update weight.rs
Szegoo Jan 3, 2023
ea63f7f
remove migration & fix benchmark
Szegoo Jan 3, 2023
aa9815a
remove migration from migrations
Szegoo Jan 3, 2023
93cefc2
initialize_pallet
Szegoo Jan 3, 2023
91ceea9
use blake2
Szegoo Jan 4, 2023
f5fc362
Update frame/pov-limit/Cargo.toml
Szegoo Jan 13, 2023
f238762
Update frame/pov-limit/src/lib.rs
Szegoo Jan 13, 2023
a8f4488
Update frame/pov-limit/Cargo.toml
Szegoo Jan 13, 2023
c12f907
rename pallet
Szegoo Jan 13, 2023
4dc6ed5
make the wasters non-generic
Szegoo Jan 13, 2023
9d2c281
rename to glutton
Szegoo Jan 13, 2023
630ca33
fix
Szegoo Jan 13, 2023
809ef50
Merge branch 'paritytech:master' into pov-limit
Szegoo Jan 27, 2023
2c8e766
small fixes & run benchmark
Szegoo Jan 27, 2023
c327247
increase left over ref-time in tests
Szegoo Jan 27, 2023
6e4e2c9
Update frame/glutton/src/lib.rs
Szegoo Feb 11, 2023
e105481
or values
Szegoo Feb 11, 2023
1c41c68
fix
Szegoo Feb 11, 2023
7a59fea
generate weight
Szegoo Feb 11, 2023
fb73955
Update frame/glutton/Cargo.toml
Szegoo Feb 14, 2023
895d439
fix nits
Szegoo Feb 14, 2023
177f605
Adjustments
ggwpez Feb 14, 2023
046c8a1
Fixes
ggwpez Feb 14, 2023
daa7c1a
fix
Szegoo Feb 15, 2023
7ddb68e
Update weights
ggwpez Feb 15, 2023
5e622e5
Tweak constants
ggwpez Feb 15, 2023
7e212ed
Update weights
ggwpez Feb 15, 2023
2610b20
remove genesis config
Szegoo Feb 16, 2023
257d29b
passing tests
Szegoo Feb 16, 2023
b65902b
More precise results
ggwpez Feb 16, 2023
80202f8
update node-executor test
Szegoo Feb 16, 2023
9c3b5df
Calculate number of iterations in advance
ggwpez Feb 17, 2023
323c365
increase criteria
Szegoo Feb 17, 2023
154c3d7
Final fixes
ggwpez Feb 17, 2023
6834abf
Update frame/glutton/src/tests.rs
Szegoo Feb 17, 2023
a42b1d2
Update frame/glutton/src/lib.rs
Szegoo Feb 17, 2023
98a237a
Update frame/glutton/src/lib.rs
Szegoo Feb 17, 2023
f6903a7
fix typos
Szegoo Feb 17, 2023
861de1e
Update frame/glutton/src/lib.rs
Szegoo Feb 17, 2023
b335d3a
Update frame/glutton/src/lib.rs
Szegoo Feb 17, 2023
f88b946
expand/shrink
Szegoo Feb 17, 2023
0fc53d9
fmt
Szegoo Feb 17, 2023
f944813
Revert "Update frame/glutton/src/lib.rs"
ggwpez Feb 19, 2023
889c90f
Use CountedStorageMap
ggwpez Feb 19, 2023
99a9774
Add benchmark
ggwpez Feb 19, 2023
ad687d3
Use manual map counter
ggwpez Feb 20, 2023
fb973bb
Merge remote-tracking branch 'origin/master' into pov-limit
ggwpez Feb 20, 2023
2869993
Use new template
ggwpez Feb 20, 2023
502240d
Doc+typos
ggwpez Feb 20, 2023
af6b3e4
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_glutton
Feb 20, 2023
2c8b112
Apply suggestions from code review
ggwpez Feb 20, 2023
0db5a70
Add minimal README
ggwpez Feb 20, 2023
62f2d8d
Merge remote-tracking branch 'origin/master' into pov-limit
Feb 20, 2023
f27c73b
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_glutton
Feb 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ members = [
"frame/uniques",
"frame/utility",
"frame/vesting",
"frame/glutton",
"frame/whitelist",
"primitives/api",
"primitives/api/proc-macro",
Expand Down
1 change: 1 addition & 0 deletions bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ node-testing = { version = "3.0.0-dev", path = "../testing" }
pallet-balances = { version = "4.0.0-dev", path = "../../../frame/balances" }
pallet-contracts = { version = "4.0.0-dev", path = "../../../frame/contracts" }
pallet-im-online = { version = "4.0.0-dev", path = "../../../frame/im-online" }
pallet-glutton = { version = "4.0.0-dev", path = "../../../frame/glutton" }
pallet-sudo = { version = "4.0.0-dev", path = "../../../frame/sudo" }
pallet-timestamp = { version = "4.0.0-dev", path = "../../../frame/timestamp" }
pallet-treasury = { version = "4.0.0-dev", path = "../../../frame/treasury" }
Expand Down
4 changes: 4 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pallet-nomination-pools-benchmarking = { version = "1.0.0", default-features = f
pallet-nomination-pools-runtime-api = { version = "1.0.0-dev", default-features = false, path = "../../../frame/nomination-pools/runtime-api" }
pallet-offences = { version = "4.0.0-dev", default-features = false, path = "../../../frame/offences" }
pallet-offences-benchmarking = { version = "4.0.0-dev", path = "../../../frame/offences/benchmarking", default-features = false, optional = true }
pallet-glutton = { version = "4.0.0-dev", default-features = false, path = "../../../frame/glutton" }
pallet-preimage = { version = "4.0.0-dev", default-features = false, path = "../../../frame/preimage" }
pallet-proxy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/proxy" }
pallet-insecure-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, path = "../../../frame/insecure-randomness-collective-flip" }
Expand Down Expand Up @@ -164,6 +165,7 @@ std = [
"node-primitives/std",
"sp-offchain/std",
"pallet-offences/std",
"pallet-glutton/std",
"pallet-preimage/std",
"pallet-proxy/std",
"sp-core/std",
Expand Down Expand Up @@ -242,6 +244,7 @@ runtime-benchmarks = [
"pallet-multisig/runtime-benchmarks",
"pallet-nomination-pools-benchmarking/runtime-benchmarks",
"pallet-offences-benchmarking/runtime-benchmarks",
"pallet-glutton/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
Expand Down Expand Up @@ -298,6 +301,7 @@ try-runtime = [
"pallet-multisig/try-runtime",
"pallet-nomination-pools/try-runtime",
"pallet-offences/try-runtime",
"pallet-glutton/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-insecure-randomness-collective-flip/try-runtime",
Expand Down
7 changes: 7 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ impl pallet_scheduler::Config for Runtime {
type Preimages = Preimage;
}

impl pallet_glutton::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_glutton::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const PreimageMaxSize: u32 = 4096 * 1024;
pub const PreimageBaseDeposit: Balance = 1 * DOLLARS;
Expand Down Expand Up @@ -1747,6 +1752,7 @@ construct_runtime!(
Recovery: pallet_recovery,
Vesting: pallet_vesting,
Scheduler: pallet_scheduler,
Glutton: pallet_glutton,
Preimage: pallet_preimage,
Proxy: pallet_proxy,
Multisig: pallet_multisig,
Expand Down Expand Up @@ -1878,6 +1884,7 @@ mod benches {
[pallet_recovery, Recovery]
[pallet_remark, Remark]
[pallet_scheduler, Scheduler]
[pallet_glutton, Glutton]
[pallet_session, SessionBench::<Runtime>]
[pallet_staking, Staking]
[pallet_state_trie_migration, StateTrieMigration]
Expand Down
51 changes: 51 additions & 0 deletions frame/glutton/Cargo.toml
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 <admin@parity.io>"]
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",
]
9 changes: 9 additions & 0 deletions frame/glutton/README.md
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`.
98 changes: 98 additions & 0 deletions frame/glutton/src/benchmarking.rs
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);
}
Loading