Describe the bug
Currently, we rate limit staking transactions by checking how many staking transactions were done within a set interval, and limiting if it exceeds the set target.
The way we do this is flawed. In the get_stakes_this_interval_for_coldkey_hotkey function, we take the value stored in TotalHotkeyColdkeyStakesThisInterval of (num_stakes, last_stake_block).
We reset num_stakes to 0 if it has been more than stake_interval blocks since last_stake_block.
Otherwise we return num_stakes with no reset.
This passes the rate limit, and then we do the transaction. We then increment num_stakes and set last_stake_block to the current block.
This is fine for stake_interval == 1, but for anything greater, we run into an issue.
Example with stake_interval = n where n > 1:
- stake
n - 1 times at block X
- wait
stake_interval - 1 blocks
- stake
1 time at block X + stake_interval - 1
- wait for next block;
- stake again ==> failed, rate limited
Why does this fail?
In 4., we should expect the rate limit count to reset to 1 as we have only staked once in the last stake_interval blocks. However, because of the faulty logic, we actually just increase the count and rate limit for another stake_interval blocks.
Describe the bug
Currently, we rate limit staking transactions by checking how many staking transactions were done within a set interval, and limiting if it exceeds the set target.
The way we do this is flawed. In the
get_stakes_this_interval_for_coldkey_hotkeyfunction, we take the value stored inTotalHotkeyColdkeyStakesThisIntervalof(num_stakes, last_stake_block).We reset
num_stakesto0if it has been more thanstake_intervalblocks sincelast_stake_block.Otherwise we return
num_stakeswith no reset.This passes the rate limit, and then we do the transaction. We then increment
num_stakesand setlast_stake_blockto the current block.This is fine for
stake_interval == 1, but for anything greater, we run into an issue.Example with
stake_interval = nwheren > 1:n - 1times at blockXstake_interval - 1blocks1time at blockX + stake_interval - 1Why does this fail?
In 4., we should expect the rate limit count to reset to
1as we have only staked once in the laststake_intervalblocks. However, because of the faulty logic, we actually just increase the count and rate limit for anotherstake_intervalblocks.