From 107824312f0701aad6f95980554cd222d2b29f41 Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Tue, 19 Aug 2025 14:34:49 +0300 Subject: [PATCH 1/3] Refactor transaction extension --- pallets/subtensor/src/tests/swap_coldkey.rs | 30 ++++++- .../subtensor/src/transaction_extension.rs | 79 +++---------------- 2 files changed, 38 insertions(+), 71 deletions(-) diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 54bdc253ce..59792d5602 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -2493,8 +2493,12 @@ fn test_coldkey_in_swap_schedule_prevents_funds_usage() { &TxBaseImplication(()), TransactionSource::External, ); - // Should pass, not in list. - assert_ok!(result); + // Should fail + assert_eq!( + // Should get an invalid transaction error + result.unwrap_err(), + CustomTransactionError::ColdkeyInSwapSchedule.into() + ); // Remove stake limit let call = RuntimeCall::SubtensorModule(SubtensorCall::remove_stake_limit { @@ -2513,7 +2517,27 @@ fn test_coldkey_in_swap_schedule_prevents_funds_usage() { &TxBaseImplication(()), TransactionSource::External, ); - // Should pass, not in list. + // Should fail + assert_eq!( + // Should get an invalid transaction error + result.unwrap_err(), + CustomTransactionError::ColdkeyInSwapSchedule.into() + ); + + // Schedule swap should succeed + let call = RuntimeCall::SubtensorModule(SubtensorCall::schedule_swap_coldkey { + new_coldkey: hotkey, + }); + let result = extension.validate( + RawOrigin::Signed(who).into(), + &call.clone(), + &info, + 10, + (), + &TxBaseImplication(()), + TransactionSource::External, + ); + // Should be ok assert_ok!(result); }); } diff --git a/pallets/subtensor/src/transaction_extension.rs b/pallets/subtensor/src/transaction_extension.rs index deb42efabf..99749032ad 100644 --- a/pallets/subtensor/src/transaction_extension.rs +++ b/pallets/subtensor/src/transaction_extension.rs @@ -120,6 +120,16 @@ where return Ok((Default::default(), None, origin)); }; + // Verify ColdkeySwapScheduled map for coldkey + match call.is_sub_type() { + // Whitelist + Some(Call::schedule_swap_coldkey { .. }) => {} + _ => { + if ColdkeySwapScheduled::::contains_key(who) { + return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); + } + } + } match call.is_sub_type() { Some(Call::commit_weights { netuid, .. }) => { if Self::check_weights_min_stake(who, *netuid) { @@ -248,54 +258,7 @@ where Err(CustomTransactionError::StakeAmountTooLow.into()) } } - Some(Call::add_stake { .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - - Ok((Default::default(), Some(who.clone()), origin)) - } - Some(Call::add_stake_limit { .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - - Ok((Default::default(), Some(who.clone()), origin)) - } - Some(Call::remove_stake { .. }) => Ok((Default::default(), Some(who.clone()), origin)), - Some(Call::remove_stake_limit { .. }) => { - Ok((Default::default(), Some(who.clone()), origin)) - } - Some(Call::move_stake { .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - Ok((Default::default(), Some(who.clone()), origin)) - } - Some(Call::transfer_stake { .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - - Ok((Default::default(), Some(who.clone()), origin)) - } - Some(Call::swap_stake { .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - Ok((Default::default(), Some(who.clone()), origin)) - } - Some(Call::swap_stake_limit { .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - Ok((Default::default(), Some(who.clone()), origin)) - } Some(Call::register { netuid, .. } | Call::burned_register { netuid, .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - let registrations_this_interval = Pallet::::get_registrations_this_interval(*netuid); let max_registrations_per_interval = @@ -308,13 +271,6 @@ where Ok((Default::default(), Some(who.clone()), origin)) } - Some(Call::dissolve_network { .. }) => { - if ColdkeySwapScheduled::::contains_key(who) { - Err(CustomTransactionError::ColdkeyInSwapSchedule.into()) - } else { - Ok((Default::default(), Some(who.clone()), origin)) - } - } Some(Call::serve_axon { netuid, version, @@ -342,20 +298,7 @@ where ) .map(|validity| (validity, Some(who.clone()), origin.clone())) } - _ => { - if let Some( - BalancesCall::transfer_keep_alive { .. } - | BalancesCall::transfer_all { .. } - | BalancesCall::transfer_allow_death { .. }, - ) = call.is_sub_type() - { - if ColdkeySwapScheduled::::contains_key(who) { - return Err(CustomTransactionError::ColdkeyInSwapSchedule.into()); - } - } - - Ok((Default::default(), Some(who.clone()), origin)) - } + _ => Ok((Default::default(), Some(who.clone()), origin)), } } From 5be820e41d4fe9bc044bbfba94ece41959afa4a8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 19 Aug 2025 16:19:11 +0000 Subject: [PATCH 2/3] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index aea2eac3f7..13169e2599 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -693,7 +693,7 @@ mod dispatches { /// - Attempting to set prometheus information withing the rate limit min. /// #[pallet::call_index(4)] - #[pallet::weight((Weight::from_parts(43_680_000, 0) + #[pallet::weight((Weight::from_parts(33_780_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_axon( @@ -2156,7 +2156,7 @@ mod dispatches { /// Emits a `SymbolUpdated` event on success. #[pallet::call_index(112)] #[pallet::weight(( - Weight::from_parts(26_880_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), + Weight::from_parts(35_510_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), DispatchClass::Operational, Pays::Yes ))] @@ -2201,7 +2201,7 @@ mod dispatches { /// * commit_reveal_version (`u16`): /// - The client (bittensor-drand) version #[pallet::call_index(113)] - #[pallet::weight((Weight::from_parts(81_920_000, 0) + #[pallet::weight((Weight::from_parts(64_220_000, 0) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_timelocked_weights( From bf552a3d39b01cf219e8964f4a036321514f67a9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 22 Aug 2025 16:02:25 +0000 Subject: [PATCH 3/3] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 819fe53c1f..aed0c150de 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2156,7 +2156,7 @@ mod dispatches { /// Emits a `SymbolUpdated` event on success. #[pallet::call_index(112)] #[pallet::weight(( - Weight::from_parts(35_510_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), + Weight::from_parts(26_200_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), DispatchClass::Operational, Pays::Yes ))]