-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New root_testing pallet
#12451
New root_testing pallet
#12451
Changes from 25 commits
aae3ad4
fae1f2f
450b02f
dd5be15
31957e7
85de51f
796b021
6dc4371
10654bc
afb0518
b8e7c21
346070b
f7ca099
95d734b
76c01ec
97cd12c
667b5da
5c46eff
6356478
3ad36d1
6e37379
0780410
a52b05e
9099a55
62e4f83
370f46e
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| [package] | ||
| name = "pallet-root-offences" | ||
| version = "1.0.0" | ||
| version = "1.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 root offences pallet" | ||
| readme = "README.md" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
@@ -17,11 +18,10 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive" | |
|
|
||
| pallet-session = { version = "4.0.0-dev", features = [ "historical" ], path = "../../frame/session", default-features = false } | ||
| pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../../frame/staking" } | ||
| pallet-offences = { version = "4.0.0-dev", default-features = false, path = "../../frame/offences" } | ||
|
|
||
| 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-runtime = { version = "6.0.0", path = "../../primitives/runtime" } | ||
| sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } | ||
| sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } | ||
|
|
||
| [dev-dependencies] | ||
|
|
@@ -45,7 +45,6 @@ std = [ | |
| "frame-system/std", | ||
| "pallet-session/std", | ||
| "pallet-staking/std", | ||
| "pallet-offences/std", | ||
| "scale-info/std", | ||
| "sp-runtime/std", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Sudo Offences Pallet | ||
| # Root Offences Pallet | ||
|
|
||
| Pallet that allows the root to create an offence. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| [package] | ||
| name = "pallet-root-testing" | ||
| version = "1.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 root testing pallet" | ||
| 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-support = { version = "4.0.0-dev", default-features = false, path = "../support" } | ||
| frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } | ||
| sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } | ||
|
|
||
| [dev-dependencies] | ||
|
|
||
| [features] | ||
| try-runtime = ["frame-support/try-runtime"] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "scale-info/std", | ||
| "sp-runtime/std", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Root Testing Pallet | ||
|
|
||
| Pallet that contains extrinsics that can be usefull in testing. | ||
|
|
||
| NOTE: This pallet should only be used for testing purposes and should not be used in production runtimes! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // 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. | ||
|
|
||
| //! # Root Testing Pallet | ||
| //! | ||
| //! Pallet that contains extrinsics that can be usefull in testing. | ||
| //! | ||
| //! NOTE: This pallet should only be used for testing purposes and should not be used in production | ||
| //! runtimes! | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| use frame_support::dispatch::DispatchResult; | ||
| use sp_runtime::Perbill; | ||
|
|
||
| pub use pallet::*; | ||
|
|
||
| #[frame_support::pallet] | ||
| pub mod pallet { | ||
| use super::*; | ||
| use frame_support::pallet_prelude::*; | ||
| use frame_system::pallet_prelude::*; | ||
|
|
||
| #[pallet::config] | ||
| pub trait Config: frame_system::Config {} | ||
|
|
||
| #[pallet::pallet] | ||
| #[pallet::generate_store(pub(super) trait Store)] | ||
| pub struct Pallet<T>(_); | ||
|
|
||
| #[pallet::call] | ||
| impl<T: Config> Pallet<T> { | ||
| /// A dispatch that will fill the block weight up to the given ratio. | ||
| #[pallet::weight(*_ratio * T::BlockWeights::get().max_block)] | ||
| pub fn fill_block(origin: OriginFor<T>, _ratio: Perbill) -> DispatchResult { | ||
| ensure_root(origin)?; | ||
| Ok(()) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,7 +197,6 @@ impl<MaxNormal: Get<u32>, MaxOverflow: Get<u32>> ConsumerLimits for (MaxNormal, | |
| pub mod pallet { | ||
| use crate::{self as frame_system, pallet_prelude::*, *}; | ||
| use frame_support::pallet_prelude::*; | ||
| use sp_runtime::DispatchErrorWithPostInfo; | ||
|
|
||
| /// System configuration trait. Implemented by runtime. | ||
| #[pallet::config] | ||
|
|
@@ -370,23 +369,6 @@ pub mod pallet { | |
|
|
||
| #[pallet::call] | ||
| impl<T: Config> Pallet<T> { | ||
| /// A dispatch that will fill the block weight up to the given ratio. | ||
| // TODO: This should only be available for testing, rather than in general usage, but | ||
| // that's not possible at present (since it's within the pallet macro). | ||
| #[pallet::weight(*_ratio * T::BlockWeights::get().max_block)] | ||
| pub fn fill_block(origin: OriginFor<T>, _ratio: Perbill) -> DispatchResultWithPostInfo { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks transaction version.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would that call look like? Or could there be a more elegant solution to this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall there were some discussion about specify call index to avoid this kind of issue but can't find it anymore. That will be the proper solution. For now, maybe just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xlc do we even need
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need the argument. @xlc is this a big deal though? most apps should handle this dynamically. For others, in any case, almost all releases contain a tx-version breaking change (bth we are not even bumping it strictly). I would say let's break it and move on.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kianenigma I removed the dummy call then. |
||
| match ensure_root(origin) { | ||
| Ok(_) => Ok(().into()), | ||
| Err(_) => { | ||
| // roughly same as a 4 byte remark since perbill is u32. | ||
| Err(DispatchErrorWithPostInfo { | ||
| post_info: Some(T::SystemWeightInfo::remark(4u32)).into(), | ||
| error: DispatchError::BadOrigin, | ||
| }) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| /// Make some on-chain remark. | ||
| /// | ||
| /// # <weight> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.