2121 TYPE_CHECKING ,
2222)
2323
24+ import asyncstdlib as a
2425from bittensor_wallet .keypair import Keypair
2526from bittensor_wallet .utils import SS58_FORMAT
2627from bt_decode import MetadataV15 , PortableRegistry , decode as decode_by_type_string
@@ -1659,8 +1660,11 @@ def convert_event_data(data):
16591660 events .append (convert_event_data (item ))
16601661 return events
16611662
1662- @async_sql_lru_cache ( max_size = 512 )
1663+ @a . lru_cache ( maxsize = 512 )
16631664 async def get_parent_block_hash (self , block_hash ):
1665+ return await self ._get_parent_block_hash (block_hash )
1666+
1667+ async def _get_parent_block_hash (self , block_hash ):
16641668 block_header = await self .rpc_request ("chain_getHeader" , [block_hash ])
16651669
16661670 if block_header ["result" ] is None :
@@ -1672,16 +1676,22 @@ async def get_parent_block_hash(self, block_hash):
16721676 return block_hash
16731677 return parent_block_hash
16741678
1675- @async_sql_lru_cache ( max_size = 16 )
1679+ @a . lru_cache ( maxsize = 16 )
16761680 async def get_block_runtime_info (self , block_hash : str ) -> dict :
1681+ return await self ._get_block_runtime_info (block_hash )
1682+
1683+ async def _get_block_runtime_info (self , block_hash : str ) -> dict :
16771684 """
16781685 Retrieve the runtime info of given block_hash
16791686 """
16801687 response = await self .rpc_request ("state_getRuntimeVersion" , [block_hash ])
16811688 return response .get ("result" )
16821689
1683- @async_sql_lru_cache ( max_size = 512 )
1690+ @a . lru_cache ( maxsize = 512 )
16841691 async def get_block_runtime_version_for (self , block_hash : str ):
1692+ return await self ._get_block_runtime_version_for (block_hash )
1693+
1694+ async def _get_block_runtime_version_for (self , block_hash : str ):
16851695 """
16861696 Retrieve the runtime version of the parent of a given block_hash
16871697 """
@@ -1914,7 +1924,6 @@ async def _make_rpc_request(
19141924
19151925 return request_manager .get_results ()
19161926
1917- @async_sql_lru_cache (max_size = 512 )
19181927 async def supports_rpc_method (self , name : str ) -> bool :
19191928 """
19201929 Check if substrate RPC supports given method
@@ -1985,8 +1994,11 @@ async def rpc_request(
19851994 else :
19861995 raise SubstrateRequestException (result [payload_id ][0 ])
19871996
1988- @async_sql_lru_cache ( max_size = 512 )
1997+ @a . lru_cache ( maxsize = 512 )
19891998 async def get_block_hash (self , block_id : int ) -> str :
1999+ return await self ._get_block_hash (block_id )
2000+
2001+ async def _get_block_hash (self , block_id : int ) -> str :
19902002 return (await self .rpc_request ("chain_getBlockHash" , [block_id ]))["result" ]
19912003
19922004 async def get_chain_head (self ) -> str :
@@ -3230,6 +3242,28 @@ async def _handler(block_data: dict[str, Any]):
32303242 return await co
32313243
32323244
3245+ class DiskCachedAsyncSubstrateInterface (AsyncSubstrateInterface ):
3246+ """
3247+ Experimental new class that uses disk-caching in addition to memory-caching for the cached methods
3248+ """
3249+
3250+ @async_sql_lru_cache (maxsize = 512 )
3251+ async def get_parent_block_hash (self , block_hash ):
3252+ return await self ._get_parent_block_hash (block_hash )
3253+
3254+ @async_sql_lru_cache (maxsize = 16 )
3255+ async def get_block_runtime_info (self , block_hash : str ) -> dict :
3256+ return await self ._get_block_runtime_info (block_hash )
3257+
3258+ @async_sql_lru_cache (maxsize = 512 )
3259+ async def get_block_runtime_version_for (self , block_hash : str ):
3260+ return await self ._get_block_runtime_version_for (block_hash )
3261+
3262+ @async_sql_lru_cache (maxsize = 512 )
3263+ async def get_block_hash (self , block_id : int ) -> str :
3264+ return await self ._get_block_hash (block_id )
3265+
3266+
32333267async def get_async_substrate_interface (
32343268 url : str ,
32353269 use_remote_preset : bool = False ,
0 commit comments