Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
43ffc7a
improve `async/subtensor.sign_and_send_extrinsic`
May 1, 2025
4d2450b
add extrinsics helper function `convert_and_normalize_weights_and_uids`
May 1, 2025
463dd2a
use `convert_and_normalize_weights_and_uids` in set_weights.py
May 1, 2025
58f3f15
use `convert_and_normalize_weights_and_uids` in weights.py
May 1, 2025
e1543db
update commit_reveal extrinsics
May 1, 2025
dbc23e3
update `bittensor.core.subtensor.Subtensor.set_weights` call
May 1, 2025
c88822f
update test related with `bittensor.core.subtensor.Subtensor.set_weig…
May 1, 2025
1b98ea0
increase set_weights' period until 16 to avoid flaky behavior
May 1, 2025
b0e5238
fix tests
May 1, 2025
e32638c
fix commit reveal unit tests
May 1, 2025
71842ec
set default period as None. Better to control this argument via each …
May 1, 2025
7225ddc
Add logic to control running localnet mode (non-/fast-blocks) to run …
May 1, 2025
6aeadae
update `commit_weights` extrinsics calls
May 1, 2025
fa9139b
update `commit_weights` extrinsics
May 1, 2025
cf2a8cc
fix fast_blocks logic in conftest.py
May 1, 2025
1751d48
fix wait_for_block logic in subtensors
May 1, 2025
e8ab07b
update docstrings
May 1, 2025
0213d03
keep fast-blocks mode by default
May 1, 2025
73e9fb2
update `reveal_weights_extrinsic` for both subtensors
May 1, 2025
c8e7e99
update `Subtensor.reveal_weights` extrinsic call
May 1, 2025
422eddf
fix related unit tests
May 1, 2025
662767c
fmt
May 1, 2025
84e7108
bittensor.core.extrinsics.move_stake.transfer_stake_extrinsic
May 1, 2025
81a5669
bittensor.core.subtensor.Subtensor.transfer_stake
May 1, 2025
6dc3e0e
bittensor.core.extrinsics.move_stake.swap_stake_extrinsic
May 1, 2025
5ab22df
bittensor.core.subtensor.Subtensor.swap_stake
May 1, 2025
9050c20
fix related tests
May 1, 2025
0f56efc
bittensor.core.extrinsics.move_stake.move_stake_extrinsic
May 1, 2025
474b2ee
bittensor.core.subtensor.Subtensor.move_stake
May 1, 2025
d549aa2
bittensor/core/extrinsics/asyncex/move_stake.py
May 1, 2025
adeda3f
related changes in bittensor/core/async_subtensor.py
May 1, 2025
cdb8bb8
Merge branch 'staging' into feat/roman/add-validity-period-to-extrins…
May 1, 2025
c0eebe0
update `bittensor/core/extrinsics/registration.py`
May 1, 2025
54e0261
update `bittensor/core/extrinsics/asyncex/registration.py`
May 1, 2025
04cc497
update `bittensor/core/async_subtensor.py`
May 1, 2025
f131a7c
update `bittensor/core/subtensor.py`
May 1, 2025
0e743f7
fix related tests
May 1, 2025
904b4cd
optimize imports in utils
May 1, 2025
f813b9c
update `bittensor/core/extrinsics/root.py`
May 1, 2025
7fe6084
update `bittensor/core/extrinsics/asyncex/root.py`
May 1, 2025
1aed640
refactoring related with `bittensor.utils.weight_utils.convert_and_no…
May 1, 2025
fb050f8
update extrinsics related calls
May 1, 2025
d7b156f
fix related tests
May 1, 2025
dba73aa
update `bittensor/core/extrinsics/serving.py`
May 2, 2025
904f9b2
update `bittensor/core/extrinsics/asyncex/serving.py`
May 2, 2025
9a27b6a
related subtensors updates
May 2, 2025
e5d2264
fix tests
May 2, 2025
a36ecb1
update `bittensor/core/extrinsics/asyncex/weights.py`
May 2, 2025
a2418b1
update `bittensor/core/extrinsics/set_weights.py`
May 2, 2025
cc5344c
rename `convert_uids_and_weights`
May 2, 2025
ca92a81
refactoring
May 2, 2025
3ee11a6
improve `sign_and_send_extrinsic` calls
May 2, 2025
f34befd
fix tests
May 2, 2025
42341a1
opps with set_weights (fixed) + tests
May 2, 2025
45d4bec
refactor
May 2, 2025
7d508c6
update `bittensor/core/extrinsics/asyncex/staking.py`
May 2, 2025
3e9db46
update `bittensor/core/extrinsics/staking.py`
May 2, 2025
93c051e
update `bittensor.core.extrinsics.staking.add_stake_multiple_extrinsic`
May 2, 2025
76e8907
update `bittensor.core.extrinsics.asyncex.staking.add_stake_multiple_…
May 2, 2025
268f95c
fix tests
May 2, 2025
6a872d3
update subtensor calls
May 2, 2025
eff87f2
refactoring
May 2, 2025
838c9bc
update start_call extrinsics
May 2, 2025
179b3dd
update subtensors start_call extrinsics
May 2, 2025
76384c9
fix tests
May 2, 2025
30953e1
extrinsics `increase_take_extrinsic` and `decrease_take_extrinsic`
May 2, 2025
9563c04
related subtensors calls
May 2, 2025
363ba28
refactoring
May 2, 2025
d1f0a90
transfer extrinsics
May 2, 2025
ac9685c
transfer extrinsics calls in subtensors
May 2, 2025
770a50a
fixed tests
May 2, 2025
8896702
replace error + formatting error for staking
May 2, 2025
de076c9
update unstaking extrinsics
May 2, 2025
1bd2e4e
update subtensor unstaking calls
May 2, 2025
ef80b8b
fix related tests
May 2, 2025
bf7c9bb
del unused imports
May 2, 2025
d7a6ef1
fix a bunch of unit test's inner calls
May 2, 2025
e915a3f
oops with `set_children` -> fixed
May 2, 2025
7fef30f
ruff + mypy + flake8
May 2, 2025
caf8c70
optimization + period for test
May 2, 2025
a752e50
Update bittensor/core/async_subtensor.py
thewhaleking May 2, 2025
6bb8954
Update bittensor/core/async_subtensor.py
thewhaleking May 2, 2025
1fc275a
Update bittensor/core/async_subtensor.py
thewhaleking May 2, 2025
12323dc
Update bittensor/core/async_subtensor.py
thewhaleking May 2, 2025
00f0b69
Update bittensor/utils/weight_utils.py
thewhaleking May 2, 2025
2235197
Update bittensor/utils/weight_utils.py
thewhaleking May 2, 2025
4c032d2
Update tests/e2e_tests/test_commit_weights.py
thewhaleking May 2, 2025
cb7b4d0
Update tests/e2e_tests/test_commit_weights.py
thewhaleking May 2, 2025
eb4d3d6
Update tests/e2e_tests/conftest.py
thewhaleking May 2, 2025
3f0b2e0
Update bittensor/core/async_subtensor.py
thewhaleking May 2, 2025
a2cc42b
Update bittensor/core/extrinsics/asyncex/weights.py
thewhaleking May 2, 2025
a31eca7
Update bittensor/core/extrinsics/root.py
thewhaleking May 2, 2025
81b7575
Update bittensor/core/extrinsics/root.py
thewhaleking May 2, 2025
65e4f12
Update bittensor/core/extrinsics/staking.py
thewhaleking May 2, 2025
f02cd52
Update bittensor/core/extrinsics/take.py
thewhaleking May 2, 2025
caba14a
Update bittensor/core/subtensor.py
thewhaleking May 2, 2025
aefb385
Update bittensor/core/subtensor.py
thewhaleking May 2, 2025
72ac8a4
Update bittensor/core/subtensor.py
thewhaleking May 2, 2025
ce0d97f
Update bittensor/core/subtensor.py
thewhaleking May 2, 2025
a6a6a13
Update bittensor/core/subtensor.py
thewhaleking May 2, 2025
05e0fc5
add TODO
May 2, 2025
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
263 changes: 192 additions & 71 deletions bittensor/core/async_subtensor.py

Large diffs are not rendered by default.

44 changes: 25 additions & 19 deletions bittensor/core/extrinsics/asyncex/commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from bittensor.core.settings import version_as_int
from bittensor.utils.btlogging import logging
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
from bittensor.utils.weight_utils import convert_and_normalize_weights_and_uids

if TYPE_CHECKING:
from bittensor_wallet import Wallet
Expand All @@ -24,23 +24,26 @@ async def _do_commit_reveal_v3(
reveal_round: int,
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
) -> tuple[bool, Optional[str]]:
period: Optional[int] = None,
) -> tuple[bool, str]:
"""
Executes the commit-reveal phase 3 for a given netuid and commit, and optionally waits for extrinsic inclusion or
finalization.
Executes commit-reveal phase 3 for a given netuid and commit, and optionally waits for extrinsic inclusion or finalization.

Arguments:
subtensor: An instance of the AsyncSubtensor class.
wallet: Wallet An instance of the Wallet class containing the user's keypair.
netuid: int The network unique identifier.
commit bytes The commit data in bytes format.
commit: bytes The commit data in bytes format.
reveal_round: int The round number for the reveal phase.
wait_for_inclusion: bool, optional Flag indicating whether to wait for the extrinsic to be included in a block.
wait_for_finalization: bool, optional Flag indicating whether to wait for the extrinsic to be finalized.
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
You can think of it as an expiration date for the transaction.

Returns:
A tuple where the first element is a boolean indicating success or failure, and the second element is an
optional string containing error message if any.
A tuple where the first element is a boolean indicating success or failure, and the second element is a
string containing an error message if any.
"""
logging.info(
f"Committing weights hash [blue]{commit.hex()}[/blue] for subnet #[blue]{netuid}[/blue] with "
Expand All @@ -57,7 +60,12 @@ async def _do_commit_reveal_v3(
},
)
return await subtensor.sign_and_send_extrinsic(
call, wallet, wait_for_inclusion, wait_for_finalization, sign_with="hotkey"
call=call,
wallet=wallet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
sign_with="hotkey",
period=period,
)


Expand All @@ -70,10 +78,11 @@ async def commit_reveal_v3_extrinsic(
version_key: int = version_as_int,
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
block_time: float = 12.0,
block_time: Union[int, float] = 12.0,
period: Optional[int] = None,
) -> tuple[bool, str]:
"""
Commits and reveals weights for given subtensor and wallet with provided uids and weights.
Commits and reveals weights for a given subtensor and wallet with provided uids and weights.

Arguments:
subtensor: The AsyncSubtensor instance.
Expand All @@ -84,21 +93,17 @@ async def commit_reveal_v3_extrinsic(
version_key: The version key to use for committing and revealing. Default is version_as_int.
wait_for_inclusion: Whether to wait for the inclusion of the transaction. Default is False.
wait_for_finalization: Whether to wait for the finalization of the transaction. Default is False.
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.
block_time (float): The number of seconds for block duration. Default is 12.0 seconds.
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
You can think of it as an expiration date for the transaction.

Returns:
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure, and the second
element is a message associated with the result
"""
try:
# Convert uids and weights
if isinstance(uids, list):
uids = np.array(uids, dtype=np.int64)
if isinstance(weights, list):
weights = np.array(weights, dtype=np.float32)

# Reformat and normalize.
uids, weights = convert_weights_and_uids_for_emit(uids, weights)
uids, weights = convert_and_normalize_weights_and_uids(uids, weights)

current_block = await subtensor.substrate.get_block(None)
subnet_hyperparameters = await subtensor.get_subnet_hyperparameters(
Expand Down Expand Up @@ -127,6 +132,7 @@ async def commit_reveal_v3_extrinsic(
reveal_round=reveal_round,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
)

if success is not True:
Expand Down
30 changes: 23 additions & 7 deletions bittensor/core/extrinsics/asyncex/move_stake.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

from bittensor.utils.balance import Balance
from bittensor.utils.btlogging import logging
Expand All @@ -18,6 +18,7 @@ async def _get_stake_in_origin_and_dest(
origin_netuid: int,
destination_netuid: int,
) -> tuple[Balance, Balance]:
"""Gets the current stake balances for both origin and destination addresses in their respective subnets."""
block_hash = await subtensor.substrate.get_chain_head()
stake_in_origin, stake_in_destination = await asyncio.gather(
subtensor.get_stake(
Expand Down Expand Up @@ -46,6 +47,7 @@ async def transfer_stake_extrinsic(
amount: Balance,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
period: Optional[int] = None,
) -> bool:
"""
Transfers stake from one coldkey to another in the Bittensor network.
Expand All @@ -60,6 +62,9 @@ async def transfer_stake_extrinsic(
amount (Balance): The amount of stake to transfer as a `Balance` object.
wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to `True`.
wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to `False`.
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
You can think of it as an expiration date for the transaction.

Returns:
bool: True if the transfer was successful, False otherwise.
Expand All @@ -77,7 +82,7 @@ async def transfer_stake_extrinsic(

# Check sufficient stake
stake_in_origin, stake_in_destination = await _get_stake_in_origin_and_dest(
subtensor,
subtensor=subtensor,
origin_hotkey_ss58=hotkey_ss58,
destination_hotkey_ss58=hotkey_ss58,
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
Expand Down Expand Up @@ -116,6 +121,7 @@ async def transfer_stake_extrinsic(
wallet=wallet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
)

if success:
Expand All @@ -126,7 +132,7 @@ async def transfer_stake_extrinsic(

# Get updated stakes
origin_stake, dest_stake = await _get_stake_in_origin_and_dest(
subtensor,
subtensor=subtensor,
origin_hotkey_ss58=hotkey_ss58,
destination_hotkey_ss58=hotkey_ss58,
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
Expand Down Expand Up @@ -163,6 +169,7 @@ async def swap_stake_extrinsic(
safe_staking: bool = False,
allow_partial_stake: bool = False,
rate_tolerance: float = 0.005,
period: Optional[int] = None,
) -> bool:
"""
Swaps stake from one subnet to another for a given hotkey in the Bittensor network.
Expand All @@ -178,7 +185,10 @@ async def swap_stake_extrinsic(
wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to False.
safe_staking (bool): If true, enables price safety checks to protect against price impact.
allow_partial_stake (bool): If true, allows partial stake swaps when the full amount would exceed the price tolerance.
rate_tolerance (float): Maximum allowed increase in price ratio (0.005 = 0.5%).
rate_tolerance (float): Maximum allowed increase in a price ratio (0.005 = 0.5%).
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
You can think of it as an expiration date for the transaction.

Returns:
bool: True if the swap was successful, False otherwise.
Expand All @@ -195,7 +205,7 @@ async def swap_stake_extrinsic(

# Check sufficient stake
stake_in_origin, stake_in_destination = await _get_stake_in_origin_and_dest(
subtensor,
subtensor=subtensor,
origin_hotkey_ss58=hotkey_ss58,
destination_hotkey_ss58=hotkey_ss58,
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
Expand Down Expand Up @@ -259,6 +269,7 @@ async def swap_stake_extrinsic(
wallet=wallet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
)

if success:
Expand Down Expand Up @@ -309,6 +320,7 @@ async def move_stake_extrinsic(
amount: Balance,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
period: Optional[int] = None,
) -> bool:
"""
Moves stake from one hotkey to another within subnets in the Bittensor network.
Expand All @@ -323,6 +335,9 @@ async def move_stake_extrinsic(
amount (Balance): The amount of stake to move as a `Balance` object.
wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to True.
wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to False.
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
You can think of it as an expiration date for the transaction.

Returns:
bool: True if the move was successful, False otherwise.
Expand All @@ -331,7 +346,7 @@ async def move_stake_extrinsic(

# Check sufficient stake
stake_in_origin, stake_in_destination = await _get_stake_in_origin_and_dest(
subtensor,
subtensor=subtensor,
origin_hotkey_ss58=origin_hotkey,
destination_hotkey_ss58=destination_hotkey,
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
Expand Down Expand Up @@ -369,6 +384,7 @@ async def move_stake_extrinsic(
wallet=wallet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
)

if success:
Expand All @@ -379,7 +395,7 @@ async def move_stake_extrinsic(

# Get updated stakes
origin_stake, dest_stake = await _get_stake_in_origin_and_dest(
subtensor,
subtensor=subtensor,
origin_hotkey_ss58=origin_hotkey,
destination_hotkey_ss58=destination_hotkey,
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
Expand Down
Loading