Skip to content

Commit b774b41

Browse files
author
Roman
committed
Merge branch 'staging' into feat/roman/add-non-fast-block-tests-each-saturday
2 parents e26d787 + 55ab373 commit b774b41

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

bittensor/core/async_subtensor.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -616,19 +616,31 @@ async def all_subnets(
616616
return subnets
617617

618618
async def blocks_since_last_step(
619-
self, netuid: int, block: Optional[int] = None
619+
self,
620+
netuid: int,
621+
block: Optional[int] = None,
622+
block_hash: Optional[str] = None,
623+
reuse_block: bool = False,
620624
) -> Optional[int]:
621625
"""Returns number of blocks since the last epoch of the subnet.
622626
623627
Arguments:
624628
netuid (int): The unique identifier of the subnetwork.
625629
block: the block number for this query.
630+
block_hash: The hash of the blockchain block number for the query. Do not specify if using reuse_block or
631+
block.
632+
reuse_block: Whether to reuse the last-used blockchain block hash. Do not set if using block_hash or block.
633+
626634
627635
Returns:
628636
block number of the last step in the subnet.
629637
"""
630638
query = await self.query_subtensor(
631-
name="BlocksSinceLastStep", block=block, params=[netuid]
639+
name="BlocksSinceLastStep",
640+
block=block,
641+
block_hash=block_hash,
642+
reuse_block=reuse_block,
643+
params=[netuid],
632644
)
633645
return query.value if query is not None and hasattr(query, "value") else query
634646

@@ -1803,11 +1815,16 @@ async def get_next_epoch_start_block(
18031815
int: The block number at which the next epoch will start.
18041816
"""
18051817
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
1806-
if not block_hash and reuse_block:
1807-
block_hash = self.substrate.last_block_hash
1808-
block = await self.substrate.get_block_number(block_hash=block_hash)
1809-
tempo = await self.tempo(netuid=netuid, block_hash=block_hash)
1810-
return (((block // tempo) + 1) * tempo) + 1 if tempo else None
1818+
blocks_since_last_step = await self.blocks_since_last_step(
1819+
netuid=netuid, block=block, block_hash=block_hash, reuse_block=reuse_block
1820+
)
1821+
tempo = await self.tempo(
1822+
netuid=netuid, block=block, block_hash=block_hash, reuse_block=reuse_block
1823+
)
1824+
1825+
if block and blocks_since_last_step and tempo:
1826+
return block - blocks_since_last_step + tempo + 1
1827+
return None
18111828

18121829
async def get_owned_hotkeys(
18131830
self,

bittensor/core/subtensor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,12 @@ def get_next_epoch_start_block(
14101410
int: The block number at which the next epoch will start.
14111411
"""
14121412
block = block or self.block
1413+
blocks_since_last_step = self.blocks_since_last_step(netuid=netuid, block=block)
14131414
tempo = self.tempo(netuid=netuid, block=block)
1414-
return (((block // tempo) + 1) * tempo) + 1 if tempo else None
1415+
1416+
if block and blocks_since_last_step and tempo:
1417+
return block - blocks_since_last_step + tempo + 1
1418+
return None
14151419

14161420
def get_owned_hotkeys(
14171421
self,

contrib/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Patchsets and enhancements should always be focused. A pull request could add a
102102
Specifically, pull requests must adhere to the following criteria:
103103
- **Must** branch off from `staging`. Make sure that all your PRs are using `staging` branch as a base or will be closed.
104104
- Contain fewer than 50 files. PRs with more than 50 files will be closed.
105-
- Use the specific [template](./.github/pull_request_template.md) appropriate to your contribution.
105+
- Use the specific [template](../.github/pull_request_template.md) appropriate to your contribution.
106106
- If a PR introduces a new feature, it *must* include corresponding tests.
107107
- Other PRs (bug fixes, refactoring, etc.) should ideally also have tests, as they provide proof of concept and prevent regression.
108108
- Categorize your PR properly by using GitHub labels. This aids in the review process by informing reviewers about the type of change at a glance.
@@ -127,7 +127,7 @@ Please follow these steps to have your contribution considered by the maintainer
127127
1. Read the [development workflow](./DEVELOPMENT_WORKFLOW.md) defined for this repository to understand our workflow.
128128
2. Ensure your PR meets the criteria stated in the 'Pull Request Philosophy' section.
129129
3. Include relevant tests for any fixed bugs or new features as stated in the [testing guide](./TESTING.md).
130-
4. Follow all instructions in [the template](https://github.com/opentensor/bittensor/blob/master/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md) to create the PR.
130+
4. Follow all instructions in [the template](../.github/pull_request_template.md) to create the PR.
131131
5. Ensure your commit messages are clear and concise. Include the issue number if applicable.
132132
6. If you have multiple commits, rebase them into a single commit using `git rebase -i`.
133133
7. Explain what your changes do and why you think they should be merged in the PR description consistent with the [style guide](./STYLE.md).

tests/unit_tests/test_async_subtensor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,8 @@ async def test_blocks_since_last_step_with_value(subtensor, mocker):
31923192
mocked_query_subtensor.assert_awaited_once_with(
31933193
name="BlocksSinceLastStep",
31943194
block=block,
3195+
block_hash=None,
3196+
reuse_block=False,
31953197
params=[netuid],
31963198
)
31973199

@@ -3214,6 +3216,8 @@ async def test_blocks_since_last_step_is_none(subtensor, mocker):
32143216
mocked_query_subtensor.assert_awaited_once_with(
32153217
name="BlocksSinceLastStep",
32163218
block=block,
3219+
block_hash=None,
3220+
reuse_block=False,
32173221
params=[netuid],
32183222
)
32193223

0 commit comments

Comments
 (0)