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
5 changes: 0 additions & 5 deletions chain-extensions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,6 @@ pub fn add_dynamic_network(hotkey: &U256, coldkey: &U256) -> NetUid {
netuid
}

#[allow(dead_code)]
pub(crate) fn remove_stake_rate_limit_for_tests(hotkey: &U256, coldkey: &U256, netuid: NetUid) {
StakingOperationRateLimiter::<Test>::remove((hotkey, coldkey, netuid));
}

#[allow(dead_code)]
pub(crate) fn setup_reserves(netuid: NetUid, tao: TaoBalance, alpha: AlphaBalance) {
SubnetTAO::<Test>::set(netuid, tao);
Expand Down
32 changes: 0 additions & 32 deletions chain-extensions/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ fn remove_stake_full_limit_success_with_limit_price() {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let expected_weight = <<mock::Test as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::remove_stake_full_limit();

let balance_before = pallet_subtensor::Pallet::<mock::Test>::get_coldkey_balance(&coldkey);
Expand Down Expand Up @@ -170,8 +168,6 @@ fn swap_stake_limit_with_tight_price_returns_slippage_error() {
stake_alpha,
);

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid_a);

let alpha_origin_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey, &coldkey, netuid_a,
Expand Down Expand Up @@ -241,8 +237,6 @@ fn remove_stake_limit_success_respects_price_limit() {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let alpha_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey, &coldkey, netuid,
Expand Down Expand Up @@ -382,8 +376,6 @@ fn swap_stake_success_moves_between_subnets() {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid_a);

let alpha_origin_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey, &coldkey, netuid_a,
Expand Down Expand Up @@ -454,8 +446,6 @@ fn transfer_stake_success_moves_between_coldkeys() {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &origin_coldkey, netuid);

let alpha_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey,
Expand Down Expand Up @@ -533,8 +523,6 @@ fn move_stake_success_moves_alpha_between_hotkeys() {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&origin_hotkey, &coldkey, netuid);

let alpha_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&origin_hotkey,
Expand Down Expand Up @@ -608,8 +596,6 @@ fn unstake_all_alpha_success_moves_stake_to_root() {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let expected_weight = <<mock::Test as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::unstake_all_alpha();

let mut env = MockEnv::new(FunctionId::UnstakeAllAlphaV1, coldkey, hotkey.encode())
Expand Down Expand Up @@ -1579,8 +1565,6 @@ fn unstake_all_success_unstakes_balance() {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let expected_weight = <<mock::Test as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::unstake_all();

let pre_balance = pallet_subtensor::Pallet::<mock::Test>::get_coldkey_balance(&coldkey);
Expand Down Expand Up @@ -1752,8 +1736,6 @@ mod caller_dispatch_tests {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let expected_weight = <<mock::Test as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::unstake_all();

let pre_balance = pallet_subtensor::Pallet::<mock::Test>::get_coldkey_balance(&coldkey);
Expand Down Expand Up @@ -1806,8 +1788,6 @@ mod caller_dispatch_tests {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let expected_weight = <<mock::Test as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::unstake_all_alpha();

let mut env = MockEnv::new(
Expand Down Expand Up @@ -1870,8 +1850,6 @@ mod caller_dispatch_tests {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&origin_hotkey, &coldkey, netuid);

let alpha_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&origin_hotkey,
Expand Down Expand Up @@ -1950,8 +1928,6 @@ mod caller_dispatch_tests {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &origin_coldkey, netuid);

let alpha_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey,
Expand Down Expand Up @@ -2039,8 +2015,6 @@ mod caller_dispatch_tests {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid_a);

let alpha_origin_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey, &coldkey, netuid_a,
Expand Down Expand Up @@ -2171,8 +2145,6 @@ mod caller_dispatch_tests {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let alpha_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey, &coldkey, netuid,
Expand Down Expand Up @@ -2251,8 +2223,6 @@ mod caller_dispatch_tests {
stake_alpha,
);

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid_a);

let alpha_origin_before =
pallet_subtensor::Pallet::<mock::Test>::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey, &coldkey, netuid_a,
Expand Down Expand Up @@ -2321,8 +2291,6 @@ mod caller_dispatch_tests {
stake_amount_raw.into(),
));

mock::remove_stake_rate_limit_for_tests(&hotkey, &coldkey, netuid);

let expected_weight = <<mock::Test as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::remove_stake_full_limit();

let balance_before =
Expand Down
4 changes: 0 additions & 4 deletions eco-tests/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,6 @@ pub fn increase_stake_on_hotkey_account(hotkey: &U256, increment: TaoBalance, ne
);
}

pub fn remove_stake_rate_limit_for_tests(hotkey: &U256, coldkey: &U256, netuid: NetUid) {
StakingOperationRateLimiter::<Test>::remove((hotkey, coldkey, netuid));
}

pub fn setup_reserves(netuid: NetUid, tao: TaoBalance, alpha: AlphaBalance) {
SubnetTAO::<Test>::set(netuid, tao);
SubnetAlphaIn::<Test>::set(netuid, alpha);
Expand Down
16 changes: 0 additions & 16 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,6 @@ mod pallet_benchmarks {

let _ = Subtensor::<T>::create_account_if_non_existent(&coldkey, &destination);

StakingOperationRateLimiter::<T>::remove((origin.clone(), coldkey.clone(), netuid));

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
Expand Down Expand Up @@ -991,8 +989,6 @@ mod pallet_benchmarks {

let amount_unstaked = AlphaBalance::from(30_000_000_000_u64);

StakingOperationRateLimiter::<T>::remove((hotkey.clone(), coldkey.clone(), netuid));

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
Expand Down Expand Up @@ -1053,8 +1049,6 @@ mod pallet_benchmarks {
.saturating_to_num::<u64>()
.into();

StakingOperationRateLimiter::<T>::remove((hotkey.clone(), coldkey.clone(), netuid));

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
Expand Down Expand Up @@ -1118,8 +1112,6 @@ mod pallet_benchmarks {
allow
));

StakingOperationRateLimiter::<T>::remove((hot.clone(), coldkey.clone(), netuid1));

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
Expand Down Expand Up @@ -1172,8 +1164,6 @@ mod pallet_benchmarks {

let _ = Subtensor::<T>::create_account_if_non_existent(&dest, &hot);

StakingOperationRateLimiter::<T>::remove((hot.clone(), coldkey.clone(), netuid));

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
Expand Down Expand Up @@ -1229,8 +1219,6 @@ mod pallet_benchmarks {
let alpha_to_swap =
Subtensor::<T>::get_stake_for_hotkey_and_coldkey_on_subnet(&hot, &coldkey, netuid1);

StakingOperationRateLimiter::<T>::remove((hot.clone(), coldkey.clone(), netuid1));

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
Expand Down Expand Up @@ -1584,8 +1572,6 @@ mod pallet_benchmarks {
staked_amt
));

StakingOperationRateLimiter::<T>::remove((hotkey.clone(), coldkey.clone(), netuid));

#[extrinsic_call]
_(RawOrigin::Signed(coldkey), hotkey);
}
Expand Down Expand Up @@ -1640,8 +1626,6 @@ mod pallet_benchmarks {
staked_amt
));

StakingOperationRateLimiter::<T>::remove((hotkey.clone(), coldkey.clone(), netuid));

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
Expand Down
15 changes: 0 additions & 15 deletions pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,21 +462,6 @@ impl<T: Config> Pallet<T> {
TransactionKeyLastBlock::<T>::remove((hot, netuid, name));
}
}
// StakingOperationRateLimiter NMAP: (hot, cold, netuid) → bool
{
let to_rm: sp_std::vec::Vec<(T::AccountId, T::AccountId)> =
StakingOperationRateLimiter::<T>::iter()
.filter_map(
|((hot, cold, n), _)| {
if n == netuid { Some((hot, cold)) } else { None }
},
)
.collect();
for (hot, cold) in to_rm {
StakingOperationRateLimiter::<T>::remove((hot, cold, netuid));
}
}

// --- 22. Subnet leasing: remove mapping and any lease-scoped state linked to this netuid.
if let Some(lease_id) = SubnetUidToLeaseId::<T>::take(netuid) {
SubnetLeases::<T>::remove(lease_id);
Expand Down
14 changes: 0 additions & 14 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2459,20 +2459,6 @@ pub mod pallet {
OptionQuery,
>;

/// DMAP ( hot, cold, netuid ) --> rate limits for staking operations
/// Value contains just a marker: we use this map as a set.
#[pallet::storage]
pub type StakingOperationRateLimiter<T: Config> = StorageNMap<
Comment thread
evgeny-s marked this conversation as resolved.
_,
(
NMapKey<Blake2_128Concat, T::AccountId>, // hot
NMapKey<Blake2_128Concat, T::AccountId>, // cold
NMapKey<Identity, NetUid>, // subnet
),
bool,
ValueQuery,
>;

#[pallet::storage] // --- MAP(netuid ) --> Root claim threshold
pub type RootClaimableThreshold<T: Config> =
StorageMap<_, Blake2_128Concat, NetUid, I96F32, ValueQuery, DefaultMinRootClaimAmount<T>>;
Expand Down
2 changes: 0 additions & 2 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ mod errors {
SameNetuid,
/// The caller does not have enough balance for the operation.
InsufficientBalance,
/// Too frequent staking operations
StakingOperationRateLimitExceeded,
/// Invalid lease beneficiary to register the leased network.
InvalidLeaseBeneficiary,
/// Lease cannot end in the past.
Expand Down
11 changes: 0 additions & 11 deletions pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ mod hooks {
}
}

// ---- Called on the finalization of this pallet. The code weight must be taken into account prior to the execution of this macro.
//
// # Args:
// * 'n': (BlockNumberFor<T>):
// - The number of the block we are finalizing.
fn on_finalize(_block_number: BlockNumberFor<T>) {
for _ in StakingOperationRateLimiter::<T>::drain() {
// Clear all entries each block
}
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
// --- Migrate storage
let mut weight = frame_support::weights::Weight::from_parts(0, 0);
Expand Down
2 changes: 0 additions & 2 deletions pallets/subtensor/src/staking/add_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl<T: Config> Pallet<T> {
netuid,
stake_to_be_added,
T::SwapInterface::max_price(),
true,
false,
)
}
Expand Down Expand Up @@ -155,7 +154,6 @@ impl<T: Config> Pallet<T> {
netuid,
possible_stake,
limit_price,
true,
false,
)
}
Expand Down
6 changes: 0 additions & 6 deletions pallets/subtensor/src/staking/move_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl<T: Config> Pallet<T> {
None,
None,
false,
true,
)?;

// Log the event.
Expand Down Expand Up @@ -141,7 +140,6 @@ impl<T: Config> Pallet<T> {
None,
None,
true,
false,
)?;

// 9. Emit an event for logging/monitoring.
Expand Down Expand Up @@ -206,7 +204,6 @@ impl<T: Config> Pallet<T> {
None,
None,
false,
true,
)?;

// Emit an event for logging.
Expand Down Expand Up @@ -274,7 +271,6 @@ impl<T: Config> Pallet<T> {
Some(limit_price),
Some(allow_partial),
false,
true,
)?;

// Emit an event for logging.
Expand Down Expand Up @@ -306,7 +302,6 @@ impl<T: Config> Pallet<T> {
maybe_limit_price: Option<TaoBalance>,
maybe_allow_partial: Option<bool>,
check_transfer_toggle: bool,
set_limit: bool,
) -> Result<TaoBalance, DispatchError> {
// Cap the alpha_amount at available Alpha because user might be paying transaxtion fees
// in Alpha and their total is already reduced by now.
Expand Down Expand Up @@ -385,7 +380,6 @@ impl<T: Config> Pallet<T> {
destination_netuid,
tao_unstaked,
T::SwapInterface::max_price(),
set_limit,
drop_fee_destination,
)?;
}
Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/src/staking/remove_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ impl<T: Config> Pallet<T> {
NetUid::ROOT,
total_tao_unstaked,
T::SwapInterface::max_price(),
false, // no limit for Root subnet
false,
)?;

Expand Down
Loading
Loading