@@ -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 ,
0 commit comments