Description
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 blockX
- wait
stake_interval - 1
blocks - stake
1
time at blockX + 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.
Activity
camfairchild commentedon Dec 12, 2024
Example:
camfairchild commentedon Dec 31, 2024
Closed by #1093 in #1119