Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(un)Staking multiple avoid tx limit #1244

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions bittensor/_subtensor/extrinsics/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import bittensor

from rich.prompt import Confirm
from time import sleep
from typing import List, Dict, Union, Optional
from bittensor.utils.balance import Balance
from ..errors import *
Expand Down Expand Up @@ -240,7 +241,7 @@ def add_stake_multiple_extrinsic (
amounts = [Balance.from_tao(amount.tao * percent_reduction) for amount in amounts]

successful_stakes = 0
for hotkey_ss58, amount, old_stake in zip(hotkey_ss58s, amounts, old_stakes):
for idx, (hotkey_ss58, amount, old_stake) in enumerate(zip(hotkey_ss58s, amounts, old_stakes)):
staking_all = False
# Convert to bittensor.Balance
if amount == None:
Expand Down Expand Up @@ -271,9 +272,17 @@ def add_stake_multiple_extrinsic (
wait_for_inclusion = wait_for_inclusion,
wait_for_finalization = wait_for_finalization,
)

if staking_response: # If we successfully staked.
# We only wait here if we expect finalization.

if idx < len(hotkey_ss58s) - 1:
# Wait for tx rate limit.
tx_rate_limit_blocks = subtensor.tx_rate_limit()
if tx_rate_limit_blocks > 0:
bittensor.__console__.print(":hourglass: [yellow]Waiting for tx rate limit: [white]{}[/white] blocks[/yellow]".format(tx_rate_limit_blocks))
sleep( tx_rate_limit_blocks * 12 ) # 12 seconds per block

if not wait_for_finalization and not wait_for_inclusion:
bittensor.__console__.print(":white_heavy_check_mark: [green]Sent[/green]")
old_balance -= staking_balance
Expand Down
11 changes: 10 additions & 1 deletion bittensor/_subtensor/extrinsics/unstaking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import bittensor

from rich.prompt import Confirm
from time import sleep
from typing import List, Dict, Union, Optional
from bittensor.utils.balance import Balance
from ..errors import *
Expand Down Expand Up @@ -245,7 +246,7 @@ def unstake_multiple_extrinsic (
old_stakes.append(old_stake) # None if not registered.

successful_unstakes = 0
for hotkey_ss58, amount, old_stake in zip(hotkey_ss58s, amounts, old_stakes):
for idx, (hotkey_ss58, amount, old_stake) in enumerate(zip(hotkey_ss58s, amounts, old_stakes)):
# Covert to bittensor.Balance
if amount == None:
# Unstake it all.
Expand Down Expand Up @@ -279,6 +280,14 @@ def unstake_multiple_extrinsic (

if staking_response: # If we successfully unstaked.
# We only wait here if we expect finalization.

if idx < len(hotkey_ss58s) - 1:
# Wait for tx rate limit.
tx_rate_limit_blocks = subtensor.tx_rate_limit()
if tx_rate_limit_blocks > 0:
bittensor.__console__.print(":hourglass: [yellow]Waiting for tx rate limit: [white]{}[/white] blocks[/yellow]".format(tx_rate_limit_blocks))
sleep( tx_rate_limit_blocks * 12 ) # 12 seconds per block

if not wait_for_finalization and not wait_for_inclusion:
bittensor.__console__.print(":white_heavy_check_mark: [green]Sent[/green]")
successful_unstakes += 1
Expand Down
3 changes: 3 additions & 0 deletions bittensor/_subtensor/subtensor_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ def total_stake (self,block: Optional[int] = None ) -> 'bittensor.Balance':

def serving_rate_limit (self, block: Optional[int] = None ) -> Optional[int]:
return self.query_subtensor( "ServingRateLimit", block ).value

def tx_rate_limit (self, block: Optional[int] = None ) -> Optional[int]:
return self.query_subtensor( "TxRateLimit", block ).value

#####################################
#### Network Parameters ####
Expand Down