Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
417 commits
Select commit Hold shift + click to select a range
49f5a94
e2e-test <- (prepare-deps, supported-versions)
Sep 5, 2025
5b1f508
try more power
Sep 5, 2025
e0a2d9b
try ignor GH cache warnings + back 32 parallel
Sep 5, 2025
4fa42a2
max-parallel: 16
Sep 5, 2025
7c55fe4
Flake8 and Mypy - linters check
Sep 5, 2025
28620d5
update mypy and unit tests workflows + use GH vars
Sep 5, 2025
4525154
Using shared cache and vars.SDK_SUPPORTED_PYTHON_VERSIONS to pass pyt…
Sep 5, 2025
ebe80e4
try 8 * 4 max-parallel
Sep 5, 2025
a2f3b08
16 * 4 max-parallel back
Sep 5, 2025
1b19ea6
update migration.md
Sep 5, 2025
13d5d47
add `bittensor.core.types.ExtrinsicResponse`
Sep 5, 2025
59e6653
update `sign_and_send_extrinsic` with ExtrinsicResponse
Sep 5, 2025
bc648eb
improve `set_children_extrinsic` + `root_set_pending_childkey_cooldow…
Sep 5, 2025
f02b097
improve `ExtrinsicResponse`
Sep 6, 2025
1fc2795
fix test_children.py
Sep 6, 2025
2df5a68
update `commit_reveal_extrinsic` + tests
Sep 6, 2025
55bd772
update migration.md
Sep 6, 2025
2476204
update `commit_weights_extrinsic` + `reveal_weights_extrinsic` + `set…
Sep 6, 2025
2ec5199
update `add_liquidity_extrinsic` + `modify_liquidity_extrinsic` + `re…
Sep 6, 2025
ad89f33
add unlock logging error message
Sep 6, 2025
120015b
support indexing for success and message
Sep 8, 2025
329e364
set `response.is_success="Success"` for all extrinsic in positive case
Sep 8, 2025
8148270
update migration.md
Sep 8, 2025
dde8f12
update return in success case for children extrinsics
Sep 8, 2025
33e05f5
update return in success case for `commit_reveal_extrinsic` extrinsic…
Sep 8, 2025
4b61511
update migration.md
Sep 8, 2025
4feed5f
update `test_commit_and_reveal_weights_cr4`
Sep 8, 2025
075979c
improve `ExtrinsicResponse`
Sep 8, 2025
12115ba
update `liquidity` docstrings
Sep 8, 2025
5674a3d
update `test_commit_reveal_v3_extrinsic*`
Sep 8, 2025
e1061b1
update `children_extrinsic*`
Sep 8, 2025
79600f7
update `transfer_stake_extrinsic`, `swap_stake_extrinsic` and `move_s…
Sep 8, 2025
3f8ae7a
fix unit tests
Sep 8, 2025
903b16f
`root_register_extrinsic`, `subtensor.burned_register` and `subtensor…
Sep 8, 2025
cad6915
`burned_register_extrinsic`, `register_subnet_extrinsic`, `register_e…
Sep 8, 2025
bd9e833
oops, need to remove
Sep 8, 2025
b85d5dd
improve `ExtrinsicResponse` description
Sep 8, 2025
ba12eea
update `publish_metadata` extrinsic + tests
Sep 9, 2025
b2fcfce
update `publish_metadata` -> `publish_metadata_extrinsic`
Sep 9, 2025
7a56176
`add_stake_extrinsic`, `subtensor.add_stake`, `add_stake_multiple_ext…
Sep 9, 2025
55c4064
`start_call_extrinsic`, `subtensor.start_call` + tests
Sep 9, 2025
0e003df
`increase_take_extrinsic`, `decrease_take_extrinsic`, `subtensor.set_…
Sep 9, 2025
c505072
`transfer_extrinsic`, `subtensor.transfer` + tests
Sep 9, 2025
d7527ee
`unstake_extrinsic`, `unstake_all_extrinsic`, `unstake_multiple_extri…
Sep 9, 2025
74047ae
update migration.md
Sep 9, 2025
445ee18
update `ExtrinsicResponse.__str__`
Sep 9, 2025
3e2dea1
opps, update response processing in tests
Sep 9, 2025
f764065
trigger cached venv properly
Sep 9, 2025
7f15d1d
try avoid deps downloading freez
Sep 9, 2025
52d46f2
update message
Sep 9, 2025
4e02e5c
fix `get_extrinsic_fee`
Sep 17, 2025
37bf840
reveal_weights_extrinsic: add `raise_error` + args order
Sep 17, 2025
213daa6
add args names in chain_interactions.py
Sep 17, 2025
cff98f4
sign_and_send_extrinsic: update args order
Sep 17, 2025
1b14804
fix tests after merge `staging`
Sep 17, 2025
1ba1749
ExtrinsicResponse
Sep 23, 2025
fb08085
fixes after rebase
Sep 23, 2025
d4252d6
delete commit reveal v3 + tests
Sep 23, 2025
21af762
removing deprecated extrinsics and replacing them with consistent ones
Sep 23, 2025
5055200
delete unnecessary comments
Sep 23, 2025
ee0683e
update subtensor calls
Sep 23, 2025
82f8f4d
fix test, delete unnecessary ones
Sep 23, 2025
609999e
Update MIGRATION.md
Sep 23, 2025
54c9a52
docstrings update + small refactoring and improvement
Sep 23, 2025
09b0785
docstrings: removed `default to/is`
Sep 23, 2025
5defaf4
rollback with typing.Self
Sep 23, 2025
f1111e7
remove `bittensor.utils.substrate_utils` (not used)
Sep 23, 2025
038e9bd
remove unused parameters
Sep 23, 2025
e9b16c7
F401 'bittensor.utils.deprecated_message' imported but unused
Sep 23, 2025
e4caf72
fix tests
Sep 23, 2025
8b0be7d
fix e2e tests (fee related
Sep 23, 2025
f1d4f72
add logging
Sep 29, 2025
23981a3
add `get_caller_name`
Sep 29, 2025
a3c1354
improve extrinsics
Sep 29, 2025
16ef067
improve ExtrinsicResponse class
Sep 29, 2025
091c3ca
update/fix tests
Sep 29, 2025
f6eabed
remove old files
Sep 29, 2025
b0a3b51
update readme and license
Sep 29, 2025
8909a1c
improve SubtensorApi
Sep 29, 2025
5c9b518
update subtensor classes
Sep 29, 2025
ef43b45
pyproject.toml
Sep 29, 2025
c5d703e
update MIGRATION.md
Sep 29, 2025
3ded4c6
fix and improve tests + ruff
Sep 29, 2025
1b13039
try faster runners
Sep 29, 2025
c332b44
nope
Sep 29, 2025
b6708fd
more time to re-run docker
Sep 29, 2025
47fdf90
fix if logic for fast block test
Sep 29, 2025
e8a9e1d
add `ExtrinsicResponse.extrinsic_receipt`
Sep 29, 2025
e1fb62f
check GPG
Sep 29, 2025
c6738c1
fix field representation
Sep 29, 2025
603b06b
uncomment tests
Sep 29, 2025
2882b42
test GPG
Sep 29, 2025
b1f407b
uncomment one more test
Sep 29, 2025
53ab89c
e2e tests conftest Finished
basfroman Sep 29, 2025
788559c
mechid related changes
basfroman Sep 29, 2025
a84f8d3
fix tests
basfroman Sep 29, 2025
ba633be
update MIGRATION.md
basfroman Sep 29, 2025
3a3ed12
opps e2e test fix
basfroman Sep 29, 2025
eee0c64
method `get_stake_for_coldkey` removed, bc this is the same as `get_s…
basfroman Sep 29, 2025
5bde1ea
`bittensor.core.subtensor_api` moved to `bittensor.core.addons.subten…
basfroman Sep 29, 2025
39b8eb2
fix imports + move timelock impl to addons
basfroman Sep 29, 2025
ecd8aac
more
basfroman Sep 29, 2025
4fab114
rename `SubtensorApi._subtensor` -> `SubtensorApi.inner_subtensor`
basfroman Sep 29, 2025
1ea45d4
updated order
basfroman Sep 29, 2025
5afe812
- method `get_subnets` renamed to `get_all_subnets_netuid` (more obvi…
basfroman Sep 29, 2025
348bc74
method `get_owned_hotkeys` get rid `reuse_block` parameter to be cons…
basfroman Sep 29, 2025
d9111d5
All liquidity methods and related extrinsics received a renamed param…
basfroman Sep 29, 2025
b9c3dcc
deprecated `bittensor.utils.version.version_checking` removed
basfroman Sep 30, 2025
63b1183
rename `hotkey` > `hotkey_ss58` in liquidity methods and extrinsics +…
basfroman Sep 30, 2025
a84677c
method `blocks_since_last_update` improved. Currently it can be used …
basfroman Sep 30, 2025
0008944
method `blocks_since_last_update` improved. Currently it can be used …
basfroman Sep 30, 2025
073ec66
attribute `DelegateInfo/lite.total_daily_return` has been deleted (Vu…
basfroman Sep 30, 2025
abb9421
fix integration tests
basfroman Sep 30, 2025
f66cd68
fix integration tests + - `Async/Subtensor` parameter `_mock` renamed…
basfroman Sep 30, 2025
781ae4e
update MIGRATION.md
basfroman Sep 30, 2025
0c5c9b4
update MIGRATION.md
basfroman Sep 30, 2025
39cc0c6
ops, _mock
basfroman Sep 30, 2025
a91cc86
fix `tests/e2e_tests/test_delegate.py`
basfroman Sep 30, 2025
94df7c6
BT_SUBTENSOR_CHAIN_ENDPOINT + MIGRATION.md
basfroman Sep 30, 2025
4c32471
ruff
basfroman Sep 30, 2025
43998af
fix `get_async_subtensor`
basfroman Sep 30, 2025
bbae839
improve `easy_import.py`: removing inconsistent class names + referen…
basfroman Sep 30, 2025
796157a
update MIGRATION.md
basfroman Sep 30, 2025
56bfa64
use updated `subnet-template`
basfroman Sep 30, 2025
db78c24
use regular `subnet-template` (merged)
basfroman Sep 30, 2025
05aa654
mode addons from `bittensor.core.addons` to `bittensor.addons` (logic…
basfroman Sep 30, 2025
0fad171
Balance has strict check operations between instances regarding unit…
basfroman Sep 30, 2025
95c0187
add `hex_to_ss58` and `ss58_to_hex` to `bittensor.utils.__init__`
basfroman Sep 30, 2025
a0d5164
new custom errors for balance check
basfroman Sep 30, 2025
13b2dff
`check_and_convert_to_balance` renamed to `check_balance_amount` + ne…
basfroman Sep 30, 2025
1750422
improve tests
basfroman Sep 30, 2025
454920c
add `check_balance_amount` across subtensor's and extrinsics codebase…
basfroman Sep 30, 2025
6c772c4
fix `get_transfer_fee`
basfroman Sep 30, 2025
a4ec8a4
set debug for the login when block is older 300 in metagraph
basfroman Sep 30, 2025
dcbe2b6
Update bittensor/utils/balance.py
basfroman Oct 2, 2025
923d349
Update bittensor/utils/balance.py
basfroman Oct 2, 2025
42aa570
review fixes
basfroman Oct 2, 2025
2817687
`bittensor.addons` -> `bittensor.extras`
basfroman Oct 2, 2025
c9439b5
important wording
basfroman Oct 2, 2025
3085d00
update extrinsics
basfroman Oct 2, 2025
0ca5bb7
update related subtensor calls and docstrings
basfroman Oct 2, 2025
4cc7fe7
update tests
basfroman Oct 2, 2025
61d0723
fix tests after rebase + update structure
basfroman Oct 4, 2025
5fb05c3
add test framework
basfroman Oct 4, 2025
ecf5e48
make `sudo_call_extrinsic` super useful
basfroman Oct 4, 2025
da6d3a6
update SubtensorApi
basfroman Oct 4, 2025
4a0d278
one more unit test
basfroman Oct 4, 2025
7fe01a5
imports optimization
basfroman Oct 4, 2025
7844956
apply framework to all e2e tests
basfroman Oct 4, 2025
88b2b62
ruff
basfroman Oct 4, 2025
b9f3e7d
update MIGRATION.md
basfroman Oct 4, 2025
4d86995
oops top much wait. fixed
basfroman Oct 4, 2025
09ee46e
add `tests/e2e_tests/framework/README.md`
basfroman Oct 4, 2025
52fa878
add import
basfroman Oct 4, 2025
a4f8e1b
API
basfroman Oct 4, 2025
3334af2
add class BlockInfo
basfroman Oct 5, 2025
e6969c9
add `subtensor.get_block_info` method
basfroman Oct 5, 2025
81874fe
update SubtensorApi
basfroman Oct 5, 2025
a2128fc
fix format + add tao app link to BlockInfo
basfroman Oct 5, 2025
40a93c9
add block
basfroman Oct 5, 2025
265e7b6
add `set_trace` for `log_verbose=True`
basfroman Oct 5, 2025
62bbdbf
add docstring
basfroman Oct 5, 2025
f824df9
add cast for checking pass
basfroman Oct 5, 2025
421455e
add unit tests
basfroman Oct 5, 2025
add72c6
move tests test_blocks and ruff
basfroman Oct 5, 2025
fba0a0b
add simple e2e tests for `get_block_info` + update MIGRATION.md
basfroman Oct 5, 2025
488c634
move methods to subtensor
basfroman Oct 5, 2025
15db098
update SubtensorApi
basfroman Oct 5, 2025
f599d39
fix tests
basfroman Oct 5, 2025
3b794af
update MIGRATION.md
basfroman Oct 5, 2025
f81e9b3
proper naming from review
basfroman Oct 6, 2025
311e154
update SubtensorApi
basfroman Oct 6, 2025
7b07eeb
fix tests
basfroman Oct 6, 2025
bee04ce
update MIGRATION.md
basfroman Oct 6, 2025
c72b213
fix get_last_commitment_bonds_reset_block
basfroman Oct 6, 2025
6e05e92
fix unit test
basfroman Oct 6, 2025
8a92175
move `tests.e2e_tests.framework` to `bittensor.extras.dev_framework`
basfroman Oct 6, 2025
daed40c
change name in README.md
basfroman Oct 6, 2025
9c83f8a
remove unused imports
basfroman Oct 6, 2025
b660723
fix test
basfroman Oct 6, 2025
c25b859
fix import
basfroman Oct 6, 2025
9b6ab1f
typo
basfroman Oct 6, 2025
a735843
Update bittensor/core/async_subtensor.py
basfroman Oct 6, 2025
d81d102
Update bittensor/core/subtensor.py
basfroman Oct 6, 2025
f6643b2
Update bittensor/core/types.py
basfroman Oct 6, 2025
9907762
Update tests/unit_tests/test_subtensor.py
basfroman Oct 6, 2025
7f6e883
update method
basfroman Oct 6, 2025
7bcd790
update class
basfroman Oct 6, 2025
4a6b5c5
fix tests
basfroman Oct 6, 2025
93ae00a
avoid close substrate after this call
basfroman Oct 6, 2025
7cd5e32
update `sudo_call_extrinsic`
basfroman Oct 6, 2025
f24f829
update `async_set_hyperparameter` and `set_hyperparameter`
basfroman Oct 6, 2025
bf7a132
more updates
basfroman Oct 6, 2025
2f4b5b6
update settings.py (`BT_NETWORK` -> `BT_SUBTENSOR_NETWORK`)
basfroman Oct 7, 2025
42997a0
update config.py (check for `BT_PARSE_CLI_ARGS` added)
basfroman Oct 7, 2025
e7ad1ea
update MIGRATION.md
basfroman Oct 7, 2025
7566616
add tests
basfroman Oct 7, 2025
f3778d3
update MIGRATION.md
basfroman Oct 7, 2025
5bb795a
revers logic
basfroman Oct 7, 2025
3f10370
flaky test
basfroman Oct 7, 2025
b6a7d06
alphabetical order of methods
basfroman Oct 7, 2025
3b8d0a9
add `SimSwapResult`
basfroman Oct 8, 2025
4fb1869
Added `bittensor.core.extrinsics.params` subpackage. This package wil…
basfroman Oct 8, 2025
de0cbd9
update `check_balance_amount`
basfroman Oct 8, 2025
a53d4d5
move `get_transfer_fn_params` to new subpackage
basfroman Oct 8, 2025
04ad6e1
apply params logic to all extrinsics
basfroman Oct 8, 2025
444fcf7
improve `ExtrinsicResponse`
basfroman Oct 8, 2025
2ab789a
update SubtensorApi
basfroman Oct 8, 2025
fcb16c9
ruff
basfroman Oct 8, 2025
62b357d
move `utils.get_extrinsic_fee` to `subtensor.get_extrinsic_fee`
basfroman Oct 8, 2025
fb40f1a
let's use `subtensor.compose_call` instead of `substrate.compose_call`
basfroman Oct 8, 2025
d484bb5
update Subtensor class and MIGRATION.md
basfroman Oct 8, 2025
813cb85
new logic for e2e tests staking fee
basfroman Oct 8, 2025
9d5a45e
remove debug
basfroman Oct 8, 2025
907015d
`subtensor.compose_call` applied
basfroman Oct 8, 2025
9410070
remove unused import
basfroman Oct 8, 2025
75c7aa8
update unit test regarding a new logic
basfroman Oct 8, 2025
2e55338
no flaky anymore - at least locally (tested 10 times :D )
basfroman Oct 8, 2025
e80420e
additional delay
basfroman Oct 8, 2025
3313743
ruff
basfroman Oct 8, 2025
01e5371
update MIGRATION.md
basfroman Oct 8, 2025
5336513
test_commit_and_reveal_weights_cr4_async
basfroman Oct 9, 2025
6cf3b59
signing_keypair
basfroman Oct 9, 2025
7528cbb
fetch sim_swap by block before extrinsic
basfroman Oct 9, 2025
c262638
TODO in test_root_set_weights.py
basfroman Oct 9, 2025
f6014fd
we doing this in e2e tests
basfroman Oct 9, 2025
928294a
maybe, but in our implementation it doesn't make a difference
basfroman Oct 9, 2025
e380099
ruff
basfroman Oct 9, 2025
82395d4
DRY
basfroman Oct 9, 2025
9c33272
consistent call for `sub.metagraph`
basfroman Oct 9, 2025
82537ad
Metagraphs docstrings
basfroman Oct 9, 2025
1d55a75
async_metagraph
basfroman Oct 9, 2025
e3a17be
don't kill subtensor after async with done
basfroman Oct 9, 2025
2f416aa
bc of logic in `MockSubtensor.neurons_lite` and then
basfroman Oct 9, 2025
7862672
query_map is good
basfroman Oct 9, 2025
80b8d0f
removed. validation handled by `convert_*_uids_and_vals_to_tensor()` …
basfroman Oct 9, 2025
c438874
improve Dev Framework
basfroman Oct 9, 2025
1d76718
update methods with mechid
basfroman Oct 10, 2025
86e9a3b
small refactoring
basfroman Oct 10, 2025
6495386
TODO fix + added test
basfroman Oct 10, 2025
6c40abe
test refactor
basfroman Oct 10, 2025
c9d53b9
close last TODO (e2e test exist)
basfroman Oct 10, 2025
b464685
fix types
basfroman Oct 10, 2025
ec0f92f
Update MIGRATION.md
basfroman Oct 10, 2025
35a51df
fix subtensor error
basfroman Oct 10, 2025
84f3af2
Merge branch 'SDKv10' into feat/roman/TODOs
basfroman Oct 10, 2025
a35314b
ops
basfroman Oct 10, 2025
23b5fb6
e2e
basfroman Oct 10, 2025
f15c9f6
wallets
basfroman Oct 10, 2025
7a75d53
return
basfroman Oct 10, 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: 6 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
13. ✅ Remove `Default is` and `Default to` in docstrings bc parameters enough.
14. ✅ `camfairchild`: TODO, but we should have a grab_metadata if we don't already. Maybe don't decode, but can have a call that removes the Raw prefix, and another just doing grab_metadata_raw (no decoding). `get_commitment_metadata` added.
15. ✅ Resolve an issue where a script using the SDK receives the `--config` or any other CLI parameters used in the SDK. Disable configuration processing. Use default values ​​instead.
16. Find and process all `TODOs` across the entire code base. If in doubt, discuss each one with the team separately. SDK has 29 TODOs.
16. Find and process all `TODOs` across the entire code base. If in doubt, discuss each one with the team separately. SDK has 29 TODOs.

## New features
1. ✅ Unify extrinsic return values by introducing an ExtrinsicResponse class. Extrinsics currently return either a boolean or a tuple.
Expand Down Expand Up @@ -274,6 +274,11 @@ Added sub-package `bittensor.core.addons` to host optional extensions and experi
- local env variable `BT_CHAIN_ENDPOINT` replaced with `BT_SUBTENSOR_CHAIN_ENDPOINT`.


## Metagraph changes:
- all methods with `mechid` parameter has reordered list of parameters.
- async `_initialize_subtensor` method no longer kill the subtensor instance after use.


### Mechid related changes:
In the next subtensor methods got updated the parameters order:
- `bonds`
Expand Down
26 changes: 4 additions & 22 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,7 @@ async def initialize(self):
raise ConnectionError

async def __aenter__(self):
logging.info(
f"[magenta]Connecting to Substrate:[/magenta] [blue]{self}[/blue][magenta]...[/magenta]"
)
try:
await self.substrate.initialize()
return self
except TimeoutError:
logging.error(
f"[red]Error[/red]: Timeout occurred connecting to substrate."
f" Verify your chain and network settings: {self}"
)
raise ConnectionError
except (ConnectionRefusedError, ssl.SSLError) as error:
logging.error(
f"[red]Error[/red]: Connection refused when connecting to substrate. "
f"Verify your chain and network settings: {self}. Error: {error}"
)
raise ConnectionError
return await self.initialize()

async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.substrate.close()
Expand Down Expand Up @@ -3908,12 +3891,12 @@ async def metagraph(
decentralized architecture, particularly in relation to neuron interconnectivity and consensus processes.
"""
metagraph = AsyncMetagraph(
network=self.chain_endpoint,
netuid=netuid,
mechid=mechid,
network=self.chain_endpoint,
lite=lite,
sync=False,
subtensor=self,
mechid=mechid,
)
await metagraph.sync(block=block, lite=lite, subtensor=self)

Expand Down Expand Up @@ -4379,7 +4362,6 @@ async def weights(
"""
storage_index = get_mechid_storage_index(netuid, mechid)
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
# TODO look into seeing if we can speed this up with storage query
w_map_encoded = await self.substrate.query_map(
module="SubtensorModule",
storage_function="Weights",
Expand Down Expand Up @@ -5647,7 +5629,7 @@ async def _blocks_weight_limit() -> bool:
and await _blocks_weight_limit()
):
logging.debug(
f"Committing weights for subnet [blue]{netuid}[/blue]. "
f"Committing weights {weights} for subnet [blue]{netuid}[/blue]. "
f"Attempt [blue]{retries + 1}[blue] of [green]{max_retries}[/green]."
)
try:
Expand Down
58 changes: 41 additions & 17 deletions bittensor/core/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,11 @@ def addresses(self) -> list[str]:
def __init__(
self,
netuid: int,
mechid: int = 0,
network: str = settings.DEFAULT_NETWORK,
lite: bool = True,
sync: bool = True,
subtensor: Optional[Union["AsyncSubtensor", "Subtensor"]] = None,
mechid: int = 0,
):
"""
Initializes a new instance of the metagraph object, setting up the basic structure and parameters based on the
Expand Down Expand Up @@ -671,7 +671,6 @@ def _create_tensor(data, dtype) -> Tensor:

self.stake = self._create_tensor(neuron_stakes, dtype=np.float32)
"""
# TODO: Check and test the creation of tensor
return (
torch.nn.Parameter(torch.tensor(data, dtype=dtype), requires_grad=False)
if use_torch()
Expand Down Expand Up @@ -706,7 +705,6 @@ def _process_weights_or_bonds(self, data, attribute: str) -> Tensor:
data_array.append(np.zeros(len(self.neurons), dtype=np.float32))
else:
uids, values = zip(*item)
# TODO: Validate and test the conversion of uids and values to tensor
if attribute == "weights":
data_array.append(
convert_weight_uids_and_vals_to_tensor(
Expand Down Expand Up @@ -1033,11 +1031,11 @@ class TorchMetagraph(MetagraphMixin, BaseClass):
def __init__(
self,
netuid: int,
mechid: int = 0,
network: str = settings.DEFAULT_NETWORK,
lite: bool = True,
sync: bool = True,
subtensor: Optional[Union["AsyncSubtensor", "Subtensor"]] = None,
mechid: int = 0,
):
"""
Initializes a new instance of the metagraph object, setting up the basic structure and parameters based on the
Expand Down Expand Up @@ -1199,11 +1197,11 @@ class NonTorchMetagraph(MetagraphMixin):
def __init__(
self,
netuid: int,
mechid: int = 0,
network: str = settings.DEFAULT_NETWORK,
lite: bool = True,
sync: bool = True,
subtensor: Optional[Union["AsyncSubtensor", "Subtensor"]] = None,
mechid: int = 0,
):
"""
Initializes a new instance of the metagraph object, setting up the basic structure and parameters based on the
Expand All @@ -1227,7 +1225,7 @@ def __init__(

metagraph = Metagraph(netuid=123, network="finney", lite=True, sync=True)
"""
MetagraphMixin.__init__(self, netuid, network, lite, sync, subtensor, mechid)
MetagraphMixin.__init__(self, netuid, mechid, network, lite, sync, subtensor)

self.netuid = netuid
self.network, self.chain_endpoint = determine_chain_endpoint_and_network(
Expand Down Expand Up @@ -1330,19 +1328,29 @@ def load_from_path(self, dir_path: str) -> "MetagraphMixin":

class AsyncMetagraph(NumpyOrTorch):
"""
TODO docstring. Advise user to use `async_metagraph` factory fn if they want to sync at init
Asynchronous version of the Metagraph class for non-blocking synchronization with the Bittensor network state.

This class allows developers to fetch and update metagraph data using async operations, enabling concurrent
execution in event-driven environments.

Note:
Prefer using the factory function `async_metagraph()` for initialization, which handles async synchronization
automatically.

Example:
metagraph = await async_metagraph(netuid=1, network="finney")
"""

def __init__(
self,
netuid: int,
mechid: int = 0,
network: str = settings.DEFAULT_NETWORK,
lite: bool = True,
sync: bool = True,
subtensor: Optional["AsyncSubtensor"] = None,
mechid: int = 0,
):
super().__init__(netuid, network, lite, sync, subtensor, mechid)
super().__init__(netuid, mechid, network, lite, sync, subtensor)

async def __aenter__(self):
if self.should_sync:
Expand Down Expand Up @@ -1467,8 +1475,9 @@ async def _initialize_subtensor(
# Lazy import due to circular import (subtensor -> metagraph, metagraph -> subtensor)
from bittensor.core.async_subtensor import AsyncSubtensor

async with AsyncSubtensor(network=self.chain_endpoint) as subtensor:
self.subtensor = subtensor
self.subtensor = AsyncSubtensor(network=self.chain_endpoint)
await self.subtensor.initialize()
self.subtensor = subtensor
return subtensor

async def _assign_neurons(
Expand Down Expand Up @@ -1518,7 +1527,6 @@ async def _set_weights_and_bonds(self, subtensor: "AsyncSubtensor", block: int):

self._set_weights_and_bonds(subtensor=subtensor)
"""
# TODO: Check and test the computation of weights and bonds
if self.netuid == 0:
self.weights = await self._process_root_weights(
[neuron.weights for neuron in self.neurons],
Expand Down Expand Up @@ -1568,7 +1576,6 @@ async def _process_root_weights(
data_array.append(np.zeros(n_subnets, dtype=np.float32))
else:
uids, values = zip(*item)
# TODO: Validate and test the conversion of uids and values to tensor
data_array.append(
convert_root_weight_uids_and_vals_to_tensor(
n_subnets, list(uids), list(values), subnets
Expand Down Expand Up @@ -1656,16 +1663,28 @@ async def _apply_extra_info(self, block: int):


class Metagraph(NumpyOrTorch):
"""
Synchronous implementation of the Metagraph, representing the current state of a Bittensor subnet.

The Metagraph encapsulates neuron attributes such as stake, trust, incentive, weights, and connectivity, and
provides methods to synchronize these values directly from the blockchain via a Subtensor instance.

Example:
from bittensor.core.subtensor import Subtensor
subtensor = Subtensor(network="finney")
metagraph = Metagraph(netuid=1, network="finney", sync=True, subtensor=subtensor)
"""

def __init__(
self,
netuid: int,
mechid: int = 0,
network: str = settings.DEFAULT_NETWORK,
lite: bool = True,
sync: bool = True,
subtensor: Optional["Subtensor"] = None,
mechid: int = 0,
):
super().__init__(netuid, network, lite, sync, subtensor, mechid)
super().__init__(netuid, mechid, network, lite, sync, subtensor)
if self.should_sync:
self.sync()

Expand Down Expand Up @@ -1877,7 +1896,6 @@ def _process_root_weights(
data_array.append(np.zeros(n_subnets, dtype=np.float32))
else:
uids, values = zip(*item)
# TODO: Validate and test the conversion of uids and values to tensor
data_array.append(
convert_root_weight_uids_and_vals_to_tensor(
n_subnets, list(uids), list(values), subnets
Expand Down Expand Up @@ -1966,6 +1984,7 @@ def _apply_extra_info(self, block: int):

async def async_metagraph(
netuid: int,
mechid: int = 0,
network: str = settings.DEFAULT_NETWORK,
lite: bool = True,
sync: bool = True,
Expand All @@ -1975,7 +1994,12 @@ async def async_metagraph(
Factory function to create an instantiated AsyncMetagraph, mainly for the ability to use sync at instantiation.
"""
metagraph_ = AsyncMetagraph(
netuid=netuid, network=network, lite=lite, sync=sync, subtensor=subtensor
netuid=netuid,
mechid=mechid,
network=network,
lite=lite,
sync=sync,
subtensor=subtensor,
)
if sync:
await metagraph_.sync()
Expand Down
8 changes: 4 additions & 4 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,11 +1693,11 @@ def get_mechanism_count(
def get_metagraph_info(
self,
netuid: int,
mechid: int = 0,
selected_indices: Optional[
Union[list[SelectiveMetagraphIndex], list[int]]
] = None,
block: Optional[int] = None,
mechid: int = 0,
) -> Optional[MetagraphInfo]:
"""
Retrieves full or partial metagraph information for the specified subnet mechanism (netuid, mechid).
Expand Down Expand Up @@ -2868,12 +2868,12 @@ def metagraph(
decentralized architecture, particularly in relation to neuron interconnectivity and consensus processes.
"""
metagraph = Metagraph(
network=self.chain_endpoint,
netuid=netuid,
mechid=mechid,
network=self.chain_endpoint,
lite=lite,
sync=False,
subtensor=self,
mechid=mechid,
)
metagraph.sync(block=block, lite=lite, subtensor=self)

Expand Down Expand Up @@ -4428,7 +4428,7 @@ def _blocks_weight_limit() -> bool:
and _blocks_weight_limit()
):
logging.debug(
f"Committing weights for subnet [blue]{netuid}[/blue]. "
f"Committing weights {weights} for subnet [blue]{netuid}[/blue]. "
f"Attempt [blue]{retries + 1}[blue] of [green]{max_retries}[/green]."
)
try:
Expand Down
4 changes: 2 additions & 2 deletions bittensor/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _check_and_log_network_settings(self):
"This increases decentralization and resilience of the network."
)

@staticmethod # TODO can this be a class method?
@staticmethod
def config() -> "Config":
"""
Creates and returns a Bittensor configuration object.
Expand All @@ -72,7 +72,7 @@ def config() -> "Config":
return Config(parser)

@staticmethod
def setup_config(network: Optional[str], config: "Config"):
def setup_config(network: Optional[str], config: "Config") -> tuple[str, str]:
"""
Sets up and returns the configuration for the Subtensor network and endpoint.

Expand Down
11 changes: 9 additions & 2 deletions bittensor/extras/dev_framework/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ def __init__(
self.wait_for_finalization = wait_for_finalization

self._netuid: Optional[int] = None
self._owner: Optional[Wallet] = None
self._calls: list[CALL_RECORD] = []

@property
def calls(self):
def calls(self) -> list[CALL_RECORD]:
return self._calls

@property
def netuid(self):
def netuid(self) -> int:
return self._netuid

@property
def owner(self) -> Wallet:
return self._owner

def execute_steps(self, steps: list[Union[STEPS, tuple]]):
"""Executes a multiple steps synchronously."""
for step in steps:
Expand Down Expand Up @@ -214,6 +219,7 @@ def _register_subnet(
else:
self._netuid = self.s.subnets.get_total_subnets() - 1
if response.success:
self._owner = owner_wallet
logging.console.info(f"Subnet [blue]{self._netuid}[/blue] was registered.")
self._add_call_record(REGISTER_SUBNET.__name__, response)
return response
Expand Down Expand Up @@ -243,6 +249,7 @@ async def _async_register_subnet(
else:
self._netuid = self.s.subnets.get_total_subnets() - 1
if response.success:
self._owner = owner_wallet
logging.console.info(f"Subnet [blue]{self._netuid}[/blue] was registered.")
self._add_call_record(REGISTER_SUBNET.__name__, response)
return response
Expand Down
1 change: 0 additions & 1 deletion bittensor/utils/mock/subtensor_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,6 @@ def neuron_for_uid_lite(

neuron_info = self._neuron_subnet_exists(uid, netuid, block)
if neuron_info is None:
# TODO Why does this return None here but a null neuron earlier?
return None

else:
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e_tests/test_hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
RegistrationNotPermittedOnRootSubnet,
SubnetNotExists,
InvalidChild,
TooManyChildren,
ProportionOverflow,
DuplicateChild,
TxRateLimitExceeded,
Expand Down Expand Up @@ -227,7 +226,7 @@ def test_children(subtensor, alice_wallet, bob_wallet, dave_wallet):
)

with pytest.raises(DuplicateChild):
subtensor.set_children(
subtensor.wallets.set_children(
wallet=alice_wallet,
hotkey_ss58=alice_wallet.hotkey.ss58_address,
netuid=dave_sn.netuid,
Expand Down Expand Up @@ -532,7 +531,7 @@ async def test_children_async(async_subtensor, alice_wallet, bob_wallet, dave_wa
raise_error=True,
)

with pytest.raises(TooManyChildren):
with pytest.raises(DuplicateChild):
await async_subtensor.extrinsics.set_children(
wallet=alice_wallet,
hotkey_ss58=alice_wallet.hotkey.ss58_address,
Expand Down
Loading