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

New root_testing pallet #12451

Merged
merged 26 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 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 bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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" }
pallet-transaction-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment" }
pallet-root-offences = { version = "1.0.0-dev", path = "../../../frame/root-offences" }
sp-application-crypto = { version = "6.0.0", path = "../../../primitives/application-crypto" }
sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" }
sp-externalities = { version = "0.12.0", path = "../../../primitives/externalities" }
Expand Down
4 changes: 2 additions & 2 deletions bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(0, 0))),
function: RuntimeCall::Sudo(pallet_sudo::Call::sudo {
call: Box::new(RuntimeCall::System(frame_system::Call::fill_block {
call: RuntimeCall::RootOffences(pallet_root_offences::Call::fill_block {
ratio: Perbill::from_percent(60),
})),
}),
}),
},
],
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 @@ -89,6 +89,7 @@ pallet-ranked-collective = { version = "4.0.0-dev", default-features = false, pa
pallet-recovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/recovery" }
pallet-referenda = { version = "4.0.0-dev", default-features = false, path = "../../../frame/referenda" }
pallet-remark = { version = "4.0.0-dev", default-features = false, path = "../../../frame/remark" }
pallet-root-offences = { version = "1.0.0-dev", default-features = false, path = "../../../frame/root-offences" }
pallet-session = { version = "4.0.0-dev", features = [ "historical" ], path = "../../../frame/session", default-features = false }
pallet-session-benchmarking = { version = "4.0.0-dev", path = "../../../frame/session/benchmarking", default-features = false, optional = true }
pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking" }
Expand Down Expand Up @@ -192,6 +193,7 @@ std = [
"pallet-ranked-collective/std",
"pallet-referenda/std",
"pallet-remark/std",
"pallet-root-offences/std",
"pallet-recovery/std",
"pallet-uniques/std",
"pallet-vesting/std",
Expand Down Expand Up @@ -239,6 +241,7 @@ runtime-benchmarks = [
"pallet-referenda/runtime-benchmarks",
"pallet-recovery/runtime-benchmarks",
"pallet-remark/runtime-benchmarks",
"pallet-root-offences/runtime-benchmarks",
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
Expand Down Expand Up @@ -292,6 +295,7 @@ try-runtime = [
"pallet-recovery/try-runtime",
"pallet-referenda/try-runtime",
"pallet-remark/try-runtime",
"pallet-root-offences/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
"pallet-state-trie-migration/try-runtime",
Expand Down
6 changes: 6 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,10 @@ impl pallet_remark::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

impl pallet_root_offences::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
Expand Down Expand Up @@ -1659,6 +1663,7 @@ construct_runtime!(
ChildBounties: pallet_child_bounties,
Referenda: pallet_referenda,
Remark: pallet_remark,
RootOffences: pallet_root_offences,
ConvictionVoting: pallet_conviction_voting,
Whitelist: pallet_whitelist,
AllianceMotion: pallet_collective::<Instance3>,
Expand Down Expand Up @@ -1771,6 +1776,7 @@ mod benches {
[pallet_referenda, Referenda]
[pallet_recovery, Recovery]
[pallet_remark, Remark]
[pallet_root_offences, RootOffences]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_staking, Staking]
Expand Down
5 changes: 2 additions & 3 deletions frame/root-offences/Cargo.toml
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"]
Expand All @@ -17,7 +18,6 @@ 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" }
Expand Down Expand Up @@ -45,7 +45,6 @@ std = [
"frame-system/std",
"pallet-session/std",
"pallet-staking/std",
"pallet-offences/std",
"scale-info/std",
"sp-runtime/std",
]
2 changes: 1 addition & 1 deletion frame/root-offences/README.md
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.

Expand Down
22 changes: 21 additions & 1 deletion frame/root-offences/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Sudo Offences Pallet
//! # Root Offences Pallet
//! Pallet that allows the root to create an offence.
//!
//! NOTE: This pallet should be used for testing purposes.
Expand All @@ -27,6 +27,8 @@ mod mock;
#[cfg(test)]
mod tests;

use frame_support::dispatch::DispatchErrorWithPostInfo;
use frame_system::WeightInfo;
use pallet_session::historical::IdentificationTuple;
use pallet_staking::{BalanceOf, Exposure, ExposureOf, Pallet as Staking};
use sp_runtime::Perbill;
Expand Down Expand Up @@ -96,6 +98,24 @@ pub mod pallet {
Self::deposit_event(Event::OffenceCreated { offenders });
Ok(())
}

/// 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) -> DispatchResultWithPostInfo {
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 as frame_system::Config>::SystemWeightInfo::remark(
4u32,
))
.into(),
error: DispatchError::BadOrigin,
})
},
}
}
}

impl<T: Config> Pallet<T> {
Expand Down
20 changes: 1 addition & 19 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use sp_runtime::{
CheckEqual, Dispatchable, Hash, Lookup, LookupError, MaybeDisplay, MaybeMallocSizeOf,
MaybeSerializeDeserialize, Member, One, Saturating, SimpleBitOps, StaticLookup, Zero,
},
DispatchError, Perbill, RuntimeDebug,
DispatchError, RuntimeDebug,
};
#[cfg(any(feature = "std", test))]
use sp_std::map;
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks transaction version.
can we have a dummy call to preserve the call index of the other calls to reduce the impact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

@xlc xlc Nov 7, 2022

Choose a reason for hiding this comment

The 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 pub fn removed_call_do_not_use(origin: OriginFor<T>, _ratio: Perbill) and make the weight to be block weight so it cannot be included

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xlc do we even need _ratio as an argument?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Expand Down