Skip to content

Commit

Permalink
Deprecates get_stake_for_coldkey_and_hotkey method of Subtensor a…
Browse files Browse the repository at this point in the history
…nd `AsyncSubtensor`, as per Issue #2568
  • Loading branch information
thewhaleking committed Feb 3, 2025
1 parent dc0ae8a commit 3bcdbb5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
69 changes: 42 additions & 27 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import copy
import ssl
import warnings
from typing import Optional, Any, Union, Iterable, TYPE_CHECKING

import aiohttp
Expand Down Expand Up @@ -1547,35 +1548,31 @@ async def get_stake(
Balance: The stake under the coldkey - hotkey pairing.
"""
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)

# Get alpha shares
alpha_shares = await self.query_module(
module="SubtensorModule",
name="Alpha",
block_hash=block_hash,
reuse_block=reuse_block,
params=[hotkey_ss58, coldkey_ss58, netuid],
alpha_shares, hotkey_alpha_result, hotkey_shares = await asyncio.gather(
self.query_module(
module="SubtensorModule",
name="Alpha",
block_hash=block_hash,
reuse_block=reuse_block,
params=[hotkey_ss58, coldkey_ss58, netuid],
),
self.query_module(
module="SubtensorModule",
name="TotalHotkeyAlpha",
block_hash=block_hash,
reuse_block=reuse_block,
params=[hotkey_ss58, netuid],
),
self.query_module(
module="SubtensorModule",
name="TotalHotkeyShares",
block_hash=block_hash,
reuse_block=reuse_block,
params=[hotkey_ss58, netuid],
),
)

# Get total hotkey alpha
hotkey_alpha_result = await self.query_module(
module="SubtensorModule",
name="TotalHotkeyAlpha",
block_hash=block_hash,
reuse_block=reuse_block,
params=[hotkey_ss58, netuid],
)
hotkey_alpha: int = getattr(hotkey_alpha_result, "value", 0)

# Get total hotkey shares
hotkey_shares = await self.query_module(
module="SubtensorModule",
name="TotalHotkeyShares",
block_hash=block_hash,
reuse_block=reuse_block,
params=[hotkey_ss58, netuid],
)

alpha_shares_as_float = fixed_to_float(alpha_shares)
hotkey_shares_as_float = fixed_to_float(hotkey_shares)

Expand All @@ -1586,7 +1583,25 @@ async def get_stake(

return Balance.from_rao(int(stake)).set_unit(netuid=netuid)

get_stake_for_coldkey_and_hotkey = get_stake
async def get_stake_for_coldkey_and_hotkey(
self,
hotkey_ss58: str,
coldkey_ss58: str,
block: Optional[int] = None,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Balance:
warnings.warn(
"This method is deprecated and will be removed in version 9.0 full release "
"Please use `AsyncSubtensor.get_stake`",
)
return await self.get_stake(
coldkey_ss58=coldkey_ss58,
hotkey_ss58=hotkey_ss58,
block=block,
block_hash=block_hash,
reuse_block=reuse_block,
)

async def get_stake_for_coldkey(
self,
Expand Down
14 changes: 13 additions & 1 deletion bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import warnings
from functools import lru_cache
from typing import TYPE_CHECKING, Any, Iterable, Optional, Union, cast

Expand Down Expand Up @@ -1206,7 +1207,18 @@ def get_stake(

return Balance.from_rao(int(stake)).set_unit(netuid=netuid)

get_stake_for_coldkey_and_hotkey = get_stake
def get_stake_for_coldkey_and_hotkey(
self, hotkey_ss58: str, coldkey_ss58: str, block: Optional[int] = None
) -> Balance:
warnings.warn(
"This method is deprecated and will be removed in version 9.0 full release "
"Please use `Subtensor.get_stake`",
)
return self.get_stake(
coldkey_ss58=coldkey_ss58,
hotkey_ss58=hotkey_ss58,
block=block,
)

def get_stake_for_coldkey(
self, coldkey_ss58: str, block: Optional[int] = None
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,7 @@ def test_get_stake_for_coldkey_and_hotkey(subtensor, mocker):
spy_balance = mocker.spy(subtensor_module, "Balance")

# Call
result = subtensor.get_stake_for_coldkey_and_hotkey(
result = subtensor.get_stake(
hotkey_ss58="hotkey", coldkey_ss58="coldkey", block=None
)

Expand Down

0 comments on commit 3bcdbb5

Please sign in to comment.