diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 2a33262073..eda6b6a489 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1685,7 +1685,7 @@ pub mod pallet { #[pallet::weight(( Weight::from_parts(3_918_000, 0) // TODO: add benchmarks .saturating_add(T::DbWeight::get().writes(1_u64)), - DispatchClass::Operational, + DispatchClass::Normal, Pays::Yes ))] pub fn sudo_set_subnet_owner_hotkey( diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 2a362783ef..6555434757 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2413,7 +2413,7 @@ mod dispatches { Weight::from_parts(5_711_000, 0) .saturating_add(T::DbWeight::get().reads(0_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)), - DispatchClass::Operational, + DispatchClass::Normal, Pays::Yes ))] pub fn sudo_set_root_claim_threshold( diff --git a/runtime/src/transaction_payment_wrapper.rs b/runtime/src/transaction_payment_wrapper.rs index 96d7f3609b..11324b4c4a 100644 --- a/runtime/src/transaction_payment_wrapper.rs +++ b/runtime/src/transaction_payment_wrapper.rs @@ -1,20 +1,55 @@ use crate::{NORMAL_DISPATCH_BASE_PRIORITY, OPERATIONAL_DISPATCH_PRIORITY, Weight}; use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_election_provider_support::private::sp_arithmetic::traits::SaturatedConversion; -use frame_support::dispatch::{DispatchClass, DispatchInfo, PostDispatchInfo}; -use frame_support::pallet_prelude::TypeInfo; -use pallet_transaction_payment::{ChargeTransactionPayment, Config, Pre, Val}; -use sp_runtime::DispatchResult; -use sp_runtime::traits::{ - DispatchInfoOf, DispatchOriginOf, Dispatchable, Implication, PostDispatchInfoOf, - TransactionExtension, TransactionExtensionMetadata, ValidateResult, +use frame_support::{ + dispatch::{DispatchClass, DispatchInfo, PostDispatchInfo}, + pallet_prelude::TypeInfo, + traits::IsSubType, }; -use sp_runtime::transaction_validity::{ - TransactionPriority, TransactionSource, TransactionValidity, TransactionValidityError, +use pallet_shield::AuthorityOriginExt; +use pallet_transaction_payment::{ChargeTransactionPayment, Config, Pre, Val}; +use sp_runtime::{ + DispatchResult, + traits::{ + DispatchInfoOf, DispatchOriginOf, Dispatchable, Implication, PostDispatchInfoOf, + TransactionExtension, TransactionExtensionMetadata, ValidateResult, + }, + transaction_validity::{ + TransactionPriority, TransactionSource, TransactionValidity, TransactionValidityError, + }, }; use sp_std::vec::Vec; use subtensor_macros::freeze_struct; +/// Helper trait to: +/// - identify whether a `RuntimeCall` is `MevShield::announce_next_key` via `IsSubType` +/// - perform the `ensure_validator` origin check +/// +pub trait MevShieldPrioritySupport: frame_system::Config { + fn is_announce_next_key(call: &Self::RuntimeCall) -> bool; + fn ensure_validator(origin: DispatchOriginOf) -> bool; +} + +impl MevShieldPrioritySupport for T +where + T: pallet_shield::Config + frame_system::Config, + ::RuntimeCall: IsSubType>, +{ + fn is_announce_next_key(call: &Self::RuntimeCall) -> bool { + if let Some(pallet_shield::Call::::announce_next_key { .. }) = + IsSubType::>::is_sub_type(call) + { + return true; + } + + false + } + + fn ensure_validator(origin: DispatchOriginOf) -> bool { + ::AuthorityOrigin::ensure_validator(origin).is_ok() + } +} + #[freeze_struct("5f10cb9db06873c0")] #[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)] #[scale_info(skip_type_params(T))] @@ -43,6 +78,7 @@ impl ChargeTransactionPaymentWrapper { impl TransactionExtension for ChargeTransactionPaymentWrapper where + T: MevShieldPrioritySupport, T::RuntimeCall: Dispatchable, { const IDENTIFIER: &'static str = "ChargeTransactionPaymentWrapper"; @@ -80,7 +116,21 @@ where let base: TransactionPriority = match info.class { DispatchClass::Normal => NORMAL_DISPATCH_BASE_PRIORITY, DispatchClass::Mandatory => NORMAL_DISPATCH_BASE_PRIORITY, - DispatchClass::Operational => OPERATIONAL_DISPATCH_PRIORITY, + DispatchClass::Operational => { + let is_root = frame_system::ensure_root(origin.clone()).is_ok(); + + let is_validator_announce_next_key = + ::is_announce_next_key(call) + && ::ensure_validator( + origin.clone(), + ); + + if is_root || is_validator_announce_next_key { + OPERATIONAL_DISPATCH_PRIORITY + } else { + NORMAL_DISPATCH_BASE_PRIORITY + } + } }; base.saturated_into::() };