diff --git a/bittensor_cli/src/commands/stake/children_hotkeys.py b/bittensor_cli/src/commands/stake/children_hotkeys.py index 12f52658c..7ad94f131 100644 --- a/bittensor_cli/src/commands/stake/children_hotkeys.py +++ b/bittensor_cli/src/commands/stake/children_hotkeys.py @@ -30,24 +30,22 @@ async def get_childkey_completion_block( """ Calculates the block at which the childkey set request will complete """ + bh = await subtensor.substrate.get_chain_head() blocks_since_last_step_query = subtensor.query( - "SubtensorModule", - "BlocksSinceLastStep", - params=[netuid], + "SubtensorModule", "BlocksSinceLastStep", params=[netuid], block_hash=bh ) tempo_query = subtensor.get_hyperparameter( - param_name="Tempo", - netuid=netuid, + param_name="Tempo", netuid=netuid, block_hash=bh ) block_number, blocks_since_last_step, tempo = await asyncio.gather( - subtensor.substrate.get_block_number(), + subtensor.substrate.get_block_number(block_hash=bh), blocks_since_last_step_query, tempo_query, ) - cooldown = block_number + 1 + cooldown = block_number + 7200 blocks_left_in_tempo = tempo - blocks_since_last_step next_tempo = block_number + blocks_left_in_tempo - next_epoch_after_cooldown = (cooldown - next_tempo) % tempo + cooldown + next_epoch_after_cooldown = (cooldown - next_tempo) % (tempo + 1) + cooldown return block_number, next_epoch_after_cooldown diff --git a/tests/e2e_tests/test_children_hotkeys.py b/tests/e2e_tests/test_children_hotkeys.py new file mode 100644 index 000000000..f286012fd --- /dev/null +++ b/tests/e2e_tests/test_children_hotkeys.py @@ -0,0 +1,15 @@ +import pytest + +from bittensor_cli.src.bittensor.subtensor_interface import SubtensorInterface +from bittensor_cli.src.commands.stake.children_hotkeys import ( + get_childkey_completion_block, +) + + +@pytest.mark.asyncio +async def test_get_childkey_completion_block(local_chain): + async with SubtensorInterface("ws://127.0.0.1:9945") as subtensor: + current_block, completion_block = await get_childkey_completion_block( + subtensor, 1 + ) + assert (completion_block - current_block) >= 7200