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
14 changes: 11 additions & 3 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 Expand Up @@ -356,7 +365,6 @@ def __do_add_stake_single(
"""
# Decrypt keys,
wallet.coldkey
wallet.hotkey

hotkey_owner = subtensor.get_hotkey_owner( hotkey_ss58 )
own_hotkey = (wallet.coldkeypub.ss58_address == hotkey_owner)
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