Companion for #11981 (#5915)

* Companion for #11981

* more renaming

* fmt

* fixes

* add generic type

* Companion for #11831

* fix

* revert changes

* Delete rename-outer-enum.diff

* revert

* Update run_benches_for_runtime.sh

* rename type Call & type Event

* passing tests

* fmt

* small fixes

* commit

* fix

* fmt

* commit

* error fixes

* fix

* small fix in test

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* remove RuntimeCall from pallet_grandpa

* last fix

* commit

* rename

* merge fix

* update lockfile for {"substrate"}

* cargo +nightly fmt

* fix

Co-authored-by: parity-processbot <>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Sergej Sakac
2022-09-13 01:03:47 +02:00
committed by GitHub
parent db0fc60344
commit 8ea6076fe5
73 changed files with 1241 additions and 1151 deletions
+16 -16
View File
@@ -71,7 +71,7 @@ pub mod pallet {
/// The module configuration trait.
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Required origin for sending XCM messages. If successful, it resolves to `MultiLocation`
/// which exists as an interior location within this chain's XCM context.
@@ -86,10 +86,10 @@ pub mod pallet {
type ExecuteXcmOrigin: EnsureOrigin<<Self as SysConfig>::Origin, Success = MultiLocation>;
/// Our XCM filter which messages to be executed using `XcmExecutor` must pass.
type XcmExecuteFilter: Contains<(MultiLocation, Xcm<<Self as SysConfig>::Call>)>;
type XcmExecuteFilter: Contains<(MultiLocation, Xcm<<Self as SysConfig>::RuntimeCall>)>;
/// Something to execute an XCM message.
type XcmExecutor: ExecuteXcm<<Self as SysConfig>::Call>;
type XcmExecutor: ExecuteXcm<<Self as SysConfig>::RuntimeCall>;
/// Our XCM filter which messages to be teleported using the dedicated extrinsic must pass.
type XcmTeleportFilter: Contains<(MultiLocation, Vec<MultiAsset>)>;
@@ -98,7 +98,7 @@ pub mod pallet {
type XcmReserveTransferFilter: Contains<(MultiLocation, Vec<MultiAsset>)>;
/// Means of measuring the weight consumed by an XCM message locally.
type Weigher: WeightBounds<<Self as SysConfig>::Call>;
type Weigher: WeightBounds<<Self as SysConfig>::RuntimeCall>;
/// Means of inverting a location.
type LocationInverter: InvertLocation;
@@ -107,9 +107,9 @@ pub mod pallet {
type Origin: From<Origin> + From<<Self as SysConfig>::Origin>;
/// The outer `Call` type.
type Call: Parameter
type RuntimeCall: Parameter
+ GetDispatchInfo
+ IsType<<Self as frame_system::Config>::Call>
+ IsType<<Self as frame_system::Config>::RuntimeCall>
+ Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>;
const VERSION_DISCOVERY_QUEUE_SIZE: u32;
@@ -564,7 +564,7 @@ pub mod pallet {
#[pallet::weight(max_weight.saturating_add(Weight::from_ref_time(100_000_000u64)))]
pub fn execute(
origin: OriginFor<T>,
message: Box<VersionedXcm<<T as SysConfig>::Call>>,
message: Box<VersionedXcm<<T as SysConfig>::RuntimeCall>>,
max_weight: Weight,
) -> DispatchResultWithPostInfo {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
@@ -1142,13 +1142,13 @@ pub mod pallet {
pub fn report_outcome_notify(
message: &mut Xcm<()>,
responder: impl Into<MultiLocation>,
notify: impl Into<<T as Config>::Call>,
notify: impl Into<<T as Config>::RuntimeCall>,
timeout: T::BlockNumber,
) -> Result<(), XcmError> {
let responder = responder.into();
let dest = T::LocationInverter::invert_location(&responder)
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
let notify: <T as Config>::Call = notify.into();
let notify: <T as Config>::RuntimeCall = notify.into();
let max_response_weight = notify.get_dispatch_info().weight;
let query_id = Self::new_notify_query(responder, notify, timeout);
let report_error = Xcm(vec![ReportError {
@@ -1169,7 +1169,7 @@ pub mod pallet {
/// which will call a dispatchable when a response happens.
pub fn new_notify_query(
responder: impl Into<MultiLocation>,
notify: impl Into<<T as Config>::Call>,
notify: impl Into<<T as Config>::RuntimeCall>,
timeout: T::BlockNumber,
) -> u64 {
let notify =
@@ -1214,10 +1214,10 @@ pub mod pallet {
}
impl<T: Config> WrapVersion for Pallet<T> {
fn wrap_version<Call>(
fn wrap_version<RuntimeCall>(
dest: &MultiLocation,
xcm: impl Into<VersionedXcm<Call>>,
) -> Result<VersionedXcm<Call>, ()> {
xcm: impl Into<VersionedXcm<RuntimeCall>>,
) -> Result<VersionedXcm<RuntimeCall>, ()> {
SupportedVersion::<T>::get(XCM_VERSION, LatestVersionedMultiLocation(dest))
.or_else(|| {
Self::note_unknown_version(dest);
@@ -1399,9 +1399,9 @@ pub mod pallet {
// be built by `(pallet_index: u8, call_index: u8, QueryId, Response)`.
// So we just encode that and then re-encode to a real Call.
let bare = (pallet_index, call_index, query_id, response);
if let Ok(call) = bare
.using_encoded(|mut bytes| <T as Config>::Call::decode(&mut bytes))
{
if let Ok(call) = bare.using_encoded(|mut bytes| {
<T as Config>::RuntimeCall::decode(&mut bytes)
}) {
Queries::<T>::remove(query_id);
let weight = call.get_dispatch_info().weight;
let max_weight = Weight::from_ref_time(max_weight);
+16 -16
View File
@@ -51,10 +51,10 @@ pub mod pallet_test_notifier {
#[pallet::config]
pub trait Config: frame_system::Config + crate::Config {
type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;
type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;
type Origin: IsType<<Self as frame_system::Config>::Origin>
+ Into<Result<crate::Origin, <Self as Config>::Origin>>;
type Call: IsType<<Self as crate::Config>::Call> + From<Call<Self>>;
type RuntimeCall: IsType<<Self as crate::Config>::RuntimeCall> + From<Call<Self>>;
}
#[pallet::event]
@@ -97,7 +97,7 @@ pub mod pallet_test_notifier {
Call::<T>::notification_received { query_id: 0, response: Default::default() };
let qid = crate::Pallet::<T>::new_notify_query(
Junction::AccountId32 { network: Any, id }.into(),
<T as Config>::Call::from(call),
<T as Config>::RuntimeCall::from(call),
100u32.into(),
);
Self::deposit_event(Event::<T>::NotifyQueryPrepared(qid));
@@ -172,7 +172,7 @@ parameter_types! {
impl frame_system::Config for Test {
type Origin = Origin;
type Call = Call;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
@@ -180,7 +180,7 @@ impl frame_system::Config for Test {
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
type BlockLength = ();
@@ -206,7 +206,7 @@ parameter_types! {
impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
type Balance = Balance;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
@@ -251,7 +251,7 @@ pub type Barrier = (
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type Call = Call;
type RuntimeCall = RuntimeCall;
type XcmSender = TestSendXcm;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = LocalOriginConverter;
@@ -259,7 +259,7 @@ impl xcm_executor::Config for XcmConfig {
type IsTeleporter = Case<TrustedAssets>;
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
type Trader = FixedRateOfFungible<CurrencyPerSecond, ()>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
@@ -274,7 +274,7 @@ parameter_types! {
}
impl pallet_xcm::Config for Test {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = (TestSendXcmErrX8, TestSendXcm);
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
@@ -282,10 +282,10 @@ impl pallet_xcm::Config for Test {
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
type LocationInverter = LocationInverter<Ancestry>;
type Origin = Origin;
type Call = Call;
type RuntimeCall = RuntimeCall;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = AdvertisedXcmVersion;
}
@@ -293,16 +293,16 @@ impl pallet_xcm::Config for Test {
impl origin::Config for Test {}
impl pallet_test_notifier::Config for Test {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type Call = Call;
type RuntimeCall = RuntimeCall;
}
pub(crate) fn last_event() -> Event {
System::events().pop().expect("Event expected").event
pub(crate) fn last_event() -> RuntimeEvent {
System::events().pop().expect("RuntimeEvent expected").event
}
pub(crate) fn last_events(n: usize) -> Vec<Event> {
pub(crate) fn last_events(n: usize) -> Vec<RuntimeEvent> {
System::events().into_iter().map(|e| e.event).rev().take(n).rev().collect()
}
+18 -15
View File
@@ -50,7 +50,7 @@ fn report_outcome_notify_works() {
query_id: 0,
response: Default::default(),
};
let notify = Call::TestNotifier(call);
let notify = RuntimeCall::TestNotifier(call);
new_test_ext_with_balances(balances).execute_with(|| {
XcmPallet::report_outcome_notify(&mut message, Parachain(PARA_ID).into(), notify, 100)
.unwrap();
@@ -85,12 +85,12 @@ fn report_outcome_notify_works() {
assert_eq!(
last_events(2),
vec![
Event::TestNotifier(pallet_test_notifier::Event::ResponseReceived(
RuntimeEvent::TestNotifier(pallet_test_notifier::Event::ResponseReceived(
Parachain(PARA_ID).into(),
0,
Response::ExecutionResult(None),
)),
Event::XcmPallet(crate::Event::Notified(0, 4, 2)),
RuntimeEvent::XcmPallet(crate::Event::Notified(0, 4, 2)),
]
);
assert_eq!(crate::Queries::<Test>::iter().collect::<Vec<_>>(), vec![]);
@@ -140,7 +140,10 @@ fn report_outcome_works() {
assert_eq!(r, Outcome::Complete(1_000));
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::ResponseReady(0, Response::ExecutionResult(None),))
RuntimeEvent::XcmPallet(crate::Event::ResponseReady(
0,
Response::ExecutionResult(None),
))
);
let response = Some((Response::ExecutionResult(None), 1));
@@ -181,7 +184,7 @@ fn send_works() {
);
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Sent(sender, RelayLocation::get(), message))
RuntimeEvent::XcmPallet(crate::Event::Sent(sender, RelayLocation::get(), message))
);
});
}
@@ -253,7 +256,7 @@ fn teleport_assets_works() {
let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap();
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
);
});
}
@@ -297,7 +300,7 @@ fn limmited_teleport_assets_works() {
let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap();
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
);
});
}
@@ -339,7 +342,7 @@ fn unlimmited_teleport_assets_works() {
);
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
);
});
}
@@ -387,7 +390,7 @@ fn reserve_transfer_assets_works() {
let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap();
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
);
});
}
@@ -436,7 +439,7 @@ fn limited_reserve_transfer_assets_works() {
let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap();
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
);
});
}
@@ -483,7 +486,7 @@ fn unlimited_reserve_transfer_assets_works() {
);
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
);
});
}
@@ -516,7 +519,7 @@ fn execute_withdraw_to_deposit_works() {
assert_eq!(Balances::total_balance(&BOB), SEND_AMOUNT);
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
);
});
}
@@ -552,8 +555,8 @@ fn trapped_assets_can_be_claimed() {
assert_eq!(
last_events(2),
vec![
Event::XcmPallet(crate::Event::AssetsTrapped(hash.clone(), source, vma)),
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(
RuntimeEvent::XcmPallet(crate::Event::AssetsTrapped(hash.clone(), source, vma)),
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Complete(
5 * BaseXcmWeight::get()
)))
]
@@ -591,7 +594,7 @@ fn trapped_assets_can_be_claimed() {
));
assert_eq!(
last_event(),
Event::XcmPallet(crate::Event::Attempted(Outcome::Incomplete(
RuntimeEvent::XcmPallet(crate::Event::Attempted(Outcome::Incomplete(
BaseXcmWeight::get(),
XcmError::UnknownClaim
)))