BREAKING: Rename Call & Event (#11981)

* rename Event to RuntimeEvent

* rename Call

* rename in runtimes

* small fix

* rename Event

* small fix & rename RuntimeCall back to Call for now

* small fixes

* more renaming

* a bit more renaming

* fmt

* small fix

* commit

* prep for renaming associated types

* fix

* rename associated Event type

* rename to RuntimeEvent

* commit

* merge conflict fixes & fmt

* additional renaming

* fix.

* fix decl_event

* rename in tests

* remove warnings

* remove accidental rename

* .

* commit

* update .stderr

* fix in test

* update .stderr

* TRYBUILD=overwrite

* docs

* fmt

* small change in docs

* rename PalletEvent to Event

* rename Call to RuntimeCall

* renamed at wrong places :P

* rename Call

* rename

* rename associated type

* fix

* fix & fmt

* commit

* frame-support-test

* passing tests

* update docs

* rustdoc fix

* update .stderr

* wrong code in docs

* merge fix

* fix in error message

* update .stderr

* docs & error message

* .

* merge fix

* merge fix

* fmt

* fmt

* merge fix

* more fixing

* fmt

* remove unused

* fmt

* fix

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Sergej Sakac
2022-09-13 00:03:31 +02:00
committed by GitHub
parent 472b5746e5
commit 6e8795afe6
228 changed files with 1791 additions and 1672 deletions
+4 -4
View File
@@ -25,7 +25,7 @@ use frame_system::RawOrigin;
const SEED: u32 = 0;
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}
@@ -33,7 +33,7 @@ benchmarks! {
where_clause { where <T::Origin as frame_support::traits::OriginTrait>::PalletsOrigin: Clone }
batch {
let c in 0 .. 1000;
let mut calls: Vec<<T as Config>::Call> = Vec::new();
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new();
for i in 0 .. c {
let call = frame_system::Call::remark { remark: vec![] }.into();
calls.push(call);
@@ -54,7 +54,7 @@ benchmarks! {
batch_all {
let c in 0 .. 1000;
let mut calls: Vec<<T as Config>::Call> = Vec::new();
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new();
for i in 0 .. c {
let call = frame_system::Call::remark { remark: vec![] }.into();
calls.push(call);
@@ -75,7 +75,7 @@ benchmarks! {
force_batch {
let c in 0 .. 1000;
let mut calls: Vec<<T as Config>::Call> = Vec::new();
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new();
for i in 0 .. c {
let call = frame_system::Call::remark { remark: vec![] }.into();
calls.push(call);
+18 -15
View File
@@ -84,16 +84,16 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event> + IsType<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The overarching call type.
type Call: Parameter
type RuntimeCall: Parameter
+ Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
+ GetDispatchInfo
+ From<frame_system::Call<Self>>
+ UnfilteredDispatchable<Origin = Self::Origin>
+ IsSubType<Call<Self>>
+ IsType<<Self as frame_system::Config>::Call>;
+ IsType<<Self as frame_system::Config>::RuntimeCall>;
/// The caller origin, overarching type of all pallets origins.
type PalletsOrigin: Parameter +
@@ -133,8 +133,9 @@ pub mod pallet {
/// The limit on the number of batched calls.
fn batched_calls_limit() -> u32 {
let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION;
let call_size = ((sp_std::mem::size_of::<<T as Config>::Call>() as u32 + CALL_ALIGN -
1) / CALL_ALIGN) * CALL_ALIGN;
let call_size = ((sp_std::mem::size_of::<<T as Config>::RuntimeCall>() as u32 +
CALL_ALIGN - 1) / CALL_ALIGN) *
CALL_ALIGN;
// The margin to take into account vec doubling capacity.
let margin_factor = 3;
@@ -147,7 +148,7 @@ pub mod pallet {
fn integrity_test() {
// If you hit this error, you need to try to `Box` big dispatchable parameters.
assert!(
sp_std::mem::size_of::<<T as Config>::Call>() as u32 <= CALL_ALIGN,
sp_std::mem::size_of::<<T as Config>::RuntimeCall>() as u32 <= CALL_ALIGN,
"Call enum size should be smaller than {} bytes.",
CALL_ALIGN,
);
@@ -201,7 +202,7 @@ pub mod pallet {
})]
pub fn batch(
origin: OriginFor<T>,
calls: Vec<<T as Config>::Call>,
calls: Vec<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let calls_len = calls.len();
@@ -262,7 +263,7 @@ pub mod pallet {
pub fn as_derivative(
origin: OriginFor<T>,
index: u16,
call: Box<<T as Config>::Call>,
call: Box<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let mut origin = origin;
let who = ensure_signed(origin.clone())?;
@@ -317,7 +318,7 @@ pub mod pallet {
})]
pub fn batch_all(
origin: OriginFor<T>,
calls: Vec<<T as Config>::Call>,
calls: Vec<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let calls_len = calls.len();
@@ -333,10 +334,12 @@ pub mod pallet {
} else {
let mut filtered_origin = origin.clone();
// Don't allow users to nest `batch_all` calls.
filtered_origin.add_filter(move |c: &<T as frame_system::Config>::Call| {
let c = <T as Config>::Call::from_ref(c);
!matches!(c.is_sub_type(), Some(Call::batch_all { .. }))
});
filtered_origin.add_filter(
move |c: &<T as frame_system::Config>::RuntimeCall| {
let c = <T as Config>::RuntimeCall::from_ref(c);
!matches!(c.is_sub_type(), Some(Call::batch_all { .. }))
},
);
call.dispatch(filtered_origin)
};
// Add the weight of this call.
@@ -376,7 +379,7 @@ pub mod pallet {
pub fn dispatch_as(
origin: OriginFor<T>,
as_origin: Box<T::PalletsOrigin>,
call: Box<<T as Config>::Call>,
call: Box<<T as Config>::RuntimeCall>,
) -> DispatchResult {
ensure_root(origin)?;
@@ -422,7 +425,7 @@ pub mod pallet {
})]
pub fn force_batch(
origin: OriginFor<T>,
calls: Vec<<T as Config>::Call>,
calls: Vec<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let calls_len = calls.len();
+66 -45
View File
@@ -110,12 +110,12 @@ impl frame_system::Config for Test {
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Call = Call;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
@@ -134,7 +134,7 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
type Balance = u64;
type DustRemoval = ();
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type WeightInfo = ();
@@ -148,23 +148,23 @@ parameter_types! {
impl example::Config for Test {}
pub struct TestBaseCallFilter;
impl Contains<Call> for TestBaseCallFilter {
fn contains(c: &Call) -> bool {
impl Contains<RuntimeCall> for TestBaseCallFilter {
fn contains(c: &RuntimeCall) -> bool {
match *c {
// Transfer works. Use `transfer_keep_alive` for a call that doesn't pass the filter.
Call::Balances(pallet_balances::Call::transfer { .. }) => true,
Call::Utility(_) => true,
RuntimeCall::Balances(pallet_balances::Call::transfer { .. }) => true,
RuntimeCall::Utility(_) => true,
// For benchmarking, this acts as a noop call
Call::System(frame_system::Call::remark { .. }) => true,
RuntimeCall::System(frame_system::Call::remark { .. }) => true,
// For tests
Call::Example(_) => true,
RuntimeCall::Example(_) => true,
_ => false,
}
}
}
impl Config for Test {
type Event = Event;
type Call = Call;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
}
@@ -187,12 +187,12 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
ext
}
fn call_transfer(dest: u64, value: u64) -> Call {
Call::Balances(BalancesCall::transfer { dest, value })
fn call_transfer(dest: u64, value: u64) -> RuntimeCall {
RuntimeCall::Balances(BalancesCall::transfer { dest, value })
}
fn call_foobar(err: bool, start_weight: Weight, end_weight: Option<Weight>) -> Call {
Call::Example(ExampleCall::foobar { err, start_weight, end_weight })
fn call_foobar(err: bool, start_weight: Weight, end_weight: Option<Weight>) -> RuntimeCall {
RuntimeCall::Example(ExampleCall::foobar { err, start_weight, end_weight })
}
#[test]
@@ -219,8 +219,10 @@ fn as_derivative_handles_weight_refund() {
// Full weight when ok
let inner_call = call_foobar(false, start_weight, None);
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let call = RuntimeCall::Utility(UtilityCall::as_derivative {
index: 0,
call: Box::new(inner_call),
});
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -228,8 +230,10 @@ fn as_derivative_handles_weight_refund() {
// Refund weight when ok
let inner_call = call_foobar(false, start_weight, Some(end_weight));
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let call = RuntimeCall::Utility(UtilityCall::as_derivative {
index: 0,
call: Box::new(inner_call),
});
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -238,8 +242,10 @@ fn as_derivative_handles_weight_refund() {
// Full weight when err
let inner_call = call_foobar(true, start_weight, None);
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let call = RuntimeCall::Utility(UtilityCall::as_derivative {
index: 0,
call: Box::new(inner_call),
});
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_noop!(
@@ -256,8 +262,10 @@ fn as_derivative_handles_weight_refund() {
// Refund weight when err
let inner_call = call_foobar(true, start_weight, Some(end_weight));
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let call = RuntimeCall::Utility(UtilityCall::as_derivative {
index: 0,
call: Box::new(inner_call),
});
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_noop!(
@@ -281,7 +289,7 @@ fn as_derivative_filters() {
Utility::as_derivative(
Origin::signed(1),
1,
Box::new(Call::Balances(pallet_balances::Call::transfer_keep_alive {
Box::new(RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive {
dest: 2,
value: 1
})),
@@ -295,16 +303,25 @@ fn as_derivative_filters() {
fn batch_with_root_works() {
new_test_ext().execute_with(|| {
let k = b"a".to_vec();
let call =
Call::System(frame_system::Call::set_storage { items: vec![(k.clone(), k.clone())] });
let call = RuntimeCall::System(frame_system::Call::set_storage {
items: vec![(k.clone(), k.clone())],
});
assert!(!TestBaseCallFilter::contains(&call));
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 10);
assert_ok!(Utility::batch(
Origin::root(),
vec![
Call::Balances(BalancesCall::force_transfer { source: 1, dest: 2, value: 5 }),
Call::Balances(BalancesCall::force_transfer { source: 1, dest: 2, value: 5 }),
RuntimeCall::Balances(BalancesCall::force_transfer {
source: 1,
dest: 2,
value: 5
}),
RuntimeCall::Balances(BalancesCall::force_transfer {
source: 1,
dest: 2,
value: 5
}),
call, // Check filters are correctly bypassed
]
));
@@ -333,7 +350,10 @@ fn batch_with_signed_filters() {
new_test_ext().execute_with(|| {
assert_ok!(Utility::batch(
Origin::signed(1),
vec![Call::Balances(pallet_balances::Call::transfer_keep_alive { dest: 2, value: 1 })]
vec![RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive {
dest: 2,
value: 1
})]
),);
System::assert_last_event(
utility::Event::BatchInterrupted {
@@ -363,11 +383,12 @@ fn batch_early_exit_works() {
fn batch_weight_calculation_doesnt_overflow() {
use sp_runtime::Perbill;
new_test_ext().execute_with(|| {
let big_call = Call::System(SystemCall::fill_block { ratio: Perbill::from_percent(50) });
let big_call =
RuntimeCall::System(SystemCall::fill_block { ratio: Perbill::from_percent(50) });
assert_eq!(big_call.get_dispatch_info().weight, Weight::MAX / 2);
// 3 * 50% saturates to 100%
let batch_call = Call::Utility(crate::Call::batch {
let batch_call = RuntimeCall::Utility(crate::Call::batch {
calls: vec![big_call.clone(), big_call.clone(), big_call.clone()],
});
@@ -386,7 +407,7 @@ fn batch_handles_weight_refund() {
// Full weight when ok
let inner_call = call_foobar(false, start_weight, None);
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -395,7 +416,7 @@ fn batch_handles_weight_refund() {
// Refund weight when ok
let inner_call = call_foobar(false, start_weight, Some(end_weight));
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -406,7 +427,7 @@ fn batch_handles_weight_refund() {
let good_call = call_foobar(false, start_weight, None);
let bad_call = call_foobar(true, start_weight, None);
let batch_calls = vec![good_call, bad_call];
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -421,7 +442,7 @@ fn batch_handles_weight_refund() {
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call];
let batch_len = batch_calls.len() as u64;
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -434,7 +455,7 @@ fn batch_handles_weight_refund() {
let good_call = call_foobar(false, start_weight, Some(end_weight));
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call.clone(), bad_call];
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -471,7 +492,7 @@ fn batch_all_revert() {
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 10);
let batch_all_calls = Call::Utility(crate::Call::<Test>::batch_all {
let batch_all_calls = RuntimeCall::Utility(crate::Call::<Test>::batch_all {
calls: vec![call_transfer(2, 5), call_transfer(2, 10), call_transfer(2, 5)],
});
assert_noop!(
@@ -502,7 +523,7 @@ fn batch_all_handles_weight_refund() {
// Full weight when ok
let inner_call = call_foobar(false, start_weight, None);
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -511,7 +532,7 @@ fn batch_all_handles_weight_refund() {
// Refund weight when ok
let inner_call = call_foobar(false, start_weight, Some(end_weight));
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -522,7 +543,7 @@ fn batch_all_handles_weight_refund() {
let good_call = call_foobar(false, start_weight, None);
let bad_call = call_foobar(true, start_weight, None);
let batch_calls = vec![good_call, bad_call];
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_err_ignore_postinfo!(result, "The cake is a lie.");
@@ -534,7 +555,7 @@ fn batch_all_handles_weight_refund() {
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call];
let batch_len = batch_calls.len() as u64;
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_err_ignore_postinfo!(result, "The cake is a lie.");
@@ -544,7 +565,7 @@ fn batch_all_handles_weight_refund() {
let good_call = call_foobar(false, start_weight, Some(end_weight));
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call.clone(), bad_call];
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_err_ignore_postinfo!(result, "The cake is a lie.");
@@ -559,7 +580,7 @@ fn batch_all_handles_weight_refund() {
#[test]
fn batch_all_does_not_nest() {
new_test_ext().execute_with(|| {
let batch_all = Call::Utility(UtilityCall::batch_all {
let batch_all = RuntimeCall::Utility(UtilityCall::batch_all {
calls: vec![call_transfer(2, 1), call_transfer(2, 1), call_transfer(2, 1)],
});
@@ -582,7 +603,7 @@ fn batch_all_does_not_nest() {
// And for those who want to get a little fancy, we check that the filter persists across
// other kinds of dispatch wrapping functions... in this case
// `batch_all(batch(batch_all(..)))`
let batch_nested = Call::Utility(UtilityCall::batch { calls: vec![batch_all] });
let batch_nested = RuntimeCall::Utility(UtilityCall::batch { calls: vec![batch_all] });
// Batch will end with `Ok`, but does not actually execute as we can see from the event
// and balances.
assert_ok!(Utility::batch_all(Origin::signed(1), vec![batch_nested]));
@@ -601,7 +622,7 @@ fn batch_all_does_not_nest() {
#[test]
fn batch_limit() {
new_test_ext().execute_with(|| {
let calls = vec![Call::System(SystemCall::remark { remark: vec![] }); 40_000];
let calls = vec![RuntimeCall::System(SystemCall::remark { remark: vec![] }); 40_000];
assert_noop!(Utility::batch(Origin::signed(1), calls.clone()), Error::<Test>::TooManyCalls);
assert_noop!(Utility::batch_all(Origin::signed(1), calls), Error::<Test>::TooManyCalls);
});