This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Glutton pallet #12833
Merged
Merged
Glutton pallet #12833
Changes from 12 commits
Commits
Show all changes
103 commits
Select commit
Hold shift + click to select a range
9de0eee
Pov-Limit pallet
Szegoo 7c0b552
use Perbill & fixes
Szegoo 1a50132
fixes
Szegoo 0e79cd3
reads & writes
Szegoo 24ac38a
update docs
Szegoo fa70f0f
tests
Szegoo c1ecfe4
calculate weight
Szegoo b99945d
Merge branch 'master' into pov-limit
Szegoo 25153a1
fmt
Szegoo 27868bd
benchmark
Szegoo 54f3117
logic fix
Szegoo 91178fb
naming fix
Szegoo 3565ff1
caclulate computation weight limit
Szegoo 24edc74
Merge branch 'paritytech:master' into pov-limit
Szegoo 9f48aba
make the Hasher generic
Szegoo f2abdfa
make the code compile
Szegoo 36b049c
generate weight
Szegoo 79c7816
fix on_idle
Szegoo b3f72d5
fix
Szegoo 810bcd6
Merge branch 'paritytech:master' into pov-limit
Szegoo 3f8a005
fix
Szegoo 114404f
make reading generic
Szegoo 90fe1ba
fix?
Szegoo 17ef8d2
fixes
Szegoo 28e03d7
remove warning
Szegoo bb83203
fix
Szegoo 33a5a74
hasher fix :D
Szegoo a8ee2f5
change value
Szegoo 6f1a430
test
Szegoo 60ae9e1
actual weight and expected weight are the same
Szegoo 00110cf
update
Szegoo ccdd60c
fix
Szegoo d1f7ea5
add events
Szegoo 3d05e36
remove useless line
Szegoo 9f12092
using actual hashing algorithm
Szegoo 039bc21
better readability
Szegoo b24304b
fix nits
Szegoo 980c24f
Update
ggwpez 2802eb7
Merge remote-tracking branch 'szegoo/pov-limit' into pov-limit
ggwpez 543bf11
add migration
Szegoo 06d15eb
hardcode proof_size in weights.rs
Szegoo 0faa4fe
format
Szegoo 58e64a1
fixes
Szegoo 90f8273
Fix weight
Szegoo e803cf9
Merge branch 'paritytech:master' into pov-limit
Szegoo 7ee0054
docs
Szegoo aad6d29
fix
Szegoo 932b4f7
Update frame/pov-limit/src/lib.rs
Szegoo 5733118
Update frame/pov-limit/src/lib.rs
Szegoo dc0e8fd
empty on_ilde & update weight.rs
Szegoo ea63f7f
remove migration & fix benchmark
Szegoo aa9815a
remove migration from migrations
Szegoo 93cefc2
initialize_pallet
Szegoo 91ceea9
use blake2
Szegoo f5fc362
Update frame/pov-limit/Cargo.toml
Szegoo f238762
Update frame/pov-limit/src/lib.rs
Szegoo a8f4488
Update frame/pov-limit/Cargo.toml
Szegoo c12f907
rename pallet
Szegoo 4dc6ed5
make the wasters non-generic
Szegoo 9d2c281
rename to glutton
Szegoo 630ca33
fix
Szegoo 809ef50
Merge branch 'paritytech:master' into pov-limit
Szegoo 2c8e766
small fixes & run benchmark
Szegoo c327247
increase left over ref-time in tests
Szegoo 6e4e2c9
Update frame/glutton/src/lib.rs
Szegoo e105481
or values
Szegoo 1c41c68
fix
Szegoo 7a59fea
generate weight
Szegoo fb73955
Update frame/glutton/Cargo.toml
Szegoo 895d439
fix nits
Szegoo 177f605
Adjustments
ggwpez 046c8a1
Fixes
ggwpez daa7c1a
fix
Szegoo 7ddb68e
Update weights
ggwpez 5e622e5
Tweak constants
ggwpez 7e212ed
Update weights
ggwpez 2610b20
remove genesis config
Szegoo 257d29b
passing tests
Szegoo b65902b
More precise results
ggwpez 80202f8
update node-executor test
Szegoo 9c3b5df
Calculate number of iterations in advance
ggwpez 323c365
increase criteria
Szegoo 154c3d7
Final fixes
ggwpez 6834abf
Update frame/glutton/src/tests.rs
Szegoo a42b1d2
Update frame/glutton/src/lib.rs
Szegoo 98a237a
Update frame/glutton/src/lib.rs
Szegoo f6903a7
fix typos
Szegoo 861de1e
Update frame/glutton/src/lib.rs
Szegoo b335d3a
Update frame/glutton/src/lib.rs
Szegoo f88b946
expand/shrink
Szegoo 0fc53d9
fmt
Szegoo f944813
Revert "Update frame/glutton/src/lib.rs"
ggwpez 889c90f
Use CountedStorageMap
ggwpez 99a9774
Add benchmark
ggwpez ad687d3
Use manual map counter
ggwpez fb973bb
Merge remote-tracking branch 'origin/master' into pov-limit
ggwpez 2869993
Use new template
ggwpez 502240d
Doc+typos
ggwpez af6b3e4
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_glutton
2c8b112
Apply suggestions from code review
ggwpez 0db5a70
Add minimal README
ggwpez 62f2d8d
Merge remote-tracking branch 'origin/master' into pov-limit
f27c73b
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_glutton
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[package] | ||
name = "pallet-pov-limit" | ||
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 nick management" | ||
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
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"] } | ||
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", 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 = [ | ||
"codec/std", | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/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,6 @@ | ||
# Pov Limit Pallet | ||
|
||
Pallet that controls compute usage and PoV size usage. The parameters for | ||
the usage are configured by root and are stored as `StorageValue`s. | ||
|
||
NOTE: This is only meant to be used for testing. |
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,35 @@ | ||
// 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. | ||
|
||
//! Pov-limit pallet benchmarking. | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
use super::*; | ||
|
||
use frame_benchmarking::benchmarks; | ||
|
||
use crate::Pallet as PovLimit; | ||
|
||
benchmarks! { | ||
hash_value { | ||
|
||
}: { | ||
PovLimit::<T>::hash_value(1u64); | ||
} | ||
|
||
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
impl_benchmark_test_suite!(PovLimit, crate::mock::new_test_ext(), crate::mock::Test); | ||
} |
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,150 @@ | ||
// 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. | ||
|
||
//! # Pov Limit Pallet | ||
//! | ||
//! Pallet that controls compute usage and PoV size usage. The parameters for | ||
//! the usage are configured by root and are stored as `StorageValue`s. | ||
//! | ||
//! NOTE: This is only meant to be used for testing. | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
mod benchmarking; | ||
#[cfg(test)] | ||
mod mock; | ||
#[cfg(test)] | ||
mod tests; | ||
pub mod weights; | ||
|
||
use frame_support::{pallet_prelude::*, traits::GenesisBuild}; | ||
use sp_core::{Blake2Hasher, Hasher}; | ||
use sp_runtime::Perbill; | ||
|
||
pub use pallet::*; | ||
pub use weights::WeightInfo; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
/// The number of times the hash function should be called to fill up | ||
/// all the block's weight. | ||
#[pallet::constant] | ||
type HashesForFull: Get<u32>; | ||
|
||
/// Weight information for this pallet. | ||
type WeightInfo: WeightInfo; | ||
} | ||
|
||
#[pallet::pallet] | ||
#[pallet::generate_store(pub(super) trait Store)] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::storage] | ||
pub(crate) type Compute<T: Config> = StorageValue<_, Perbill, ValueQuery>; | ||
|
||
#[pallet::storage] | ||
pub(crate) type Storage<T: Config> = StorageValue<_, u32, ValueQuery>; | ||
|
||
#[pallet::genesis_config] | ||
pub struct GenesisConfig { | ||
pub compute: Perbill, | ||
pub storage: u32, | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl Default for GenesisConfig { | ||
fn default() -> Self { | ||
Self { compute: Default::default(), storage: Default::default() } | ||
} | ||
} | ||
|
||
#[pallet::genesis_build] | ||
impl<T: Config> GenesisBuild<T> for GenesisConfig { | ||
fn build(&self) { | ||
Compute::<T>::set(self.compute); | ||
Storage::<T>::set(self.storage); | ||
} | ||
} | ||
|
||
#[pallet::hooks] | ||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { | ||
fn on_idle(_: BlockNumberFor<T>, remaining_weight: Weight) -> Weight { | ||
let mut weight = T::DbWeight::get().reads(1); | ||
|
||
for i in 0..(Compute::<T>::get().mul_ceil(T::HashesForFull::get())) { | ||
weight.saturating_add(T::WeightInfo::hash_value()); | ||
if remaining_weight.any_lt(weight) { | ||
weight = remaining_weight; | ||
break | ||
} | ||
Self::hash_value(i.into()); | ||
} | ||
|
||
for i in 0..Storage::<T>::get() { | ||
weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); | ||
if remaining_weight.any_lt(weight) { | ||
weight = remaining_weight; | ||
break | ||
} | ||
|
||
storage::unhashed::put(&i.to_le_bytes(), &i.to_le_bytes()); | ||
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let _: Option<Vec<u8>> = storage::unhashed::get(&i.to_le_bytes()); | ||
} | ||
|
||
weight | ||
} | ||
} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
/// Set the `Compute` storage value that determines how much of the | ||
/// block's weight to use during `on_initialize`. | ||
/// | ||
/// Only callable by Root. | ||
#[pallet::weight(T::DbWeight::get().writes(1))] | ||
pub fn set_compute(origin: OriginFor<T>, compute: Perbill) -> DispatchResult { | ||
let _ = ensure_root(origin)?; | ||
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Compute::<T>::set(compute); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Set the `Storage` storage value that determines the PoV size usage | ||
/// for each block. | ||
/// | ||
/// Only callable by Root. | ||
#[pallet::weight(T::DbWeight::get().writes(1))] | ||
pub fn set_storage(origin: OriginFor<T>, storage: u32) -> DispatchResult { | ||
let _ = ensure_root(origin)?; | ||
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Storage::<T>::set(storage); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn hash_value(value: u64) { | ||
Blake2Hasher::hash(&value.to_le_bytes()); | ||
} | ||
} | ||
} |
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,84 @@ | ||
// 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. | ||
|
||
use super::*; | ||
use crate as pallet_pov_limit; | ||
|
||
use frame_support::traits::{ConstU32, ConstU64}; | ||
use sp_core::H256; | ||
use sp_runtime::{ | ||
testing::Header, | ||
traits::{BlakeTwo256, IdentityLookup}, | ||
}; | ||
|
||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>; | ||
type Block = frame_system::mocking::MockBlock<Test>; | ||
|
||
frame_support::construct_runtime!( | ||
pub enum Test where | ||
Block = Block, | ||
NodeBlock = Block, | ||
UncheckedExtrinsic = UncheckedExtrinsic, | ||
{ | ||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, | ||
PovLimit: pallet_pov_limit::{Pallet}, | ||
} | ||
); | ||
|
||
impl frame_system::Config for Test { | ||
type BaseCallFilter = frame_support::traits::Everything; | ||
type BlockWeights = (); | ||
type BlockLength = (); | ||
type DbWeight = (); | ||
type RuntimeOrigin = RuntimeOrigin; | ||
type Index = u64; | ||
type BlockNumber = u64; | ||
type Hash = H256; | ||
type RuntimeCall = RuntimeCall; | ||
type Hashing = BlakeTwo256; | ||
type AccountId = u64; | ||
type Lookup = IdentityLookup<Self::AccountId>; | ||
type Header = Header; | ||
type RuntimeEvent = RuntimeEvent; | ||
type BlockHashCount = ConstU64<250>; | ||
type Version = (); | ||
type PalletInfo = PalletInfo; | ||
type AccountData = pallet_balances::AccountData<u64>; | ||
type OnNewAccount = (); | ||
type OnKilledAccount = (); | ||
type SystemWeightInfo = (); | ||
type SS58Prefix = (); | ||
type OnSetCode = (); | ||
type MaxConsumers = ConstU32<16>; | ||
} | ||
|
||
impl Config for Test { | ||
type HashesForFull = ConstU32<1000000>; | ||
type WeightInfo = crate::weights::SubstrateWeight<Test>; | ||
} | ||
|
||
pub fn new_test_ext() -> sp_io::TestExternalities { | ||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap(); | ||
|
||
let genesis = pallet::GenesisConfig { compute: Perbill::from_percent(50), storage: 10000 }; | ||
|
||
GenesisBuild::<Test>::assimilate_storage(&genesis, &mut t).unwrap(); | ||
|
||
let mut ext = sp_io::TestExternalities::new(t); | ||
ext.execute_with(|| System::set_block_number(1)); | ||
ext | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe to be more generic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could even use an actual name, like glutton or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds funny :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should I rename this to
pallet-glutton
then? Would the parachains that will run the code from this pallet be called glutton parachains? :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually quite like "Glutton Parachains". It has the double meaning of one who over-consumes (the parachain), but also one who relishes in enduring something (i.e. "glutton for punishment"), and it is seeing how much validators can endure from parachains.
I also didn't know this before but it's another name for wolverines (https://en.wikipedia.org/wiki/Wolverine), so it can have a nice logo :).