Skip to content

Commit 04fe4d9

Browse files
authored
Merge pull request #3052 from opentensor/fix/roman/fix-after-Rate-limit-hyperparams-setting
Fix after `Rate limit hyperparams setting`
2 parents c8711b2 + 01b9d64 commit 04fe4d9

File tree

9 files changed

+187
-3
lines changed

9 files changed

+187
-3
lines changed

bittensor/core/async_subtensor.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,33 @@ async def does_hotkey_exist(
11041104
)
11051105
return return_val
11061106

1107+
async def get_admin_freeze_window(
1108+
self,
1109+
block: Optional[int] = None,
1110+
block_hash: Optional[str] = None,
1111+
reuse_block: bool = False,
1112+
) -> int:
1113+
"""
1114+
Returns the number of blocks when dependent transactions will be frozen for execution.
1115+
1116+
Arguments:
1117+
block: The block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
1118+
reuse_block.
1119+
block_hash: The hash of the blockchain block for the query. Do not specify if using block or reuse_block.
1120+
reuse_block: Whether to reuse the last-used block hash. Do not set if using block_hash or block.
1121+
1122+
Returns:
1123+
AdminFreezeWindow as integer. The number of blocks are frozen.
1124+
"""
1125+
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
1126+
return (
1127+
await self.substrate.query(
1128+
module="SubtensorModule",
1129+
storage_function="AdminFreezeWindow",
1130+
block_hash=block_hash,
1131+
)
1132+
).value
1133+
11071134
async def get_all_subnets_info(
11081135
self,
11091136
block: Optional[int] = None,

bittensor/core/subtensor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,23 @@ def does_hotkey_exist(self, hotkey_ss58: str, block: Optional[int] = None) -> bo
630630
)
631631
return return_val
632632

633+
def get_admin_freeze_window(self, block: Optional[int] = None) -> int:
634+
"""
635+
Returns the number of blocks when dependent transactions will be frozen for execution.
636+
637+
Arguments:
638+
block: The block number for which the children are to be retrieved.
639+
640+
Returns:
641+
AdminFreezeWindow as integer. The number of blocks are frozen.
642+
"""
643+
644+
return self.substrate.query(
645+
module="SubtensorModule",
646+
storage_function="AdminFreezeWindow",
647+
block_hash=self.determine_block_hash(block),
648+
).value
649+
633650
def get_all_subnets_info(self, block: Optional[int] = None) -> list["SubnetInfo"]:
634651
"""
635652
Retrieves detailed information about all subnets within the Bittensor network. This function provides

tests/e2e_tests/test_commit_reveal.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ async def test_commit_and_reveal_weights_cr4(local_chain, subtensor, alice_walle
3131
Raises:
3232
AssertionError: If any of the checks or verifications fail
3333
"""
34+
35+
# turn off admin freeze window limit for testing
36+
assert (
37+
sudo_set_admin_utils(
38+
local_chain,
39+
alice_wallet,
40+
call_function="sudo_set_admin_freeze_window",
41+
call_params={"window": 0},
42+
)[0]
43+
is True
44+
), "Failed to set admin freeze window to 0"
45+
3446
logging.console.info("Testing `test_commit_and_reveal_weights_cr4`")
3547

3648
# 12 for non-fast-block, 0.25 for fast block
@@ -249,6 +261,18 @@ async def test_async_commit_and_reveal_weights_cr4(
249261
Raises:
250262
AssertionError: If any of the checks or verifications fail
251263
"""
264+
265+
# turn off admin freeze window limit for testing
266+
assert (
267+
sudo_set_admin_utils(
268+
local_chain,
269+
alice_wallet,
270+
call_function="sudo_set_admin_freeze_window",
271+
call_params={"window": 0},
272+
)[0]
273+
is True
274+
), "Failed to set admin freeze window to 0"
275+
252276
logging.console.info("Testing `test_commit_and_reveal_weights_cr4`")
253277

254278
async with async_subtensor:

tests/e2e_tests/test_commit_weights.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ async def test_commit_and_reveal_weights_legacy(local_chain, subtensor, alice_wa
2626
Raises:
2727
AssertionError: If any of the checks or verifications fail
2828
"""
29+
30+
# turn off admin freeze window limit for testing
31+
assert (
32+
sudo_set_admin_utils(
33+
local_chain,
34+
alice_wallet,
35+
call_function="sudo_set_admin_freeze_window",
36+
call_params={"window": 0},
37+
)[0]
38+
is True
39+
), "Failed to set admin freeze window to 0"
40+
2941
netuid = subtensor.get_total_subnets() # 2
3042
set_tempo = 100 if subtensor.is_fast_blocks() else 10
3143
print("Testing test_commit_and_reveal_weights")
@@ -165,6 +177,18 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
165177
Raises:
166178
AssertionError: If any of the checks or verifications fail
167179
"""
180+
181+
# turn off admin freeze window limit for testing
182+
assert (
183+
sudo_set_admin_utils(
184+
local_chain,
185+
alice_wallet,
186+
call_function="sudo_set_admin_freeze_window",
187+
call_params={"window": 0},
188+
)[0]
189+
is True
190+
), "Failed to set admin freeze window to 0"
191+
168192
subnet_tempo = 50 if subtensor.is_fast_blocks() else 10
169193
netuid = subtensor.get_total_subnets() # 2
170194

tests/e2e_tests/test_incentive.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
)
1010
from tests.e2e_tests.utils.e2e_test_utils import wait_to_start_call
1111

12-
DURATION_OF_START_CALL = 10
13-
1412

1513
@pytest.mark.asyncio
1614
async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wallet):
@@ -26,6 +24,17 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
2624
AssertionError: If any of the checks or verifications fail
2725
"""
2826

27+
# turn off admin freeze window limit for testing
28+
assert (
29+
sudo_set_admin_utils(
30+
local_chain,
31+
alice_wallet,
32+
call_function="sudo_set_admin_freeze_window",
33+
call_params={"window": 0},
34+
)[0]
35+
is True
36+
), "Failed to set admin freeze window to 0"
37+
2938
print("Testing test_incentive")
3039
alice_subnet_netuid = subtensor.get_total_subnets() # 2
3140

tests/e2e_tests/test_liquid_alpha.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from tests.e2e_tests.utils.chain_interactions import (
44
sudo_set_hyperparameter_bool,
55
sudo_set_hyperparameter_values,
6+
sudo_set_admin_utils,
67
)
78

89

@@ -28,6 +29,17 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
2829
Raises:
2930
AssertionError: If any of the checks or verifications fail
3031
"""
32+
# turn off admin freeze window limit for testing
33+
assert (
34+
sudo_set_admin_utils(
35+
local_chain,
36+
alice_wallet,
37+
call_function="sudo_set_admin_freeze_window",
38+
call_params={"window": 0},
39+
)[0]
40+
is True
41+
), "Failed to set admin freeze window to 0"
42+
3143
u16_max = 65535
3244
netuid = 2
3345
logging.console.info("Testing test_liquid_alpha_enabled")

tests/e2e_tests/test_set_weights.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ async def test_set_weights_uses_next_nonce(local_chain, subtensor, alice_wallet)
2828
AssertionError: If any of the checks or verifications fail
2929
"""
3030

31+
# turn off admin freeze window limit for testing
32+
assert (
33+
sudo_set_admin_utils(
34+
local_chain,
35+
alice_wallet,
36+
call_function="sudo_set_admin_freeze_window",
37+
call_params={"window": 0},
38+
)[0]
39+
is True
40+
), "Failed to set admin freeze window to 0"
41+
3142
netuids = [2, 3]
3243
subnet_tempo = 50
3344
BLOCK_TIME = 0.25 # 12 for non-fast-block, 0.25 for fast block

tests/e2e_tests/test_staking.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ def test_safe_staking_scenarios(
342342
2. Succeeds with strict threshold (0.5%) and partial staking allowed
343343
3. Succeeds with lenient threshold (10% and 30%) and no partial staking
344344
"""
345+
346+
# turn off admin freeze window limit for testing
347+
assert (
348+
sudo_set_admin_utils(
349+
local_chain,
350+
alice_wallet,
351+
call_function="sudo_set_admin_freeze_window",
352+
call_params={"window": 0},
353+
)[0]
354+
is True
355+
), "Failed to set admin freeze window to 0"
356+
345357
alice_subnet_netuid = subtensor.subnets.get_total_subnets() # 2
346358
# Register root as Alice - the subnet owner and validator
347359
assert subtensor.extrinsics.register_subnet(alice_wallet, True, True)

tests/e2e_tests/utils/chain_interactions.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
from bittensor import Wallet
1717
from bittensor.core.async_subtensor import AsyncSubtensor
1818
from bittensor.core.subtensor import Subtensor
19-
from async_substrate_interface import SubstrateInterface, ExtrinsicReceipt
19+
from async_substrate_interface import (
20+
AsyncSubstrateInterface,
21+
AsyncExtrinsicReceipt,
22+
SubstrateInterface,
23+
ExtrinsicReceipt,
24+
)
2025

2126

2227
def get_dynamic_balance(rao: int, netuid: int = 0):
@@ -274,6 +279,49 @@ def sudo_set_admin_utils(
274279
return response.is_success, response.error_message
275280

276281

282+
async def async_sudo_set_admin_utils(
283+
substrate: "AsyncSubstrateInterface",
284+
wallet: "Wallet",
285+
call_function: str,
286+
call_params: dict,
287+
call_module: str = "AdminUtils",
288+
) -> tuple[bool, Optional[dict]]:
289+
"""
290+
Wraps the call in sudo to set hyperparameter values using AdminUtils.
291+
292+
Parameters:
293+
substrate: Substrate connection.
294+
wallet: Wallet object with the keypair for signing.
295+
call_function: The AdminUtils function to call.
296+
call_params: Parameters for the AdminUtils function.
297+
call_module: The AdminUtils module to call. Defaults to "AdminUtils".
298+
299+
Returns:
300+
tuple: (success status, error details).
301+
"""
302+
inner_call = await substrate.compose_call(
303+
call_module=call_module,
304+
call_function=call_function,
305+
call_params=call_params,
306+
)
307+
308+
sudo_call = await substrate.compose_call(
309+
call_module="Sudo",
310+
call_function="sudo",
311+
call_params={"call": inner_call},
312+
)
313+
extrinsic = await substrate.create_signed_extrinsic(
314+
call=sudo_call, keypair=wallet.coldkey
315+
)
316+
response: "AsyncExtrinsicReceipt" = await substrate.submit_extrinsic(
317+
extrinsic,
318+
wait_for_inclusion=True,
319+
wait_for_finalization=True,
320+
)
321+
322+
return await response.is_success, await response.error_message
323+
324+
277325
async def root_set_subtensor_hyperparameter_values(
278326
substrate: "SubstrateInterface",
279327
wallet: "Wallet",

0 commit comments

Comments
 (0)