Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8743cc8
update migration.md
Sep 5, 2025
2501287
add `bittensor.core.types.ExtrinsicResponse`
Sep 5, 2025
f6f9006
update `sign_and_send_extrinsic` with ExtrinsicResponse
Sep 5, 2025
dba885f
improve `set_children_extrinsic` + `root_set_pending_childkey_cooldow…
Sep 5, 2025
da8215d
improve `ExtrinsicResponse`
Sep 6, 2025
f09b5ba
fix test_children.py
Sep 6, 2025
c18dd8d
update `commit_reveal_extrinsic` + tests
Sep 6, 2025
5ba5e03
update migration.md
Sep 6, 2025
15f9eac
update `commit_weights_extrinsic` + `reveal_weights_extrinsic` + `set…
Sep 6, 2025
8e2ba9b
update `add_liquidity_extrinsic` + `modify_liquidity_extrinsic` + `re…
Sep 6, 2025
1cfaa9c
add unlock logging error message
Sep 6, 2025
af735a0
support indexing for success and message
Sep 8, 2025
9fc6d47
set `response.is_success="Success"` for all extrinsic in positive case
Sep 8, 2025
1222778
update migration.md
Sep 8, 2025
56b8a0d
update return in success case for children extrinsics
Sep 8, 2025
b730ce2
update return in success case for `commit_reveal_extrinsic` extrinsic…
Sep 8, 2025
1c4263d
update migration.md
Sep 8, 2025
8cec705
update `test_commit_and_reveal_weights_cr4`
Sep 8, 2025
c5e9ffa
improve `ExtrinsicResponse`
Sep 8, 2025
dbe9812
update `liquidity` docstrings
Sep 8, 2025
a2d61ce
update `test_commit_reveal_v3_extrinsic*`
Sep 8, 2025
1eb841d
update `children_extrinsic*`
Sep 8, 2025
b83ec6e
update `transfer_stake_extrinsic`, `swap_stake_extrinsic` and `move_s…
Sep 8, 2025
2dc3e82
fix unit tests
Sep 8, 2025
a901017
`root_register_extrinsic`, `subtensor.burned_register` and `subtensor…
Sep 8, 2025
efbdd81
`burned_register_extrinsic`, `register_subnet_extrinsic`, `register_e…
Sep 8, 2025
ba8b076
oops, need to remove
Sep 8, 2025
b570993
improve `ExtrinsicResponse` description
Sep 8, 2025
3937bf5
update `publish_metadata` extrinsic + tests
Sep 9, 2025
328d3f2
update `publish_metadata` -> `publish_metadata_extrinsic`
Sep 9, 2025
1384148
`add_stake_extrinsic`, `subtensor.add_stake`, `add_stake_multiple_ext…
Sep 9, 2025
7e6b459
`start_call_extrinsic`, `subtensor.start_call` + tests
Sep 9, 2025
32bf983
`increase_take_extrinsic`, `decrease_take_extrinsic`, `subtensor.set_…
Sep 9, 2025
2ea1e55
`transfer_extrinsic`, `subtensor.transfer` + tests
Sep 9, 2025
826c62e
`unstake_extrinsic`, `unstake_all_extrinsic`, `unstake_multiple_extri…
Sep 9, 2025
1a3c3de
bumping deps version
Sep 9, 2025
5261b44
update migration.md
Sep 9, 2025
c3f5741
update `ExtrinsicResponse.__str__`
Sep 9, 2025
e227a4a
opps, update response processing in tests
Sep 9, 2025
1c4c35f
trigger cached venv properly
Sep 9, 2025
b9a97ee
try avoid deps downloading freez
Sep 9, 2025
5e37f86
update message
Sep 9, 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
7 changes: 5 additions & 2 deletions .github/workflows/_run-e2e-single.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ jobs:
path: |
~/.cache/uv
.venv
key: uv-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
restore-keys: uv-${{ runner.os }}-py${{ matrix.python-version }}-
key: |
uv-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
uv-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
uv-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-

- name: Install dependencies
run: uv sync --extra dev --dev
Expand Down
429 changes: 210 additions & 219 deletions bittensor/core/async_subtensor.py

Large diffs are not rendered by default.

56 changes: 29 additions & 27 deletions bittensor/core/extrinsics/asyncex/children.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import TYPE_CHECKING, Optional
from bittensor.utils import float_to_u64, unlock_key

from bittensor.core.types import ExtrinsicResponse
from bittensor.utils import float_to_u64, unlock_key, get_function_name
from bittensor.utils.btlogging import logging

if TYPE_CHECKING:
from bittensor_wallet import Wallet
Expand All @@ -16,7 +19,7 @@ async def set_children_extrinsic(
raise_error: bool = False,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = True,
) -> tuple[bool, str]:
) -> ExtrinsicResponse:
"""
Allows a coldkey to set children-keys.

Expand All @@ -34,9 +37,7 @@ async def set_children_extrinsic(
wait_for_finalization: Waits for the transaction to be finalized on the blockchain.

Returns:
Tuple[bool, str]:
- True and a success message if the extrinsic is successfully submitted or processed.
- False and an error message if the submission fails or the wallet cannot be unlocked.
ExtrinsicResponse: The result object of the extrinsic execution.

Raises:
DuplicateChild: There are duplicates in the list of children.
Expand All @@ -54,7 +55,10 @@ async def set_children_extrinsic(
unlock = unlock_key(wallet, raise_error=raise_error)

if not unlock.success:
return False, unlock.message
logging.error(unlock.message)
return ExtrinsicResponse(
False, unlock.message, extrinsic_function=get_function_name()
)

async with subtensor.substrate as substrate:
call = await substrate.compose_call(
Expand All @@ -73,22 +77,23 @@ async def set_children_extrinsic(
},
)

success, message = await subtensor.sign_and_send_extrinsic(
response = await subtensor.sign_and_send_extrinsic(
call=call,
wallet=wallet,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
calling_function=get_function_name(),
)

if not wait_for_finalization and not wait_for_inclusion:
return True, message
return response

if success:
return True, "Success with `set_children_extrinsic` response."
if response.success:
return response

return True, message
return response


async def root_set_pending_childkey_cooldown_extrinsic(
Expand All @@ -99,7 +104,7 @@ async def root_set_pending_childkey_cooldown_extrinsic(
raise_error: bool = False,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = True,
) -> tuple[bool, str]:
) -> ExtrinsicResponse:
"""
Allows a root coldkey to set children-keys.

Expand All @@ -115,14 +120,13 @@ async def root_set_pending_childkey_cooldown_extrinsic(
wait_for_finalization: Waits for the transaction to be finalized on the blockchain.

Returns:
Tuple[bool, str]:
- True and a success message if the extrinsic is successfully submitted or processed.
- False and an error message if the submission fails or the wallet cannot be unlocked.
ExtrinsicResponse: The result object of the extrinsic execution.
"""
unlock = unlock_key(wallet)

if not unlock.success:
return False, unlock.message
if not (unlock := unlock_key(wallet)).success:
logging.error(unlock.message)
return ExtrinsicResponse(
False, unlock.message, extrinsic_function=get_function_name()
)

async with subtensor.substrate as substrate:
call = await substrate.compose_call(
Expand All @@ -137,22 +141,20 @@ async def root_set_pending_childkey_cooldown_extrinsic(
call_params={"call": call},
)

success, message = await subtensor.sign_and_send_extrinsic(
response = await subtensor.sign_and_send_extrinsic(
call=sudo_call,
wallet=wallet,
period=period,
raise_error=raise_error,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
calling_function=get_function_name(),
)

if not wait_for_finalization and not wait_for_inclusion:
return True, message
return response

if success:
return (
True,
"Success with `root_set_pending_childkey_cooldown_extrinsic` response.",
)
if response.success:
return response

return True, message
return response
111 changes: 57 additions & 54 deletions bittensor/core/extrinsics/asyncex/commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from numpy.typing import NDArray

from bittensor.core.settings import version_as_int
from bittensor.core.types import ExtrinsicResponse
from bittensor.utils import get_function_name, unlock_key
from bittensor.utils.btlogging import logging
from bittensor.utils.weight_utils import convert_and_normalize_weights_and_uids

Expand All @@ -29,7 +31,7 @@ async def commit_reveal_extrinsic(
raise_error: bool = False,
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
) -> tuple[bool, str]:
) -> ExtrinsicResponse:
"""
Commits and reveals weights for a given subtensor and wallet with provided uids and weights.

Expand All @@ -50,67 +52,68 @@ async def commit_reveal_extrinsic(
wait_for_finalization: Whether to wait for the finalization of the transaction.

Returns:
Tuple[bool, str]:
- True and a success message if the extrinsic is successfully submitted or processed.
- False and an error message if the submission fails or the wallet cannot be unlocked.
ExtrinsicResponse: The result object of the extrinsic execution.
"""
try:
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(
netuid, block_hash=current_block["header"]["hash"]
if not (unlock := unlock_key(wallet, unlock_type="hotkey")).success:
logging.error(unlock.message)
return ExtrinsicResponse(
False, unlock.message, extrinsic_function=get_function_name()
)
tempo = subnet_hyperparameters.tempo
subnet_reveal_period_epochs = subnet_hyperparameters.commit_reveal_period

# Encrypt `commit_hash` with t-lock and `get reveal_round`
commit_for_reveal, reveal_round = get_encrypted_commit(
uids=uids,
weights=weights,
version_key=version_key,
tempo=tempo,
current_block=current_block["header"]["number"],
netuid=netuid,
subnet_reveal_period_epochs=subnet_reveal_period_epochs,
block_time=block_time,
hotkey=wallet.hotkey.public_key,
)
uids, weights = convert_and_normalize_weights_and_uids(uids, weights)

logging.info(
f"Committing weights hash [blue]{commit_for_reveal.hex()}[/blue] for subnet #[blue]{netuid}[/blue] with "
f"reveal round [blue]{reveal_round}[/blue]..."
)
current_block = await subtensor.substrate.get_block(None)
subnet_hyperparameters = await subtensor.get_subnet_hyperparameters(
netuid, block_hash=current_block["header"]["hash"]
)
tempo = subnet_hyperparameters.tempo
subnet_reveal_period_epochs = subnet_hyperparameters.commit_reveal_period

call = await subtensor.substrate.compose_call(
call_module="SubtensorModule",
call_function="commit_timelocked_weights",
call_params={
"netuid": netuid,
"commit": commit_for_reveal,
"reveal_round": reveal_round,
"commit_reveal_version": commit_reveal_version,
},
)
success, message = await subtensor.sign_and_send_extrinsic(
call=call,
wallet=wallet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
sign_with="hotkey",
period=period,
raise_error=raise_error,
)
# Encrypt `commit_hash` with t-lock and `get reveal_round`
commit_for_reveal, reveal_round = get_encrypted_commit(
uids=uids,
weights=weights,
version_key=version_key,
tempo=tempo,
current_block=current_block["header"]["number"],
netuid=netuid,
subnet_reveal_period_epochs=subnet_reveal_period_epochs,
block_time=block_time,
hotkey=wallet.hotkey.public_key,
)

logging.info(
f"Committing weights hash [blue]{commit_for_reveal.hex()}[/blue] for subnet #[blue]{netuid}[/blue] with "
f"reveal round [blue]{reveal_round}[/blue]..."
)

if not success:
logging.error(message)
return False, message
call = await subtensor.substrate.compose_call(
call_module="SubtensorModule",
call_function="commit_timelocked_weights",
call_params={
"netuid": netuid,
"commit": commit_for_reveal,
"reveal_round": reveal_round,
"commit_reveal_version": commit_reveal_version,
},
)
response = await subtensor.sign_and_send_extrinsic(
call=call,
wallet=wallet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
sign_with="hotkey",
period=period,
raise_error=raise_error,
calling_function=get_function_name(),
)

if response.success:
logging.success(
f"[green]Finalized![/green] Weights committed with reveal round [blue]{reveal_round}[/blue]."
)
return True, f"reveal_round:{reveal_round}"
response.data = {"reveal_round": reveal_round}
return response

except Exception as e:
logging.error(f":cross_mark: [red]Failed. Error:[/red] {e}")
return False, str(e)
logging.error(response.message)
return response
Loading
Loading