Skip to content

Commit 2111900

Browse files
authored
Merge pull request #3076 from opentensor/feat/roman/mechid-related-changes
[v10] `mechid` related changes
2 parents 0229d35 + 4c2e128 commit 2111900

File tree

8 files changed

+85
-64
lines changed

8 files changed

+85
-64
lines changed

MIGRATION.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,20 @@ Removing deprecated extrinsics and replacing them with consistent ones:
234234
- method `query_map_subtensor` has updated parameters order.
235235
- method `query_map` has updated parameters order.
236236
- method `add_stake_multiple` has updated parameters order.
237+
238+
### Mechid related changes:
239+
In the next subtensor methods got updated the parameters order:
240+
- `bonds`
241+
- `get_metagraph_info`
242+
- `get_timelocked_weight_commits`
243+
- `metagraph`
244+
- `weights`
245+
- `commit_weights`
246+
- `reveal_weights`
247+
- `set_weights`
248+
249+
Additional:
250+
- `bittensor.core.chain_data.metagraph_info.MetagraphInfo` got required attribute `mechid: int`.
251+
252+
### Renames parameters:
253+
- `get_metagraph_info`: `field_indices` -> `selected_indices` (to be consistent)

bittensor/core/async_subtensor.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -869,10 +869,10 @@ async def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]
869869
async def bonds(
870870
self,
871871
netuid: int,
872+
mechid: int = 0,
872873
block: Optional[int] = None,
873874
block_hash: Optional[str] = None,
874875
reuse_block: bool = False,
875-
mechid: int = 0,
876876
) -> list[tuple[int, list[tuple[int, int]]]]:
877877
"""Retrieves the bond distribution set by subnet validators within a specific subnet.
878878
@@ -882,10 +882,10 @@ async def bonds(
882882
883883
Parameters:
884884
netuid: Subnet identifier.
885+
mechid: Subnet mechanism identifier.
885886
block: The block number for this query. Do not specify if using block_hash or reuse_block.
886887
block_hash: The hash of the block for the query. Do not specify if using reuse_block or block.
887888
reuse_block: Whether to reuse the last-used block hash. Do not set if using block_hash or block.
888-
mechid: Subnet mechanism identifier.
889889
890890
Returns:
891891
List of tuples mapping each neuron's UID to its bonds with other neurons.
@@ -1921,15 +1921,16 @@ async def get_minimum_required_stake(self):
19211921

19221922
return Balance.from_rao(getattr(result, "value", 0))
19231923

1924-
# TODO: update parameters order in SDKv10, rename `field_indices` to `selected_indices`
19251924
async def get_metagraph_info(
19261925
self,
19271926
netuid: int,
1928-
field_indices: Optional[Union[list[SelectiveMetagraphIndex], list[int]]] = None,
1927+
mechid: int = 0,
1928+
selected_indices: Optional[
1929+
Union[list[SelectiveMetagraphIndex], list[int]]
1930+
] = None,
19291931
block: Optional[int] = None,
19301932
block_hash: Optional[str] = None,
19311933
reuse_block: bool = False,
1932-
mechid: int = 0,
19331934
) -> Optional[MetagraphInfo]:
19341935
"""
19351936
Retrieves full or partial metagraph information for the specified subnet (netuid).
@@ -1940,7 +1941,7 @@ async def get_metagraph_info(
19401941
19411942
Parameters:
19421943
netuid: The unique identifier of the subnet to query.
1943-
field_indices: Optional list of SelectiveMetagraphIndex or int values specifying which fields to retrieve.
1944+
selected_indices: Optional list of SelectiveMetagraphIndex or int values specifying which fields to retrieve.
19441945
If not provided, all available fields will be returned.
19451946
block: The blockchain block number for the query.
19461947
block_hash: The hash of the blockchain block number at which to perform the query.
@@ -1960,14 +1961,14 @@ async def get_metagraph_info(
19601961
# Retrieve selective data from the metagraph from subnet 2 mechanism 0
19611962
partial_meta_info = subtensor.get_metagraph_info(
19621963
netuid=2,
1963-
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
1964+
selected_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
19641965
)
19651966
19661967
# Retrieve selective data from the metagraph from subnet 2 mechanism 1
19671968
partial_meta_info = subtensor.get_metagraph_info(
19681969
netuid=2,
19691970
mechid=1,
1970-
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
1971+
selected_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
19711972
)
19721973
19731974
Notes:
@@ -1982,9 +1983,9 @@ async def get_metagraph_info(
19821983
indexes = (
19831984
[
19841985
f.value if isinstance(f, SelectiveMetagraphIndex) else f
1985-
for f in field_indices
1986+
for f in selected_indices
19861987
]
1987-
if field_indices is not None
1988+
if selected_indices is not None
19881989
else [f for f in range(len(SelectiveMetagraphIndex))]
19891990
)
19901991

@@ -2695,24 +2696,23 @@ async def get_subnet_prices(
26952696
prices.update({0: Balance.from_tao(1)})
26962697
return prices
26972698

2698-
# TODO: update order in SDKv10
26992699
async def get_timelocked_weight_commits(
27002700
self,
27012701
netuid: int,
2702+
mechid: int = 0,
27022703
block: Optional[int] = None,
27032704
block_hash: Optional[str] = None,
27042705
reuse_block: bool = False,
2705-
mechid: int = 0,
27062706
) -> list[tuple[str, int, str, int]]:
27072707
"""
27082708
Retrieves CRv4 weight commit information for a specific subnet.
27092709
27102710
Parameters:
27112711
netuid: Subnet identifier.
2712-
block (Optional[int]): The blockchain block number for the query.
2712+
mechid: Subnet mechanism identifier.
2713+
block: The blockchain block number for the query.
27132714
block_hash: The hash of the block to retrieve the stake from. Do not specify if using block or reuse_block.
27142715
reuse_block: Whether to use the last-used block. Do not set if using block_hash or block.
2715-
mechid: Subnet mechanism identifier.
27162716
27172717
Returns:
27182718
A list of commit details, where each item contains:
@@ -3539,23 +3539,22 @@ async def max_weight_limit(
35393539
)
35403540
return None if call is None else u16_normalized_float(int(call))
35413541

3542-
# TODO: update parameters order in SDKv10
35433542
async def metagraph(
35443543
self,
35453544
netuid: int,
3545+
mechid: int = 0,
35463546
lite: bool = True,
35473547
block: Optional[int] = None,
3548-
mechid: int = 0,
35493548
) -> "AsyncMetagraph":
35503549
"""
35513550
Returns a synced metagraph for a specified subnet within the Bittensor network.
35523551
The metagraph represents the network's structure, including neuron connections and interactions.
35533552
35543553
Parameters:
35553554
netuid: The network UID of the subnet to query.
3555+
mechid: Subnet mechanism identifier.
35563556
lite: If true, returns a metagraph using a lightweight sync (no weights, no bonds).
35573557
block: Block number for synchronization, or `None` for the latest block.
3558-
mechid: Subnet mechanism identifier.
35593558
35603559
Returns:
35613560
The metagraph representing the subnet's structure and neuron relationships.
@@ -4007,14 +4006,13 @@ async def handler(block_data: dict):
40074006
)
40084007
return True
40094008

4010-
# TODO: update order in SDKv10
40114009
async def weights(
40124010
self,
40134011
netuid: int,
4012+
mechid: int = 0,
40144013
block: Optional[int] = None,
40154014
block_hash: Optional[str] = None,
40164015
reuse_block: bool = False,
4017-
mechid: int = 0,
40184016
) -> list[tuple[int, list[tuple[int, int]]]]:
40194017
"""
40204018
Retrieves the weight distribution set by neurons within a specific subnet of the Bittensor network.
@@ -4463,13 +4461,13 @@ async def commit_weights(
44634461
salt: Salt,
44644462
uids: UIDs,
44654463
weights: Weights,
4464+
mechid: int = 0,
44664465
version_key: int = version_as_int,
44674466
max_retries: int = 5,
44684467
period: Optional[int] = 16,
44694468
raise_error: bool = True,
44704469
wait_for_inclusion: bool = False,
44714470
wait_for_finalization: bool = False,
4472-
mechid: int = 0,
44734471
) -> ExtrinsicResponse:
44744472
"""
44754473
Commits a hash of the subnet validator's weight vector to the Bittensor blockchain using the provided wallet.
@@ -4481,6 +4479,7 @@ async def commit_weights(
44814479
salt: list of randomly generated integers as salt to generated weighted hash.
44824480
uids: NumPy array of neuron UIDs for which weights are being committed.
44834481
weights: NumPy array of weight values corresponding to each UID.
4482+
mechid: The subnet mechanism unique identifier.
44844483
version_key: Version key for compatibility with the network.
44854484
max_retries: The number of maximum attempts to commit weights.
44864485
period: The number of blocks during which the transaction will remain valid after it's submitted. If
@@ -4489,7 +4488,6 @@ async def commit_weights(
44894488
raise_error: Raises a relevant exception rather than returning `False` if unsuccessful.
44904489
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block.
44914490
wait_for_finalization: Whether to wait for finalization of the extrinsic.
4492-
mechid: The subnet mechanism unique identifier.
44934491
44944492
Returns:
44954493
ExtrinsicResponse: The result object of the extrinsic execution.
@@ -4810,13 +4808,13 @@ async def reveal_weights(
48104808
uids: UIDs,
48114809
weights: Weights,
48124810
salt: Salt,
4811+
mechid: int = 0,
48134812
max_retries: int = 5,
48144813
version_key: int = version_as_int,
48154814
period: Optional[int] = 16,
48164815
raise_error: bool = False,
48174816
wait_for_inclusion: bool = True,
48184817
wait_for_finalization: bool = True,
4819-
mechid: int = 0,
48204818
) -> ExtrinsicResponse:
48214819
"""
48224820
Reveals the weights for a specific subnet on the Bittensor blockchain using the provided wallet.
@@ -4828,6 +4826,7 @@ async def reveal_weights(
48284826
uids: NumPy array of neuron UIDs for which weights are being revealed.
48294827
weights: NumPy array of weight values corresponding to each UID.
48304828
salt: NumPy array of salt values corresponding to the hash function.
4829+
mechid: The subnet mechanism unique identifier.
48314830
max_retries: The number of maximum attempts to reveal weights.
48324831
version_key: Version key for compatibility with the network.
48334832
period: The number of blocks during which the transaction will remain valid after it's submitted. If the
@@ -4836,7 +4835,6 @@ async def reveal_weights(
48364835
raise_error: Raises a relevant exception rather than returning `False` if unsuccessful.
48374836
wait_for_inclusion: Waits for the transaction to be included in a block.
48384837
wait_for_finalization: Waits for the transaction to be finalized on the blockchain.
4839-
mechid: The subnet mechanism unique identifier.
48404838
48414839
Returns:
48424840
ExtrinsicResponse: The result object of the extrinsic execution.
@@ -5122,6 +5120,7 @@ async def set_weights(
51225120
netuid: int,
51235121
uids: UIDs,
51245122
weights: Weights,
5123+
mechid: int = 0,
51255124
block_time: float = 12.0,
51265125
commit_reveal_version: int = 4,
51275126
max_retries: int = 5,
@@ -5130,7 +5129,6 @@ async def set_weights(
51305129
raise_error: bool = False,
51315130
wait_for_inclusion: bool = True,
51325131
wait_for_finalization: bool = True,
5133-
mechid: int = 0,
51345132
) -> ExtrinsicResponse:
51355133
"""
51365134
Sets the weight vector for a neuron acting as a validator, specifying the weights assigned to subnet miners
@@ -5146,6 +5144,7 @@ async def set_weights(
51465144
uids: The list of subnet miner neuron UIDs that the weights are being set for.
51475145
weights: The corresponding weights to be set for each UID, representing the validator's evaluation of each
51485146
miner's performance.
5147+
mechid: The subnet mechanism unique identifier.
51495148
block_time: The number of seconds for block duration.
51505149
commit_reveal_version: The version of the chain commit-reveal protocol to use.
51515150
max_retries: The number of maximum attempts to set weights.
@@ -5156,7 +5155,6 @@ async def set_weights(
51565155
raise_error: Raises a relevant exception rather than returning `False` if unsuccessful.
51575156
wait_for_inclusion: Waits for the transaction to be included in a block.
51585157
wait_for_finalization: Waits for the transaction to be finalized on the blockchain.
5159-
mechid: The subnet mechanism unique identifier.
51605158
51615159
Returns:
51625160
ExtrinsicResponse: The result object of the extrinsic execution.

bittensor/core/chain_data/metagraph_info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def process_nested(
7070
class MetagraphInfo(InfoBase):
7171
# Subnet index
7272
netuid: int
73+
mechid: int
7374

7475
# Name and symbol
7576
name: str
@@ -173,8 +174,6 @@ class MetagraphInfo(InfoBase):
173174

174175
commitments: Optional[tuple[tuple[str, str]]]
175176

176-
mechid: int = 0
177-
178177
@classmethod
179178
def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
180179
"""Returns a MetagraphInfo object from decoded chain data."""

0 commit comments

Comments
 (0)