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

Add staking and unstaking extrinsics #2456

Merged
merged 31 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
77bc5b5
fast refactor for subtensor modules
roman-opentensor Nov 21, 2024
aa6111a
add unstake extrinsics
roman-opentensor Nov 21, 2024
d5ea91e
add emoji
roman-opentensor Nov 21, 2024
34c9537
add helper methods to subtensor.Subtensor
roman-opentensor Nov 21, 2024
8940e02
imports
roman-opentensor Nov 21, 2024
4122d7b
add extrinsics calls to Subtensor class
roman-opentensor Nov 21, 2024
7860b6f
add staking
roman-opentensor Nov 21, 2024
907ce02
fix circular import
roman-opentensor Nov 21, 2024
6ef229b
order
roman-opentensor Nov 21, 2024
5c72efe
added `add_stake` and `add_stake_multiple`
roman-opentensor Nov 21, 2024
7f373a3
Merge branch 'staging' into feat/roman/add_unstake_extrinsic
roman-opentensor Nov 21, 2024
c3727da
test for `Subtensor.get_stake_for_coldkey_and_hotkey`
roman-opentensor Nov 22, 2024
babf9b4
test for `Subtensor.get_hotkey_owner`
roman-opentensor Nov 22, 2024
9f439ad
test for `Subtensor.get_minimum_required_stake`
roman-opentensor Nov 22, 2024
242ad71
test for `Subtensor.does_hotkey_exist`
roman-opentensor Nov 22, 2024
49bc391
test for `Subtensor.tx_rate_limit`
roman-opentensor Nov 22, 2024
7c8f1af
test for `Subtensor.get_delegates`
roman-opentensor Nov 22, 2024
0a43fa4
test for `Subtensor.is_hotkey_delegate`
roman-opentensor Nov 22, 2024
ba26ef8
test for `Subtensor.add_stake` extrinsic call
roman-opentensor Nov 22, 2024
ebad015
test for `Subtensor.add_stake_multiple` extrinsic call
roman-opentensor Nov 22, 2024
f78abe2
test for `Subtensor.unstake` extrinsic call
roman-opentensor Nov 22, 2024
360f5cd
test for `Subtensor.unstake_multiple` extrinsic call
roman-opentensor Nov 22, 2024
762e593
Merge pull request #2458 from opentensor/tests/roman/add_unstake_extr…
roman-opentensor Nov 22, 2024
27d22d6
Update bittensor/core/extrinsics/staking.py
roman-opentensor Nov 22, 2024
6ba5a25
Update bittensor/core/extrinsics/unstaking.py
roman-opentensor Nov 22, 2024
093a9aa
Update bittensor/core/extrinsics/unstaking.py
roman-opentensor Nov 22, 2024
140f037
Update bittensor/core/async_subtensor.py
roman-opentensor Nov 22, 2024
0f257cf
Update bittensor/core/extrinsics/staking.py
roman-opentensor Nov 22, 2024
a15915c
Merge branch 'staging' into feat/roman/add_unstake_extrinsic
roman-opentensor Nov 22, 2024
456528d
fix unused import
roman-opentensor Nov 22, 2024
2d12d87
Merge branch 'staging' into feat/roman/add_unstake_extrinsic
roman-opentensor Nov 22, 2024
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
70 changes: 36 additions & 34 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,41 @@ async def encode_params(

return param_data.to_hex()

async def get_hyperparameter(
self,
param_name: str,
netuid: int,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[Any]:
"""
Retrieves a specified hyperparameter for a specific subnet.

Args:
param_name (str): The name of the hyperparameter to retrieve.
netuid (int): The unique identifier of the subnet.
block_hash (Optional[str]): The hash of blockchain block number for the query.
reuse_block (bool): Whether to reuse the last-used block hash.

Returns:
The value of the specified hyperparameter if the subnet exists, or None
"""
if not await self.subnet_exists(netuid, block_hash):
logging.error(f"subnet {netuid} does not exist")
return None

result = await self.substrate.query(
module="SubtensorModule",
storage_function=param_name,
params=[netuid],
block_hash=block_hash,
reuse_block_hash=reuse_block,
)

return result

# Common subtensor methods =========================================================================================

async def get_current_block(self) -> int:
"""
Returns the current block number on the Bittensor blockchain. This function provides the latest block number, indicating the most recent state of the blockchain.
Expand Down Expand Up @@ -663,39 +698,6 @@ async def subnet_exists(
)
return result

async def get_hyperparameter(
self,
param_name: str,
netuid: int,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[Any]:
"""
Retrieves a specified hyperparameter for a specific subnet.

Args:
param_name (str): The name of the hyperparameter to retrieve.
netuid (int): The unique identifier of the subnet.
block_hash (Optional[str]): The hash of blockchain block number for the query.
reuse_block (bool): Whether to reuse the last-used block hash.

Returns:
The value of the specified hyperparameter if the subnet exists, or None
"""
if not await self.subnet_exists(netuid, block_hash):
print("subnet does not exist")
return None

result = await self.substrate.query(
module="SubtensorModule",
storage_function=param_name,
params=[netuid],
block_hash=block_hash,
reuse_block_hash=reuse_block,
)

return result

async def filter_netuids_by_registered_hotkeys(
self,
all_netuids: Iterable[int],
Expand Down Expand Up @@ -1357,7 +1359,7 @@ async def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]
call = await self.get_hyperparameter(param_name="LastUpdate", netuid=netuid)
return None if call is None else await self.get_current_block() - int(call[uid])

# extrinsics
# Extrinsics =======================================================================================================

async def transfer(
self,
Expand Down
Loading
Loading