Skip to content
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
822 changes: 413 additions & 409 deletions Cargo.lock

Large diffs are not rendered by default.

270 changes: 135 additions & 135 deletions Cargo.toml

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions eco-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ useless_conversion = "allow"

[dependencies]
pallet-subtensor = { path = "../pallets/subtensor", default-features = false, features = ["std"] }
frame-support = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
frame-system = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
sp-core = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
sp-io = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
sp-runtime = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
sp-std = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
frame-support = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
frame-system = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
sp-core = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
sp-io = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
sp-runtime = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
sp-std = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
codec = { package = "parity-scale-codec", version = "3.7.5", default-features = false, features = ["derive", "std"] }
scale-info = { version = "2.11.2", default-features = false, features = ["derive", "std"] }
pallet-balances = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
pallet-scheduler = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
pallet-preimage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
pallet-balances = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
pallet-scheduler = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
pallet-preimage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
pallet-drand = { path = "../pallets/drand", default-features = false, features = ["std"] }
pallet-subtensor-swap = { path = "../pallets/swap", default-features = false, features = ["std"] }
pallet-crowdloan = { path = "../pallets/crowdloan", default-features = false, features = ["std"] }
Expand All @@ -42,7 +42,7 @@ share-pool = { path = "../primitives/share-pool", default-features = false, feat
safe-math = { path = "../primitives/safe-math", default-features = false, features = ["std"] }
log = { version = "0.4.21", default-features = false, features = ["std"] }
approx = "0.5"
sp-tracing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "fb1dd20df37710800aa284ac49bb26193d5539ee", default-features = false, features = ["std"] }
sp-tracing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "285b4f8b392c517e50e237e717d28ea4f3666e7c", default-features = false, features = ["std"] }
tracing = "0.1"
tracing-log = "0.2"
tracing-subscriber = { version = "=0.3.18", features = ["fmt", "env-filter"] }
Expand Down
2 changes: 1 addition & 1 deletion eco-tests/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl system::Config for Test {
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
type DispatchGuard = pallet_subtensor::CheckColdkeySwap<Test>;
type DispatchExtension = pallet_subtensor::CheckColdkeySwap<Test>;
}

parameter_types! {
Expand Down
40 changes: 25 additions & 15 deletions pallets/subtensor/src/guards/check_coldkey_swap.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
use crate::{Call, ColdkeySwapAnnouncements, ColdkeySwapDisputes, Config, Error};
use frame_support::dispatch::{
DispatchGuard, DispatchInfo, DispatchResultWithPostInfo, PostDispatchInfo,
use frame_support::{
dispatch::{DispatchErrorWithPostInfo, DispatchExtension, DispatchInfo, PostDispatchInfo},
pallet_prelude::*,
traits::{IsSubType, OriginTrait},
};
use frame_support::traits::{IsSubType, OriginTrait};
use sp_runtime::traits::Dispatchable;
use sp_std::marker::PhantomData;

type CallOf<T> = <T as frame_system::Config>::RuntimeCall;
type DispatchableOriginOf<T> = <CallOf<T> as Dispatchable>::RuntimeOrigin;

/// Dispatch guard that blocks most calls when a coldkey swap is active.
/// Dispatch extension that blocks most calls when a coldkey swap is active.
///
/// When a coldkey swap has been announced for the signing account:
/// - If the swap is disputed, ALL calls are blocked.
/// - Otherwise, only swap-related calls and MEV-protected calls (`submit_encrypted`)
/// are allowed through.
///
/// Root origin bypasses this guard entirely (handled by `check_dispatch_guard`).
/// Root origin bypasses this extension entirely.
/// Non-signed origins pass through.
///
/// Because this is a `DispatchGuard` (not a `TransactionExtension`), it fires at every
/// Because this is a `DispatchExtension` (not a `TransactionExtension`), it fires at every
/// `call.dispatch(origin)` site — including inside the proxy pallet's `do_proxy()`.
/// This means nested proxies of any depth are handled automatically with the real
/// resolved origin.
pub struct CheckColdkeySwap<T: Config>(PhantomData<T>);

impl<T> DispatchGuard<<T as frame_system::Config>::RuntimeCall> for CheckColdkeySwap<T>
impl<T> DispatchExtension<<T as frame_system::Config>::RuntimeCall> for CheckColdkeySwap<T>
where
T: Config + pallet_shield::Config,
<T as frame_system::Config>::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
+ IsSubType<Call<T>>
+ IsSubType<pallet_shield::Call<T>>,
DispatchableOriginOf<T>: OriginTrait<AccountId = T::AccountId>,
{
fn check(origin: &DispatchableOriginOf<T>, call: &CallOf<T>) -> DispatchResultWithPostInfo {
type Pre = ();

fn weight(_call: &CallOf<T>) -> Weight {
T::DbWeight::get().reads(2)
}

fn pre_dispatch(
origin: &DispatchableOriginOf<T>,
call: &CallOf<T>,
) -> Result<Self::Pre, DispatchErrorWithPostInfo> {
// Only care about signed origins.
// Root is already bypassed by check_dispatch_guard() before we get here.
// Root is already bypassed by the extension before we get here.
let Some(who) = origin.as_signer() else {
return Ok(().into());
return Ok(());
};

if ColdkeySwapAnnouncements::<T>::contains_key(who) {
Expand Down Expand Up @@ -65,7 +75,7 @@ where
}
}

Ok(().into())
Ok(())
}
}

Expand Down Expand Up @@ -108,7 +118,7 @@ mod tests {
]
}

/// Calls that should be allowed through the guard during an active (undisputed) swap.
/// Calls that should be allowed through the extension during an active (undisputed) swap.
fn authorized_calls() -> Vec<RuntimeCall> {
vec![
RuntimeCall::SubtensorModule(crate::Call::announce_coldkey_swap {
Expand Down Expand Up @@ -148,7 +158,7 @@ mod tests {
}

#[test]
fn none_bypasses_guard() {
fn none_bypasses_extension() {
new_test_ext(1).execute_with(|| {
let who = U256::from(1);
setup_swap_disputed(&who);
Expand All @@ -158,7 +168,7 @@ mod tests {
}

#[test]
fn root_bypasses_guard() {
fn root_bypasses_extension() {
new_test_ext(1).execute_with(|| {
let who = U256::from(1);
setup_swap_disputed(&who);
Expand Down Expand Up @@ -193,7 +203,7 @@ mod tests {
assert_ne!(
err.error,
Error::<Test>::ColdkeySwapAnnounced.into(),
"Authorized call should not be blocked by the guard"
"Authorized call should not be blocked by the extension"
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl system::Config for Test {
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
type DispatchGuard = crate::CheckColdkeySwap<Test>;
type DispatchExtension = crate::CheckColdkeySwap<Test>;
}

parameter_types! {
Expand Down
26 changes: 1 addition & 25 deletions pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(clippy::arithmetic_side_effects)]

use approx::assert_abs_diff_eq;
use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays};
use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays};
use frame_support::sp_runtime::DispatchError;
use frame_support::{assert_err, assert_noop, assert_ok, traits::Currency};
use frame_system::RawOrigin;
Expand Down Expand Up @@ -364,30 +364,6 @@ fn test_add_stake_total_issuance_no_change() {
});
}

#[test]
fn test_remove_stake_dispatch_info_ok() {
new_test_ext(1).execute_with(|| {
let hotkey = U256::from(0);
let amount_unstaked = AlphaBalance::from(5000);
let netuid = NetUid::from(1);
let call = RuntimeCall::SubtensorModule(SubtensorCall::remove_stake {
hotkey,
netuid,
amount_unstaked,
});
assert_eq!(
call.get_dispatch_info(),
DispatchInfo {
call_weight: frame_support::weights::Weight::from_parts(1_671_800_000, 0)
.add_proof_size(0),
extension_weight: frame_support::weights::Weight::zero(),
class: DispatchClass::Normal,
pays_fee: Pays::Yes
}
);
});
}

#[test]
fn test_remove_stake_ok_no_emission() {
new_test_ext(1).execute_with(|| {
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,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: 394,
spec_version: 395,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -381,7 +381,7 @@ impl frame_system::Config for Runtime {
type PostInherents = ();
type PostTransactions = ();
type ExtensionsWeightInfo = frame_system::SubstrateExtensionsWeight<Runtime>;
type DispatchGuard = pallet_subtensor::CheckColdkeySwap<Runtime>;
type DispatchExtension = pallet_subtensor::CheckColdkeySwap<Runtime>;
}

impl pallet_insecure_randomness_collective_flip::Config for Runtime {}
Expand Down
Loading