From 960510caf690969c622220d0da8323190908fde2 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Mon, 1 Dec 2025 16:30:26 +0100 Subject: [PATCH 01/11] Filter for incorrect sudo calls --- Cargo.lock | 1 + pallets/subtensor/Cargo.toml | 2 + pallets/subtensor/src/tests/mock.rs | 7 ++ pallets/subtensor/src/tests/mod.rs | 1 + pallets/subtensor/src/tests/tx_extension.rs | 102 ++++++++++++++++++ .../subtensor/src/transaction_extension.rs | 20 +++- 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 pallets/subtensor/src/tests/tx_extension.rs diff --git a/Cargo.lock b/Cargo.lock index a5f4583519..30da716616 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10784,6 +10784,7 @@ dependencies = [ "pallet-subtensor-proxy", "pallet-subtensor-swap", "pallet-subtensor-utility", + "pallet-sudo", "pallet-transaction-payment", "parity-scale-codec", "polkadot-runtime-common", diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 2e35a89d19..9b6192da4e 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -55,6 +55,7 @@ sha2.workspace = true rand_chacha.workspace = true pallet-crowdloan.workspace = true pallet-subtensor-proxy.workspace = true +pallet-sudo.workspace = true [dev-dependencies] pallet-balances = { workspace = true, features = ["std"] } @@ -117,6 +118,7 @@ std = [ "pallet-subtensor-swap/std", "subtensor-swap-interface/std", "pallet-subtensor-utility/std", + "pallet-sudo/std", "safe-math/std", "share-pool/std", "ark-serialize/std", diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 090fcf8f75..b8310f8b5d 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -47,6 +47,7 @@ frame_support::construct_runtime!( Swap: pallet_subtensor_swap::{Pallet, Call, Storage, Event} = 12, Crowdloan: pallet_crowdloan::{Pallet, Call, Storage, Event} = 13, Proxy: pallet_subtensor_proxy = 14, + Sudo: pallet_sudo::{Pallet, Call, Storage, Event} = 15, } ); @@ -471,6 +472,12 @@ impl InstanceFilter for subtensor_runtime_common::ProxyType { } } +impl pallet_sudo::Config for Test { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WeightInfo = pallet_sudo::weights::SubstrateWeight; +} + mod test_crypto { use super::KEY_TYPE; use sp_core::{ diff --git a/pallets/subtensor/src/tests/mod.rs b/pallets/subtensor/src/tests/mod.rs index bbaf25af58..76eb2cb4fb 100644 --- a/pallets/subtensor/src/tests/mod.rs +++ b/pallets/subtensor/src/tests/mod.rs @@ -31,3 +31,4 @@ mod swap_hotkey; mod swap_hotkey_with_subnet; mod uids; mod weights; +mod tx_extension; diff --git a/pallets/subtensor/src/tests/tx_extension.rs b/pallets/subtensor/src/tests/tx_extension.rs new file mode 100644 index 0000000000..5876d4ddd5 --- /dev/null +++ b/pallets/subtensor/src/tests/tx_extension.rs @@ -0,0 +1,102 @@ +use frame_support::assert_ok; +use frame_support::dispatch::GetDispatchInfo; +use crate::tests::mock::{new_test_ext, RuntimeCall, RuntimeOrigin, SubtensorCall}; +use subtensor_runtime_common::{NetUid, TaoCurrency}; +use sp_core::U256; +use sp_runtime::traits::{TransactionExtension, TxBaseImplication, ValidateResult}; +use crate::transaction_extension::SubtensorTransactionExtension; + +use super::mock::*; +use crate::*; + +fn some_call() -> RuntimeCall { + let hotkey = U256::from(0); + let amount_staked = TaoCurrency::from(5000); + let netuid = NetUid::from(1); + RuntimeCall::SubtensorModule(SubtensorCall::add_stake { + hotkey, + netuid, + amount_staked, + }) +} +fn sudo_extrinsic(inner: RuntimeCall) -> RuntimeCall { + RuntimeCall::Sudo(pallet_sudo::Call::sudo { + call: Box::new(inner), + }) +} + +fn validate_ext( + origin: RuntimeOrigin, + call: &RuntimeCall, +) -> ValidateResult::AccountId>, RuntimeCall> { + let ext = SubtensorTransactionExtension::::new(); + + ext.validate( + origin, + call, + &call.get_dispatch_info(), + 0, + (), + &TxBaseImplication(()), + TransactionSource::External, + ) +} +#[test] +fn sudo_signed_by_correct_key_is_valid() { + new_test_ext(1).execute_with(|| { + let sudo_key: ::AccountId = U256::from(42); + pallet_sudo::Key::::put(sudo_key); + let sudo_call = sudo_extrinsic(some_call()); + + // Signed origin with correct sudo key + let origin = RuntimeOrigin::signed(sudo_key); + let res = validate_ext(origin, &sudo_call); + assert_ok!(res); + }); +} + +#[test] +fn sudo_signed_by_wrong_account_is_rejected() { + new_test_ext(1).execute_with(|| { + let sudo_key: ::AccountId = U256::from(42); + // Set sudo key in storage + pallet_sudo::Key::::put(sudo_key); + let sudo_call = sudo_extrinsic(some_call()); + // Wrong signer + let origin = RuntimeOrigin::signed(U256::from(99)); + let res = validate_ext(origin, &sudo_call); + assert!( + matches!( + res, + Err(TransactionValidityError::Invalid(InvalidTransaction::BadSigner)) + ) + ); + }); +} + +#[test] +fn sudo_when_no_sudo_key_configured_is_rejected() { + new_test_ext(1).execute_with(|| { + // Remove sudo key + pallet_sudo::Key::::kill(); + let sudo_call = sudo_extrinsic(some_call()); + let origin = RuntimeOrigin::signed(U256::from(42)); + let res = validate_ext(origin, &sudo_call); + assert!( + matches!( + res, + Err(TransactionValidityError::Invalid(InvalidTransaction::BadSigner)) + ) + ); + }); +} + +#[test] +fn non_sudo_extrinsic_does_not_trigger_filter() { + new_test_ext(1).execute_with(|| { + let origin = RuntimeOrigin::signed(U256::from(42)); + let call = some_call(); + let res = validate_ext(origin, &call); + assert!(res.is_ok()); + }); +} \ No newline at end of file diff --git a/pallets/subtensor/src/transaction_extension.rs b/pallets/subtensor/src/transaction_extension.rs index cf1d410ea9..efd4f21818 100644 --- a/pallets/subtensor/src/transaction_extension.rs +++ b/pallets/subtensor/src/transaction_extension.rs @@ -13,7 +13,9 @@ use sp_runtime::traits::{ }; use sp_runtime::transaction_validity::{ TransactionSource, TransactionValidity, TransactionValidityError, ValidTransaction, + InvalidTransaction }; +use pallet_sudo::Call as SudoCall; use sp_std::marker::PhantomData; use sp_std::vec::Vec; use subtensor_macros::freeze_struct; @@ -85,7 +87,7 @@ where } } -impl +impl TransactionExtension<::RuntimeCall> for SubtensorTransactionExtension where @@ -94,6 +96,7 @@ where ::RuntimeOrigin: AsSystemOriginSigner + Clone, ::RuntimeCall: IsSubType>, ::RuntimeCall: IsSubType>, + ::RuntimeCall: IsSubType>, { const IDENTIFIER: &'static str = "SubtensorTransactionExtension"; @@ -121,6 +124,21 @@ where return Ok((Default::default(), None, origin)); }; + // Check validity of the signer for sudo call + if let Some(_sudo_call) = IsSubType::>::is_sub_type(call) { + let sudo_key = pallet_sudo::pallet::Key::::get(); + + // No sudo key configured → reject + let Some(expected_who) = sudo_key else { + return Err(InvalidTransaction::BadSigner.into()); + }; + + // Signer does not match the sudo key → reject + if *who != expected_who { + return Err(InvalidTransaction::BadSigner.into()); + } + } + // Verify ColdkeySwapScheduled map for coldkey match call.is_sub_type() { // Whitelist From 89fe04fb8ba57265195207b7e08b683c5dfa78af Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Mon, 8 Dec 2025 17:30:18 +0100 Subject: [PATCH 02/11] Propagate runtime-benchmarks --- pallets/subtensor/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 9b6192da4e..7cbdff2464 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -147,6 +147,7 @@ runtime-benchmarks = [ "pallet-commitments/runtime-benchmarks", "pallet-crowdloan/runtime-benchmarks", "pallet-drand/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", "pallet-subtensor-proxy/runtime-benchmarks", "pallet-subtensor-swap/runtime-benchmarks", "pallet-subtensor-utility/runtime-benchmarks" From 76757b98342b8639e18072eaabc679cb2929402c Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Mon, 8 Dec 2025 17:57:21 +0100 Subject: [PATCH 03/11] Propagate try-runtime --- pallets/subtensor/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 7cbdff2464..84024c069d 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -87,6 +87,7 @@ try-runtime = [ "pallet-commitments/try-runtime", "pallet-crowdloan/try-runtime", "pallet-drand/try-runtime", + "pallet-sudo/try-runtime", "pallet-subtensor-proxy/try-runtime", "pallet-subtensor-utility/try-runtime" ] From bc4967c05b2e9dc047dec3685a137629bd7847c7 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Tue, 9 Dec 2025 17:48:23 +0100 Subject: [PATCH 04/11] cargo fmt --- pallets/subtensor/src/tests/mod.rs | 2 +- pallets/subtensor/src/tests/tx_extension.rs | 32 +++++++++---------- .../subtensor/src/transaction_extension.rs | 6 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pallets/subtensor/src/tests/mod.rs b/pallets/subtensor/src/tests/mod.rs index 76eb2cb4fb..f741e04152 100644 --- a/pallets/subtensor/src/tests/mod.rs +++ b/pallets/subtensor/src/tests/mod.rs @@ -29,6 +29,6 @@ mod subnet_emissions; mod swap_coldkey; mod swap_hotkey; mod swap_hotkey_with_subnet; +mod tx_extension; mod uids; mod weights; -mod tx_extension; diff --git a/pallets/subtensor/src/tests/tx_extension.rs b/pallets/subtensor/src/tests/tx_extension.rs index 5876d4ddd5..2a34b045e4 100644 --- a/pallets/subtensor/src/tests/tx_extension.rs +++ b/pallets/subtensor/src/tests/tx_extension.rs @@ -1,10 +1,10 @@ +use crate::tests::mock::{RuntimeCall, RuntimeOrigin, SubtensorCall, new_test_ext}; +use crate::transaction_extension::SubtensorTransactionExtension; use frame_support::assert_ok; use frame_support::dispatch::GetDispatchInfo; -use crate::tests::mock::{new_test_ext, RuntimeCall, RuntimeOrigin, SubtensorCall}; -use subtensor_runtime_common::{NetUid, TaoCurrency}; use sp_core::U256; use sp_runtime::traits::{TransactionExtension, TxBaseImplication, ValidateResult}; -use crate::transaction_extension::SubtensorTransactionExtension; +use subtensor_runtime_common::{NetUid, TaoCurrency}; use super::mock::*; use crate::*; @@ -65,12 +65,12 @@ fn sudo_signed_by_wrong_account_is_rejected() { // Wrong signer let origin = RuntimeOrigin::signed(U256::from(99)); let res = validate_ext(origin, &sudo_call); - assert!( - matches!( - res, - Err(TransactionValidityError::Invalid(InvalidTransaction::BadSigner)) - ) - ); + assert!(matches!( + res, + Err(TransactionValidityError::Invalid( + InvalidTransaction::BadSigner + )) + )); }); } @@ -82,12 +82,12 @@ fn sudo_when_no_sudo_key_configured_is_rejected() { let sudo_call = sudo_extrinsic(some_call()); let origin = RuntimeOrigin::signed(U256::from(42)); let res = validate_ext(origin, &sudo_call); - assert!( - matches!( - res, - Err(TransactionValidityError::Invalid(InvalidTransaction::BadSigner)) - ) - ); + assert!(matches!( + res, + Err(TransactionValidityError::Invalid( + InvalidTransaction::BadSigner + )) + )); }); } @@ -99,4 +99,4 @@ fn non_sudo_extrinsic_does_not_trigger_filter() { let res = validate_ext(origin, &call); assert!(res.is_ok()); }); -} \ No newline at end of file +} diff --git a/pallets/subtensor/src/transaction_extension.rs b/pallets/subtensor/src/transaction_extension.rs index efd4f21818..c2840af56a 100644 --- a/pallets/subtensor/src/transaction_extension.rs +++ b/pallets/subtensor/src/transaction_extension.rs @@ -6,16 +6,16 @@ use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; use frame_support::pallet_prelude::Weight; use frame_support::traits::IsSubType; +use pallet_sudo::Call as SudoCall; use scale_info::TypeInfo; use sp_runtime::traits::{ AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Implication, TransactionExtension, ValidateResult, }; use sp_runtime::transaction_validity::{ - TransactionSource, TransactionValidity, TransactionValidityError, ValidTransaction, - InvalidTransaction + InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, + ValidTransaction, }; -use pallet_sudo::Call as SudoCall; use sp_std::marker::PhantomData; use sp_std::vec::Vec; use subtensor_macros::freeze_struct; From 181ffd8338d855be1e71f0026ee365f68d5bdcd0 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Thu, 11 Dec 2025 16:06:28 +0100 Subject: [PATCH 05/11] Move sudo filter into the separate Transaction Extension --- Cargo.lock | 1 - node/src/benchmarking.rs | 4 +- node/src/mev_shield/author.rs | 2 + pallets/subtensor/Cargo.toml | 4 - pallets/subtensor/src/tests/mock.rs | 7 -- pallets/subtensor/src/tests/mod.rs | 1 - pallets/subtensor/src/tests/tx_extension.rs | 102 ----------------- .../subtensor/src/transaction_extension.rs | 22 +--- runtime/src/lib.rs | 4 + runtime/src/sudo_wrapper.rs | 92 +++++++++++++++ runtime/tests/sudo_wrapper.rs | 108 ++++++++++++++++++ 11 files changed, 211 insertions(+), 136 deletions(-) delete mode 100644 pallets/subtensor/src/tests/tx_extension.rs create mode 100644 runtime/src/sudo_wrapper.rs create mode 100644 runtime/tests/sudo_wrapper.rs diff --git a/Cargo.lock b/Cargo.lock index 5476a27b32..4b32cbe31a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10784,7 +10784,6 @@ dependencies = [ "pallet-subtensor-proxy", "pallet-subtensor-swap", "pallet-subtensor-utility", - "pallet-sudo", "pallet-transaction-payment", "parity-scale-codec", "polkadot-runtime-common", diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 4acece56f4..3bf7fa0138 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -5,7 +5,7 @@ use crate::client::FullClient; use node_subtensor_runtime as runtime; -use node_subtensor_runtime::pallet_subtensor; +use node_subtensor_runtime::{pallet_subtensor, sudo_wrapper}; use node_subtensor_runtime::{check_nonce, transaction_payment_wrapper}; use runtime::{BalancesCall, SystemCall}; use sc_cli::Result; @@ -136,6 +136,7 @@ pub fn create_benchmark_extrinsic( )), check_nonce::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), + sudo_wrapper::SudoTransactionExtension::::new(), transaction_payment_wrapper::ChargeTransactionPaymentWrapper::new( pallet_transaction_payment::ChargeTransactionPayment::::from(0), ), @@ -160,6 +161,7 @@ pub fn create_benchmark_extrinsic( (), (), (), + (), None, ), ); diff --git a/node/src/mev_shield/author.rs b/node/src/mev_shield/author.rs index 2f6c86f5df..2e9ae18cf4 100644 --- a/node/src/mev_shield/author.rs +++ b/node/src/mev_shield/author.rs @@ -374,6 +374,7 @@ where frame_system::CheckEra::::from(Era::Immortal), node_subtensor_runtime::check_nonce::CheckNonce::::from(nonce).into(), frame_system::CheckWeight::::new(), + node_subtensor_runtime::sudo_wrapper::SudoTransactionExtension::::new(), node_subtensor_runtime::transaction_payment_wrapper::ChargeTransactionPaymentWrapper::< runtime::Runtime, >::new(pallet_transaction_payment::ChargeTransactionPayment::< @@ -400,6 +401,7 @@ where genesis_h256, // CheckEra::Implicit (Immortal => genesis hash) (), // CheckNonce::Implicit = () (), // CheckWeight::Implicit = () + (), // SudoTransactionExtension::Implicit = () (), // ChargeTransactionPaymentWrapper::Implicit = () (), // SubtensorTransactionExtension::Implicit = () (), // DrandPriority::Implicit = () diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 84024c069d..2e35a89d19 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -55,7 +55,6 @@ sha2.workspace = true rand_chacha.workspace = true pallet-crowdloan.workspace = true pallet-subtensor-proxy.workspace = true -pallet-sudo.workspace = true [dev-dependencies] pallet-balances = { workspace = true, features = ["std"] } @@ -87,7 +86,6 @@ try-runtime = [ "pallet-commitments/try-runtime", "pallet-crowdloan/try-runtime", "pallet-drand/try-runtime", - "pallet-sudo/try-runtime", "pallet-subtensor-proxy/try-runtime", "pallet-subtensor-utility/try-runtime" ] @@ -119,7 +117,6 @@ std = [ "pallet-subtensor-swap/std", "subtensor-swap-interface/std", "pallet-subtensor-utility/std", - "pallet-sudo/std", "safe-math/std", "share-pool/std", "ark-serialize/std", @@ -148,7 +145,6 @@ runtime-benchmarks = [ "pallet-commitments/runtime-benchmarks", "pallet-crowdloan/runtime-benchmarks", "pallet-drand/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", "pallet-subtensor-proxy/runtime-benchmarks", "pallet-subtensor-swap/runtime-benchmarks", "pallet-subtensor-utility/runtime-benchmarks" diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index b8310f8b5d..090fcf8f75 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -47,7 +47,6 @@ frame_support::construct_runtime!( Swap: pallet_subtensor_swap::{Pallet, Call, Storage, Event} = 12, Crowdloan: pallet_crowdloan::{Pallet, Call, Storage, Event} = 13, Proxy: pallet_subtensor_proxy = 14, - Sudo: pallet_sudo::{Pallet, Call, Storage, Event} = 15, } ); @@ -472,12 +471,6 @@ impl InstanceFilter for subtensor_runtime_common::ProxyType { } } -impl pallet_sudo::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; - type WeightInfo = pallet_sudo::weights::SubstrateWeight; -} - mod test_crypto { use super::KEY_TYPE; use sp_core::{ diff --git a/pallets/subtensor/src/tests/mod.rs b/pallets/subtensor/src/tests/mod.rs index f741e04152..bbaf25af58 100644 --- a/pallets/subtensor/src/tests/mod.rs +++ b/pallets/subtensor/src/tests/mod.rs @@ -29,6 +29,5 @@ mod subnet_emissions; mod swap_coldkey; mod swap_hotkey; mod swap_hotkey_with_subnet; -mod tx_extension; mod uids; mod weights; diff --git a/pallets/subtensor/src/tests/tx_extension.rs b/pallets/subtensor/src/tests/tx_extension.rs deleted file mode 100644 index 2a34b045e4..0000000000 --- a/pallets/subtensor/src/tests/tx_extension.rs +++ /dev/null @@ -1,102 +0,0 @@ -use crate::tests::mock::{RuntimeCall, RuntimeOrigin, SubtensorCall, new_test_ext}; -use crate::transaction_extension::SubtensorTransactionExtension; -use frame_support::assert_ok; -use frame_support::dispatch::GetDispatchInfo; -use sp_core::U256; -use sp_runtime::traits::{TransactionExtension, TxBaseImplication, ValidateResult}; -use subtensor_runtime_common::{NetUid, TaoCurrency}; - -use super::mock::*; -use crate::*; - -fn some_call() -> RuntimeCall { - let hotkey = U256::from(0); - let amount_staked = TaoCurrency::from(5000); - let netuid = NetUid::from(1); - RuntimeCall::SubtensorModule(SubtensorCall::add_stake { - hotkey, - netuid, - amount_staked, - }) -} -fn sudo_extrinsic(inner: RuntimeCall) -> RuntimeCall { - RuntimeCall::Sudo(pallet_sudo::Call::sudo { - call: Box::new(inner), - }) -} - -fn validate_ext( - origin: RuntimeOrigin, - call: &RuntimeCall, -) -> ValidateResult::AccountId>, RuntimeCall> { - let ext = SubtensorTransactionExtension::::new(); - - ext.validate( - origin, - call, - &call.get_dispatch_info(), - 0, - (), - &TxBaseImplication(()), - TransactionSource::External, - ) -} -#[test] -fn sudo_signed_by_correct_key_is_valid() { - new_test_ext(1).execute_with(|| { - let sudo_key: ::AccountId = U256::from(42); - pallet_sudo::Key::::put(sudo_key); - let sudo_call = sudo_extrinsic(some_call()); - - // Signed origin with correct sudo key - let origin = RuntimeOrigin::signed(sudo_key); - let res = validate_ext(origin, &sudo_call); - assert_ok!(res); - }); -} - -#[test] -fn sudo_signed_by_wrong_account_is_rejected() { - new_test_ext(1).execute_with(|| { - let sudo_key: ::AccountId = U256::from(42); - // Set sudo key in storage - pallet_sudo::Key::::put(sudo_key); - let sudo_call = sudo_extrinsic(some_call()); - // Wrong signer - let origin = RuntimeOrigin::signed(U256::from(99)); - let res = validate_ext(origin, &sudo_call); - assert!(matches!( - res, - Err(TransactionValidityError::Invalid( - InvalidTransaction::BadSigner - )) - )); - }); -} - -#[test] -fn sudo_when_no_sudo_key_configured_is_rejected() { - new_test_ext(1).execute_with(|| { - // Remove sudo key - pallet_sudo::Key::::kill(); - let sudo_call = sudo_extrinsic(some_call()); - let origin = RuntimeOrigin::signed(U256::from(42)); - let res = validate_ext(origin, &sudo_call); - assert!(matches!( - res, - Err(TransactionValidityError::Invalid( - InvalidTransaction::BadSigner - )) - )); - }); -} - -#[test] -fn non_sudo_extrinsic_does_not_trigger_filter() { - new_test_ext(1).execute_with(|| { - let origin = RuntimeOrigin::signed(U256::from(42)); - let call = some_call(); - let res = validate_ext(origin, &call); - assert!(res.is_ok()); - }); -} diff --git a/pallets/subtensor/src/transaction_extension.rs b/pallets/subtensor/src/transaction_extension.rs index c2840af56a..cf1d410ea9 100644 --- a/pallets/subtensor/src/transaction_extension.rs +++ b/pallets/subtensor/src/transaction_extension.rs @@ -6,15 +6,13 @@ use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; use frame_support::pallet_prelude::Weight; use frame_support::traits::IsSubType; -use pallet_sudo::Call as SudoCall; use scale_info::TypeInfo; use sp_runtime::traits::{ AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Implication, TransactionExtension, ValidateResult, }; use sp_runtime::transaction_validity::{ - InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, - ValidTransaction, + TransactionSource, TransactionValidity, TransactionValidityError, ValidTransaction, }; use sp_std::marker::PhantomData; use sp_std::vec::Vec; @@ -87,7 +85,7 @@ where } } -impl +impl TransactionExtension<::RuntimeCall> for SubtensorTransactionExtension where @@ -96,7 +94,6 @@ where ::RuntimeOrigin: AsSystemOriginSigner + Clone, ::RuntimeCall: IsSubType>, ::RuntimeCall: IsSubType>, - ::RuntimeCall: IsSubType>, { const IDENTIFIER: &'static str = "SubtensorTransactionExtension"; @@ -124,21 +121,6 @@ where return Ok((Default::default(), None, origin)); }; - // Check validity of the signer for sudo call - if let Some(_sudo_call) = IsSubType::>::is_sub_type(call) { - let sudo_key = pallet_sudo::pallet::Key::::get(); - - // No sudo key configured → reject - let Some(expected_who) = sudo_key else { - return Err(InvalidTransaction::BadSigner.into()); - }; - - // Signer does not match the sudo key → reject - if *who != expected_who { - return Err(InvalidTransaction::BadSigner.into()); - } - } - // Verify ColdkeySwapScheduled map for coldkey match call.is_sub_type() { // Whitelist diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 35272d9817..0ec1ba362f 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -13,6 +13,7 @@ use core::num::NonZeroU64; pub mod check_nonce; mod migrations; pub mod transaction_payment_wrapper; +pub mod sudo_wrapper; extern crate alloc; @@ -170,6 +171,7 @@ impl frame_system::offchain::CreateSignedTransaction frame_system::CheckEra::::from(Era::Immortal), check_nonce::CheckNonce::::from(nonce).into(), frame_system::CheckWeight::::new(), + SudoTransactionExtension::::new(), ChargeTransactionPaymentWrapper::new( pallet_transaction_payment::ChargeTransactionPayment::::from(0), ), @@ -1160,6 +1162,7 @@ impl pallet_subtensor_swap::Config for Runtime { use crate::transaction_payment_wrapper::ChargeTransactionPaymentWrapper; use sp_runtime::BoundedVec; +use crate::sudo_wrapper::SudoTransactionExtension; pub struct AuraPalletIntrf; impl pallet_admin_utils::AuraInterface> for AuraPalletIntrf { @@ -1608,6 +1611,7 @@ pub type TransactionExtensions = ( frame_system::CheckEra, check_nonce::CheckNonce, frame_system::CheckWeight, + SudoTransactionExtension, ChargeTransactionPaymentWrapper, pallet_subtensor::transaction_extension::SubtensorTransactionExtension, pallet_drand::drand_priority::DrandPriority, diff --git a/runtime/src/sudo_wrapper.rs b/runtime/src/sudo_wrapper.rs new file mode 100644 index 0000000000..0792040c9d --- /dev/null +++ b/runtime/src/sudo_wrapper.rs @@ -0,0 +1,92 @@ +use sp_std::marker::PhantomData; +use codec::{Decode, DecodeWithMemTracking, Encode}; +use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; +use frame_support::traits::IsSubType; +use scale_info::TypeInfo; +use pallet_sudo::Call as SudoCall; +use sp_runtime::traits::{AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Implication, TransactionExtension, ValidateResult}; +use sp_runtime::transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidityError}; +use frame_system::Config; +use subtensor_macros::freeze_struct; +use frame_support::pallet_prelude::Weight; + +#[freeze_struct("99dce71278b36b44")] +#[derive(Default, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)] +pub struct SudoTransactionExtension(pub PhantomData); + +impl sp_std::fmt::Debug for SudoTransactionExtension { + #[cfg(feature = "std")] + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "SudoTransactionExtension",) + } + #[cfg(not(feature = "std"))] + fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result { + Ok(()) + } +} + +impl SudoTransactionExtension { + pub fn new() -> Self { + Self(Default::default()) + } +} + +impl TransactionExtension<::RuntimeCall> for SudoTransactionExtension +where + ::RuntimeCall:Dispatchable, + ::RuntimeOrigin: AsSystemOriginSigner + Clone, + ::RuntimeCall: IsSubType>, +{ + const IDENTIFIER: &'static str = "SudoTransactionExtension"; + + type Implicit = (); + type Val = Option; + type Pre = (); + + fn weight(&self, _call: &::RuntimeCall) -> Weight { + Weight::zero() + } + + fn validate( + &self, + origin: ::RuntimeOrigin, + call: &::RuntimeCall, + _info: &DispatchInfoOf<::RuntimeCall>, + _len: usize, + _self_implicit: Self::Implicit, + _inherited_implication: &impl Implication, + _source: TransactionSource, + ) -> ValidateResult::RuntimeCall> { + // Ensure the transaction is signed, else we just skip the extension. + let Some(who) = origin.as_system_origin_signer() else { + return Ok((Default::default(), None, origin)); + }; + + // Check validity of the signer for sudo call + if let Some(_sudo_call) = IsSubType::>::is_sub_type(call) { + let sudo_key = pallet_sudo::pallet::Key::::get(); + + // No sudo key configured → reject + let Some(expected_who) = sudo_key else { + return Err(InvalidTransaction::BadSigner.into()); + }; + + // Signer does not match the sudo key → reject + if *who != expected_who { + return Err(InvalidTransaction::BadSigner.into()); + } + } + + Ok((Default::default(), Some(who.clone()), origin)) + } + fn prepare( + self, + _val: Self::Val, + _origin: &::RuntimeOrigin, + _call: &::RuntimeCall, + _info: &DispatchInfoOf<::RuntimeCall>, + _len: usize, + ) -> Result { + Ok(()) + } +} diff --git a/runtime/tests/sudo_wrapper.rs b/runtime/tests/sudo_wrapper.rs new file mode 100644 index 0000000000..e8fa20792a --- /dev/null +++ b/runtime/tests/sudo_wrapper.rs @@ -0,0 +1,108 @@ +use frame_support::assert_ok; +use frame_support::dispatch::GetDispatchInfo; +use sp_runtime::traits::{TransactionExtension, TxBaseImplication, ValidateResult}; +use sp_runtime::transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidityError}; +use node_subtensor_runtime::{BuildStorage, RuntimeGenesisConfig, System, SystemCall, RuntimeCall, RuntimeOrigin, Runtime, sudo_wrapper}; +use subtensor_runtime_common::AccountId; + +const SUDO_ACCOUNT: [u8; 32] = [1_u8; 32]; +const OTHER_ACCOUNT: [u8; 32] = [3_u8; 32]; + +fn new_test_ext() -> sp_io::TestExternalities { + let mut ext: sp_io::TestExternalities = RuntimeGenesisConfig { + sudo: pallet_sudo::GenesisConfig { key: None }, + ..Default::default() + } + .build_storage() + .unwrap() + .into(); + ext.execute_with(|| System::set_block_number(1)); + ext +} + +fn call_remark() -> RuntimeCall { + let remark = vec![1, 2, 3]; + RuntimeCall::System(SystemCall::remark { remark }) +} + +fn sudo_extrinsic(inner: RuntimeCall) -> RuntimeCall { + RuntimeCall::Sudo(pallet_sudo::Call::sudo { + call: Box::new(inner), + }) +} + +fn validate_ext( + origin: RuntimeOrigin, + call: &RuntimeCall, +) -> ValidateResult, RuntimeCall> { + let ext = sudo_wrapper::SudoTransactionExtension::::new(); + + ext.validate( + origin, + call, + &call.get_dispatch_info(), + 0, + (), + &TxBaseImplication(()), + TransactionSource::External, + ) +} +#[test] +fn sudo_signed_by_correct_key_is_valid() { + new_test_ext().execute_with(|| { + let sudo_key = AccountId::from(SUDO_ACCOUNT); + pallet_sudo::Key::::put(sudo_key.clone()); + let sudo_call = sudo_extrinsic(call_remark()); + + // Signed origin with correct sudo key + let origin = RuntimeOrigin::signed(sudo_key); + let res = validate_ext(origin, &sudo_call); + assert_ok!(res); + }); +} + +#[test] +fn sudo_signed_by_wrong_account_is_rejected() { + new_test_ext().execute_with(|| { + let sudo_key = AccountId::from(SUDO_ACCOUNT); + // Set sudo key in storage + pallet_sudo::Key::::put(sudo_key.clone()); + let sudo_call = sudo_extrinsic(call_remark()); + // Wrong signer + let origin = RuntimeOrigin::signed(AccountId::from(OTHER_ACCOUNT)); + let res = validate_ext(origin, &sudo_call); + assert!(matches!( + res, + Err(TransactionValidityError::Invalid( + InvalidTransaction::BadSigner + )) + )); + }); +} + +#[test] +fn sudo_when_no_sudo_key_configured_is_rejected() { + new_test_ext().execute_with(|| { + // Remove sudo key + pallet_sudo::Key::::kill(); + let sudo_call = sudo_extrinsic(call_remark()); + let origin = RuntimeOrigin::signed(AccountId::from(SUDO_ACCOUNT)); + let res = validate_ext(origin, &sudo_call); + assert!(matches!( + res, + Err(TransactionValidityError::Invalid( + InvalidTransaction::BadSigner + )) + )); + }); +} + +#[test] +fn non_sudo_extrinsic_does_not_trigger_filter() { + new_test_ext().execute_with(|| { + let origin = RuntimeOrigin::signed(AccountId::from(OTHER_ACCOUNT)); + let call = call_remark(); + let res = validate_ext(origin, &call); + assert!(res.is_ok()); + }); +} From a8e64a068b73a1cdf549c136adf6edbefccbfcca Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Thu, 11 Dec 2025 16:13:31 +0100 Subject: [PATCH 06/11] cargo fmt --- node/src/benchmarking.rs | 2 +- node/src/mev_shield/author.rs | 3 ++- runtime/src/lib.rs | 4 ++-- runtime/src/sudo_wrapper.rs | 22 ++++++++++++++-------- runtime/tests/sudo_wrapper.rs | 9 +++++++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 3bf7fa0138..295fd172f6 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -5,8 +5,8 @@ use crate::client::FullClient; use node_subtensor_runtime as runtime; -use node_subtensor_runtime::{pallet_subtensor, sudo_wrapper}; use node_subtensor_runtime::{check_nonce, transaction_payment_wrapper}; +use node_subtensor_runtime::{pallet_subtensor, sudo_wrapper}; use runtime::{BalancesCall, SystemCall}; use sc_cli::Result; use sc_client_api::BlockBackend; diff --git a/node/src/mev_shield/author.rs b/node/src/mev_shield/author.rs index 2e9ae18cf4..c266a6981a 100644 --- a/node/src/mev_shield/author.rs +++ b/node/src/mev_shield/author.rs @@ -374,7 +374,8 @@ where frame_system::CheckEra::::from(Era::Immortal), node_subtensor_runtime::check_nonce::CheckNonce::::from(nonce).into(), frame_system::CheckWeight::::new(), - node_subtensor_runtime::sudo_wrapper::SudoTransactionExtension::::new(), + node_subtensor_runtime::sudo_wrapper::SudoTransactionExtension::::new( + ), node_subtensor_runtime::transaction_payment_wrapper::ChargeTransactionPaymentWrapper::< runtime::Runtime, >::new(pallet_transaction_payment::ChargeTransactionPayment::< diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 0ec1ba362f..47b0862d8b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -12,8 +12,8 @@ use core::num::NonZeroU64; pub mod check_nonce; mod migrations; -pub mod transaction_payment_wrapper; pub mod sudo_wrapper; +pub mod transaction_payment_wrapper; extern crate alloc; @@ -1160,9 +1160,9 @@ impl pallet_subtensor_swap::Config for Runtime { type WeightInfo = pallet_subtensor_swap::weights::DefaultWeight; } +use crate::sudo_wrapper::SudoTransactionExtension; use crate::transaction_payment_wrapper::ChargeTransactionPaymentWrapper; use sp_runtime::BoundedVec; -use crate::sudo_wrapper::SudoTransactionExtension; pub struct AuraPalletIntrf; impl pallet_admin_utils::AuraInterface> for AuraPalletIntrf { diff --git a/runtime/src/sudo_wrapper.rs b/runtime/src/sudo_wrapper.rs index 0792040c9d..cf23a0c1de 100644 --- a/runtime/src/sudo_wrapper.rs +++ b/runtime/src/sudo_wrapper.rs @@ -1,14 +1,19 @@ -use sp_std::marker::PhantomData; use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; +use frame_support::pallet_prelude::Weight; use frame_support::traits::IsSubType; -use scale_info::TypeInfo; -use pallet_sudo::Call as SudoCall; -use sp_runtime::traits::{AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Implication, TransactionExtension, ValidateResult}; -use sp_runtime::transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidityError}; use frame_system::Config; +use pallet_sudo::Call as SudoCall; +use scale_info::TypeInfo; +use sp_runtime::traits::{ + AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Implication, TransactionExtension, + ValidateResult, +}; +use sp_runtime::transaction_validity::{ + InvalidTransaction, TransactionSource, TransactionValidityError, +}; +use sp_std::marker::PhantomData; use subtensor_macros::freeze_struct; -use frame_support::pallet_prelude::Weight; #[freeze_struct("99dce71278b36b44")] #[derive(Default, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)] @@ -31,9 +36,10 @@ impl SudoTransactionExtension { } } -impl TransactionExtension<::RuntimeCall> for SudoTransactionExtension +impl + TransactionExtension<::RuntimeCall> for SudoTransactionExtension where - ::RuntimeCall:Dispatchable, + ::RuntimeCall: Dispatchable, ::RuntimeOrigin: AsSystemOriginSigner + Clone, ::RuntimeCall: IsSubType>, { diff --git a/runtime/tests/sudo_wrapper.rs b/runtime/tests/sudo_wrapper.rs index e8fa20792a..7a7a1c6362 100644 --- a/runtime/tests/sudo_wrapper.rs +++ b/runtime/tests/sudo_wrapper.rs @@ -1,8 +1,13 @@ use frame_support::assert_ok; use frame_support::dispatch::GetDispatchInfo; +use node_subtensor_runtime::{ + BuildStorage, Runtime, RuntimeCall, RuntimeGenesisConfig, RuntimeOrigin, System, SystemCall, + sudo_wrapper, +}; use sp_runtime::traits::{TransactionExtension, TxBaseImplication, ValidateResult}; -use sp_runtime::transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidityError}; -use node_subtensor_runtime::{BuildStorage, RuntimeGenesisConfig, System, SystemCall, RuntimeCall, RuntimeOrigin, Runtime, sudo_wrapper}; +use sp_runtime::transaction_validity::{ + InvalidTransaction, TransactionSource, TransactionValidityError, +}; use subtensor_runtime_common::AccountId; const SUDO_ACCOUNT: [u8; 32] = [1_u8; 32]; From 84e2ba62ed45e5c4a413d988de8e3667e41426e8 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Thu, 11 Dec 2025 17:30:43 +0100 Subject: [PATCH 07/11] Fix clippy --- runtime/tests/sudo_wrapper.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/tests/sudo_wrapper.rs b/runtime/tests/sudo_wrapper.rs index 7a7a1c6362..0869fbcd0d 100644 --- a/runtime/tests/sudo_wrapper.rs +++ b/runtime/tests/sudo_wrapper.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unwrap_used)] + use frame_support::assert_ok; use frame_support::dispatch::GetDispatchInfo; use node_subtensor_runtime::{ From 1fa82ddb78b1c705f75b3392a8d1db99999fd702 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Sat, 13 Dec 2025 14:58:56 +0100 Subject: [PATCH 08/11] Change order for tx extension --- node/src/benchmarking.rs | 2 +- node/src/mev_shield/author.rs | 6 +++--- runtime/src/lib.rs | 4 ++-- runtime/src/sudo_wrapper.rs | 20 +++----------------- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 295fd172f6..5430a75d9e 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -136,10 +136,10 @@ pub fn create_benchmark_extrinsic( )), check_nonce::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - sudo_wrapper::SudoTransactionExtension::::new(), transaction_payment_wrapper::ChargeTransactionPaymentWrapper::new( pallet_transaction_payment::ChargeTransactionPayment::::from(0), ), + sudo_wrapper::SudoTransactionExtension::::new(), pallet_subtensor::transaction_extension::SubtensorTransactionExtension::< runtime::Runtime, >::new(), diff --git a/node/src/mev_shield/author.rs b/node/src/mev_shield/author.rs index dec1ab0b1a..99000d4ac6 100644 --- a/node/src/mev_shield/author.rs +++ b/node/src/mev_shield/author.rs @@ -386,13 +386,13 @@ where frame_system::CheckEra::::from(era), node_subtensor_runtime::check_nonce::CheckNonce::::from(nonce).into(), frame_system::CheckWeight::::new(), - node_subtensor_runtime::sudo_wrapper::SudoTransactionExtension::::new( - ), node_subtensor_runtime::transaction_payment_wrapper::ChargeTransactionPaymentWrapper::< runtime::Runtime, >::new(pallet_transaction_payment::ChargeTransactionPayment::< runtime::Runtime, >::from(0u64)), + node_subtensor_runtime::sudo_wrapper::SudoTransactionExtension::::new( + ), pallet_subtensor::transaction_extension::SubtensorTransactionExtension::< runtime::Runtime, >::new(), @@ -428,8 +428,8 @@ where at_hash_h256, // CheckEra::Implicit = hash of the block the tx is created at (), // CheckNonce::Implicit = () (), // CheckWeight::Implicit = () - (), // SudoTransactionExtension::Implicit = () (), // ChargeTransactionPaymentWrapper::Implicit = () + (), // SudoTransactionExtension::Implicit = () (), // SubtensorTransactionExtension::Implicit = () (), // DrandPriority::Implicit = () None, // CheckMetadataHash::Implicit = Option<[u8; 32]> diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9e119ca1c1..60a740c3af 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -171,10 +171,10 @@ impl frame_system::offchain::CreateSignedTransaction frame_system::CheckEra::::from(Era::Immortal), check_nonce::CheckNonce::::from(nonce).into(), frame_system::CheckWeight::::new(), - SudoTransactionExtension::::new(), ChargeTransactionPaymentWrapper::new( pallet_transaction_payment::ChargeTransactionPayment::::from(0), ), + SudoTransactionExtension::::new(), pallet_subtensor::transaction_extension::SubtensorTransactionExtension::::new( ), pallet_drand::drand_priority::DrandPriority::::new(), @@ -1611,8 +1611,8 @@ pub type TransactionExtensions = ( frame_system::CheckEra, check_nonce::CheckNonce, frame_system::CheckWeight, - SudoTransactionExtension, ChargeTransactionPaymentWrapper, + SudoTransactionExtension, pallet_subtensor::transaction_extension::SubtensorTransactionExtension, pallet_drand::drand_priority::DrandPriority, frame_metadata_hash_extension::CheckMetadataHash, diff --git a/runtime/src/sudo_wrapper.rs b/runtime/src/sudo_wrapper.rs index cf23a0c1de..32e8e825fd 100644 --- a/runtime/src/sudo_wrapper.rs +++ b/runtime/src/sudo_wrapper.rs @@ -1,6 +1,5 @@ use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; -use frame_support::pallet_prelude::Weight; use frame_support::traits::IsSubType; use frame_system::Config; use pallet_sudo::Call as SudoCall; @@ -9,11 +8,10 @@ use sp_runtime::traits::{ AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Implication, TransactionExtension, ValidateResult, }; -use sp_runtime::transaction_validity::{ - InvalidTransaction, TransactionSource, TransactionValidityError, -}; +use sp_runtime::transaction_validity::{InvalidTransaction, TransactionSource}; use sp_std::marker::PhantomData; use subtensor_macros::freeze_struct; +use sp_runtime::impl_tx_ext_default; #[freeze_struct("99dce71278b36b44")] #[derive(Default, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)] @@ -49,9 +47,7 @@ where type Val = Option; type Pre = (); - fn weight(&self, _call: &::RuntimeCall) -> Weight { - Weight::zero() - } + impl_tx_ext_default!(::RuntimeCall; weight prepare); fn validate( &self, @@ -85,14 +81,4 @@ where Ok((Default::default(), Some(who.clone()), origin)) } - fn prepare( - self, - _val: Self::Val, - _origin: &::RuntimeOrigin, - _call: &::RuntimeCall, - _info: &DispatchInfoOf<::RuntimeCall>, - _len: usize, - ) -> Result { - Ok(()) - } } From 35ed4cf735347a08ecbfd791c49b3b1d3630a13c Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Sat, 13 Dec 2025 15:05:11 +0100 Subject: [PATCH 09/11] cargo fmt --- runtime/src/sudo_wrapper.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/sudo_wrapper.rs b/runtime/src/sudo_wrapper.rs index 32e8e825fd..9fc046ebfe 100644 --- a/runtime/src/sudo_wrapper.rs +++ b/runtime/src/sudo_wrapper.rs @@ -4,6 +4,7 @@ use frame_support::traits::IsSubType; use frame_system::Config; use pallet_sudo::Call as SudoCall; use scale_info::TypeInfo; +use sp_runtime::impl_tx_ext_default; use sp_runtime::traits::{ AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Implication, TransactionExtension, ValidateResult, @@ -11,7 +12,6 @@ use sp_runtime::traits::{ use sp_runtime::transaction_validity::{InvalidTransaction, TransactionSource}; use sp_std::marker::PhantomData; use subtensor_macros::freeze_struct; -use sp_runtime::impl_tx_ext_default; #[freeze_struct("99dce71278b36b44")] #[derive(Default, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)] From 19f99e5915f84558e9b20e7f73fb76213010cd5c Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Mon, 15 Dec 2025 15:22:06 +0100 Subject: [PATCH 10/11] Remove Val type --- runtime/src/sudo_wrapper.rs | 6 +++--- runtime/tests/sudo_wrapper.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/src/sudo_wrapper.rs b/runtime/src/sudo_wrapper.rs index 9fc046ebfe..154fbcb89d 100644 --- a/runtime/src/sudo_wrapper.rs +++ b/runtime/src/sudo_wrapper.rs @@ -44,7 +44,7 @@ where const IDENTIFIER: &'static str = "SudoTransactionExtension"; type Implicit = (); - type Val = Option; + type Val = (); type Pre = (); impl_tx_ext_default!(::RuntimeCall; weight prepare); @@ -61,7 +61,7 @@ where ) -> ValidateResult::RuntimeCall> { // Ensure the transaction is signed, else we just skip the extension. let Some(who) = origin.as_system_origin_signer() else { - return Ok((Default::default(), None, origin)); + return Ok((Default::default(), (), origin)); }; // Check validity of the signer for sudo call @@ -79,6 +79,6 @@ where } } - Ok((Default::default(), Some(who.clone()), origin)) + Ok((Default::default(), (), origin)) } } diff --git a/runtime/tests/sudo_wrapper.rs b/runtime/tests/sudo_wrapper.rs index 0869fbcd0d..bd47b6df35 100644 --- a/runtime/tests/sudo_wrapper.rs +++ b/runtime/tests/sudo_wrapper.rs @@ -41,7 +41,7 @@ fn sudo_extrinsic(inner: RuntimeCall) -> RuntimeCall { fn validate_ext( origin: RuntimeOrigin, call: &RuntimeCall, -) -> ValidateResult, RuntimeCall> { +) -> ValidateResult<(), RuntimeCall> { let ext = sudo_wrapper::SudoTransactionExtension::::new(); ext.validate( From 1f59643d06b9d4225a2804d3cdba106e072c33c9 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Mon, 15 Dec 2025 17:25:34 +0100 Subject: [PATCH 11/11] cargo fmt --- runtime/tests/sudo_wrapper.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/runtime/tests/sudo_wrapper.rs b/runtime/tests/sudo_wrapper.rs index bd47b6df35..bdcd17bd6e 100644 --- a/runtime/tests/sudo_wrapper.rs +++ b/runtime/tests/sudo_wrapper.rs @@ -38,10 +38,7 @@ fn sudo_extrinsic(inner: RuntimeCall) -> RuntimeCall { }) } -fn validate_ext( - origin: RuntimeOrigin, - call: &RuntimeCall, -) -> ValidateResult<(), RuntimeCall> { +fn validate_ext(origin: RuntimeOrigin, call: &RuntimeCall) -> ValidateResult<(), RuntimeCall> { let ext = sudo_wrapper::SudoTransactionExtension::::new(); ext.validate(