Skip to content

Fix Stake rate limit for target>1 #1091

Description

@camfairchild

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:

  1. stake n - 1 times at block X
  2. wait stake_interval - 1 blocks
  3. stake 1 time at block X + stake_interval - 1
  4. wait for next block;
  5. 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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions