@@ -117,7 +117,7 @@ def __init__(self, network: str = DEFAULT_NETWORK):
117
117
self .network = network
118
118
if network == "local" :
119
119
logging .warning (
120
- "[yellow] Warning[/yellow] : Verify your local subtensor is running on port 9944."
120
+ "Warning: Verify your local subtensor is running on port 9944."
121
121
)
122
122
else :
123
123
is_valid , _ = validate_chain_endpoint (network )
@@ -1271,19 +1271,19 @@ async def get_delegate_identities(
1271
1271
1272
1272
async def is_hotkey_registered (self , netuid : int , hotkey_ss58 : str ) -> bool :
1273
1273
"""Checks to see if the hotkey is registered on a given netuid"""
1274
- _result = await self .substrate .query (
1274
+ result = await self .substrate .query (
1275
1275
module = "SubtensorModule" ,
1276
1276
storage_function = "Uids" ,
1277
1277
params = [netuid , hotkey_ss58 ],
1278
1278
)
1279
- if _result is not None :
1279
+ if result is not None :
1280
1280
return True
1281
1281
else :
1282
1282
return False
1283
1283
1284
1284
async def get_uid_for_hotkey_on_subnet (
1285
1285
self , hotkey_ss58 : str , netuid : int , block_hash : Optional [str ] = None
1286
- ):
1286
+ ) -> Optional [ int ] :
1287
1287
"""
1288
1288
Retrieves the unique identifier (UID) for a neuron's hotkey on a specific subnet.
1289
1289
@@ -1297,12 +1297,42 @@ async def get_uid_for_hotkey_on_subnet(
1297
1297
1298
1298
The UID is a critical identifier within the network, linking the neuron's hotkey to its operational and governance activities on a particular subnet.
1299
1299
"""
1300
- return self .substrate .query (
1300
+ result = await self .substrate .query (
1301
1301
module = "SubtensorModule" ,
1302
1302
storage_function = "Uids" ,
1303
1303
params = [netuid , hotkey_ss58 ],
1304
1304
block_hash = block_hash ,
1305
1305
)
1306
+ return result
1307
+
1308
+ async def weights_rate_limit (self , netuid : int ) -> Optional [int ]:
1309
+ """
1310
+ Returns network WeightsSetRateLimit hyperparameter.
1311
+
1312
+ Args:
1313
+ netuid (int): The unique identifier of the subnetwork.
1314
+
1315
+ Returns:
1316
+ Optional[int]: The value of the WeightsSetRateLimit hyperparameter, or ``None`` if the subnetwork does not exist or the parameter is not found.
1317
+ """
1318
+ call = await self .get_hyperparameter (
1319
+ param_name = "WeightsSetRateLimit" , netuid = netuid
1320
+ )
1321
+ return None if call is None else int (call )
1322
+
1323
+ async def blocks_since_last_update (self , netuid : int , uid : int ) -> Optional [int ]:
1324
+ """
1325
+ Returns the number of blocks since the last update for a specific UID in the subnetwork.
1326
+
1327
+ Args:
1328
+ netuid (int): The unique identifier of the subnetwork.
1329
+ uid (int): The unique identifier of the neuron.
1330
+
1331
+ Returns:
1332
+ Optional[int]: The number of blocks since the last update, or ``None`` if the subnetwork or UID does not exist.
1333
+ """
1334
+ call = await self .get_hyperparameter (param_name = "LastUpdate" , netuid = netuid )
1335
+ return None if call is None else await self .get_current_block () - int (call [uid ])
1306
1336
1307
1337
# extrinsics
1308
1338
@@ -1445,12 +1475,15 @@ async def set_weights(
1445
1475
1446
1476
This function is crucial in shaping the network's collective intelligence, where each neuron's learning and contribution are influenced by the weights it sets towards others【81†source】.
1447
1477
"""
1448
- uid = self .get_uid_for_hotkey_on_subnet (wallet .hotkey .ss58_address , netuid )
1478
+ uid = await self .get_uid_for_hotkey_on_subnet (
1479
+ wallet .hotkey .ss58_address , netuid
1480
+ )
1449
1481
retries = 0
1450
1482
success = False
1451
1483
message = "No attempt made. Perhaps it is too soon to set weights!"
1452
1484
while (
1453
- self .blocks_since_last_update (netuid , uid ) > self .weights_rate_limit (netuid ) # type: ignore
1485
+ await self .blocks_since_last_update (netuid , uid )
1486
+ > await self .weights_rate_limit (netuid )
1454
1487
and retries < max_retries
1455
1488
):
1456
1489
try :
0 commit comments