@@ -616,19 +616,31 @@ async def all_subnets(
616
616
return subnets
617
617
618
618
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 ,
620
624
) -> Optional [int ]:
621
625
"""Returns number of blocks since the last epoch of the subnet.
622
626
623
627
Arguments:
624
628
netuid (int): The unique identifier of the subnetwork.
625
629
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
+
626
634
627
635
Returns:
628
636
block number of the last step in the subnet.
629
637
"""
630
638
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 ],
632
644
)
633
645
return query .value if query is not None and hasattr (query , "value" ) else query
634
646
@@ -1803,11 +1815,16 @@ async def get_next_epoch_start_block(
1803
1815
int: The block number at which the next epoch will start.
1804
1816
"""
1805
1817
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
1811
1828
1812
1829
async def get_owned_hotkeys (
1813
1830
self ,
0 commit comments