diff --git a/pallets/shield/src/lib.rs b/pallets/shield/src/lib.rs index e60bb2a6dc..22cf3240a1 100644 --- a/pallets/shield/src/lib.rs +++ b/pallets/shield/src/lib.rs @@ -16,20 +16,22 @@ pub mod pallet { use super::*; use codec::Encode; use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo}, + dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo}, pallet_prelude::*, traits::ConstU32, + traits::IsSubType, weights::Weight, }; use frame_system::pallet_prelude::*; use sp_consensus_aura::sr25519::AuthorityId as AuraAuthorityId; use sp_core::ByteArray; - use sp_runtime::transaction_validity::{ - InvalidTransaction, TransactionSource, ValidTransaction, - }; use sp_runtime::{ AccountId32, DispatchErrorWithPostInfo, RuntimeDebug, Saturating, - traits::{BadOrigin, Hash}, + traits::{ + BadOrigin, DispatchInfoOf, DispatchOriginOf, Dispatchable, Hash, Implication, + TransactionExtension, + }, + transaction_validity::{InvalidTransaction, TransactionSource, ValidTransaction}, }; use sp_std::{marker::PhantomData, prelude::*}; use subtensor_macros::freeze_struct; @@ -382,4 +384,93 @@ pub mod pallet { } } } + + #[freeze_struct("51f74eb54f5ab1fe")] + #[derive(Default, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)] + pub struct MevShieldDecryptionFilter(pub PhantomData); + + impl sp_std::fmt::Debug for MevShieldDecryptionFilter { + fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { + write!(f, "MevShieldDecryptionFilter") + } + } + + impl MevShieldDecryptionFilter { + pub fn new() -> Self { + Self(PhantomData) + } + + #[inline] + fn mev_failed_priority() -> TransactionPriority { + 1u64 + } + } + + impl TransactionExtension> + for MevShieldDecryptionFilter + where + ::RuntimeCall: + Dispatchable, + ::RuntimeCall: IsSubType>, + { + const IDENTIFIER: &'static str = "MevShieldDecryptionFilter"; + + type Implicit = (); + type Val = (); + type Pre = (); + + fn weight(&self, _call: &RuntimeCallFor) -> Weight { + // Only does light pattern matching; treat as free. + Weight::zero() + } + + fn validate( + &self, + origin: DispatchOriginOf>, + call: &RuntimeCallFor, + _info: &DispatchInfoOf>, + _len: usize, + _self_implicit: Self::Implicit, + _inherited_implication: &impl Implication, + source: TransactionSource, + ) -> ValidateResult> { + match call.is_sub_type() { + Some(Call::mark_decryption_failed { id, .. }) => { + match source { + TransactionSource::Local | TransactionSource::InBlock => { + let validity_res = + ValidTransaction::with_tag_prefix("mev-shield-failed") + .priority(Self::mev_failed_priority()) + .longevity(64) + .and_provides(id) + .propagate(false) + .build(); + + match validity_res { + Ok(validity) => Ok((validity, (), origin)), + Err(e) => Err(e), + } + } + + // Anything coming from the outside world (including *signed* + // transactions) is rejected at the pool boundary. + _ => Err(InvalidTransaction::Call.into()), + } + } + + _ => Ok((Default::default(), (), origin)), + } + } + + fn prepare( + self, + _val: Self::Val, + _origin: &DispatchOriginOf>, + _call: &RuntimeCallFor, + _info: &DispatchInfoOf>, + _len: usize, + ) -> Result { + Ok(()) + } + } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 8a293e95e9..9d502c925d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -237,7 +237,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 350, + spec_version: 360, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,