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

Expect less chaos: use explicit call indices #1984

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 0 deletions pallets/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the list of invulnerable (fixed) collators.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set_invulnerables(new.len() as u32))]
pub fn set_invulnerables(
origin: OriginFor<T>,
Expand Down Expand Up @@ -315,6 +316,7 @@ pub mod pallet {
/// Set the ideal number of collators (not including the invulnerables).
/// If lowering this number, then the number of running collators could be higher than this figure.
/// Aside from that edge case, there should be no other way to have more collators than the desired number.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::set_desired_candidates())]
pub fn set_desired_candidates(
origin: OriginFor<T>,
Expand All @@ -331,6 +333,7 @@ pub mod pallet {
}

/// Set the candidacy bond amount.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::set_candidacy_bond())]
pub fn set_candidacy_bond(
origin: OriginFor<T>,
Expand All @@ -346,6 +349,7 @@ pub mod pallet {
/// registered session keys and (b) be able to reserve the `CandidacyBond`.
///
/// This call is not available to `Invulnerable` collators.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCandidates::get()))]
pub fn register_as_candidate(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Expand Down Expand Up @@ -391,6 +395,7 @@ pub mod pallet {
/// This call will fail if the total number of candidates would drop below `MinCandidates`.
///
/// This call is not available to `Invulnerable` collators.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::leave_intent(T::MaxCandidates::get()))]
pub fn leave_intent(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Expand Down
1 change: 1 addition & 0 deletions pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub mod pallet {
///
/// Events:
/// - `OverweightServiced`: On success.
#[pallet::call_index(0)]
#[pallet::weight(Weight::from_ref_time(weight_limit.saturating_add(1_000_000)))]
pub fn service_overweight(
origin: OriginFor<T>,
Expand Down
4 changes: 4 additions & 0 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ pub mod pallet {
///
/// As a side effect, this function upgrades the current validation function
/// if the appropriate time has come.
#[pallet::call_index(0)]
#[pallet::weight((0, DispatchClass::Mandatory))]
// TODO: This weight should be corrected.
pub fn set_validation_data(
Expand Down Expand Up @@ -431,6 +432,7 @@ pub mod pallet {
Ok(PostDispatchInfo { actual_weight: Some(total_weight), pays_fee: Pays::No })
}

#[pallet::call_index(1)]
#[pallet::weight((1_000, DispatchClass::Operational))]
pub fn sudo_send_upward_message(
origin: OriginFor<T>,
Expand All @@ -441,6 +443,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(2)]
#[pallet::weight((1_000_000, DispatchClass::Operational))]
pub fn authorize_upgrade(origin: OriginFor<T>, code_hash: T::Hash) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -451,6 +454,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(3)]
#[pallet::weight(1_000_000)]
pub fn enact_authorized_upgrade(
_: OriginFor<T>,
Expand Down
1 change: 1 addition & 0 deletions pallets/solo-to-para/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(0)]
pub fn schedule_migration(
origin: OriginFor<T>,
Expand Down
9 changes: 9 additions & 0 deletions pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub mod pallet {
///
/// Events:
/// - `OverweightServiced`: On success.
#[pallet::call_index(0)]
#[pallet::weight((Weight::from_ref_time(weight_limit.saturating_add(1_000_000)), DispatchClass::Operational,))]
pub fn service_overweight(
origin: OriginFor<T>,
Expand All @@ -160,6 +161,7 @@ pub mod pallet {
/// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin.
///
/// - `origin`: Must pass `ControllerOrigin`.
#[pallet::call_index(1)]
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
pub fn suspend_xcm_execution(origin: OriginFor<T>) -> DispatchResult {
T::ControllerOrigin::ensure_origin(origin)?;
Expand All @@ -174,6 +176,7 @@ pub mod pallet {
/// Note that this function doesn't change the status of the in/out bound channels.
///
/// - `origin`: Must pass `ControllerOrigin`.
#[pallet::call_index(2)]
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
pub fn resume_xcm_execution(origin: OriginFor<T>) -> DispatchResult {
T::ControllerOrigin::ensure_origin(origin)?;
Expand All @@ -188,6 +191,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.suspend_value`
#[pallet::call_index(3)]
#[pallet::weight((T::WeightInfo::set_config_with_u32(), DispatchClass::Operational,))]
pub fn update_suspend_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -201,6 +205,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.drop_threshold`
#[pallet::call_index(4)]
#[pallet::weight((T::WeightInfo::set_config_with_u32(),DispatchClass::Operational,))]
pub fn update_drop_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -214,6 +219,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.resume_threshold`
#[pallet::call_index(5)]
#[pallet::weight((T::WeightInfo::set_config_with_u32(), DispatchClass::Operational,))]
pub fn update_resume_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -226,6 +232,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.threshold_weight`
#[pallet::call_index(6)]
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
pub fn update_threshold_weight(origin: OriginFor<T>, new: XcmWeight) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -239,6 +246,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.weight_restrict_decay`.
#[pallet::call_index(7)]
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
pub fn update_weight_restrict_decay(
origin: OriginFor<T>,
Expand All @@ -257,6 +265,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.xcmp_max_individual_weight`.
#[pallet::call_index(8)]
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
pub fn update_xcmp_max_individual_weight(
origin: OriginFor<T>,
Expand Down
2 changes: 2 additions & 0 deletions parachain-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// An example dispatchable that takes a singles value as a parameter, writes the value to
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
#[pallet::call_index(0)]
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(1))]
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResultWithPostInfo {
// Check that the extrinsic was signed and get the signer.
Expand All @@ -84,6 +85,7 @@ pub mod pallet {
}

/// An example dispatchable that may throw a custom error.
#[pallet::call_index(1)]
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().reads_writes(1,1))]
pub fn cause_error(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let _who = ensure_signed(origin)?;
Expand Down
6 changes: 6 additions & 0 deletions parachains/pallets/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(0)]
pub fn start(origin: OriginFor<T>, para: ParaId, payload: Vec<u8>) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -146,6 +147,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(1)]
#[pallet::weight(0)]
pub fn start_many(
origin: OriginFor<T>,
Expand All @@ -165,6 +167,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(2)]
#[pallet::weight(0)]
pub fn stop(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -176,6 +179,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(3)]
#[pallet::weight(0)]
pub fn stop_all(origin: OriginFor<T>, maybe_para: Option<ParaId>) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -187,6 +191,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(4)]
#[pallet::weight(0)]
pub fn ping(origin: OriginFor<T>, seq: u32, payload: Vec<u8>) -> DispatchResult {
// Only accept pings from other chains.
Expand All @@ -212,6 +217,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(5)]
#[pallet::weight(0)]
pub fn pong(origin: OriginFor<T>, seq: u32, payload: Vec<u8>) -> DispatchResult {
// Only accept pings from other chains.
Expand Down
2 changes: 1 addition & 1 deletion test/runtime/src/test_pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/// A special pallet that exposes dispatchables that are only useful for testing.
pub use pallet::*;

#[frame_support::pallet]
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
Expand Down