From a9348d4e05c7f3c4eacfe452de65fc1692cdd0c7 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Fri, 25 Jul 2025 14:35:00 +0200 Subject: [PATCH 1/2] Reload runtime types when retrieved. --- async_substrate_interface/async_substrate.py | 1 + async_substrate_interface/sync_substrate.py | 14 +------------- async_substrate_interface/types.py | 9 +++++++++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index cd2cc21..9e8172d 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -1068,6 +1068,7 @@ async def init_runtime( return runtime runtime_version = await self.get_block_runtime_version_for(block_hash) + if runtime_version is None: raise SubstrateRequestException( f"No runtime information for block '{block_hash}'" diff --git a/async_substrate_interface/sync_substrate.py b/async_substrate_interface/sync_substrate.py index ff805dc..8a73207 100644 --- a/async_substrate_interface/sync_substrate.py +++ b/async_substrate_interface/sync_substrate.py @@ -773,9 +773,6 @@ def init_runtime( if block_id is not None: if runtime := self.runtime_cache.retrieve(block=block_id): self.runtime = runtime - self.runtime.load_runtime() - if self.runtime.registry: - self.runtime.load_registry_type_map() return self.runtime block_hash = self.get_block_hash(block_id) @@ -785,9 +782,6 @@ def init_runtime( self.last_block_hash = block_hash if runtime := self.runtime_cache.retrieve(block_hash=block_hash): self.runtime = runtime - self.runtime.load_runtime() - if self.runtime.registry: - self.runtime.load_registry_type_map() return self.runtime runtime_version = self.get_block_runtime_version_for(block_hash) @@ -801,15 +795,9 @@ def init_runtime( if runtime := self.runtime_cache.retrieve(runtime_version=runtime_version): self.runtime = runtime - self.runtime.load_runtime() - if self.runtime.registry: - self.runtime.load_registry_type_map() - return runtime + return self.runtime else: self.runtime = self.get_runtime_for_version(runtime_version, block_hash) - self.runtime.load_runtime() - if self.runtime.registry: - self.runtime.load_registry_type_map() return self.runtime def get_runtime_for_version( diff --git a/async_substrate_interface/types.py b/async_substrate_interface/types.py index 57681f3..95575bf 100644 --- a/async_substrate_interface/types.py +++ b/async_substrate_interface/types.py @@ -75,16 +75,25 @@ def retrieve( runtime = self.blocks.get(block) if runtime is not None: self.last_used = runtime + runtime.load_runtime() + if runtime.registry: + runtime.load_registry_type_map() return runtime if block_hash is not None: runtime = self.block_hashes.get(block_hash) if runtime is not None: self.last_used = runtime + runtime.load_runtime() + if runtime.registry: + runtime.load_registry_type_map() return runtime if runtime_version is not None: runtime = self.versions.get(runtime_version) if runtime is not None: self.last_used = runtime + runtime.load_runtime() + if runtime.registry: + runtime.load_registry_type_map() return runtime return None From 6f8d23e93443f6967823ad9bb041c939cdf25428 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Fri, 25 Jul 2025 14:35:18 +0200 Subject: [PATCH 2/2] Ruff --- async_substrate_interface/async_substrate.py | 2 +- async_substrate_interface/sync_substrate.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index 9e8172d..fc4f034 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -330,7 +330,7 @@ async def process_events(self): self.__error_message = { "type": "System", "name": "Token", - "docs": dispatch_error["Token"] + "docs": dispatch_error["Token"], } elif not has_transaction_fee_paid_event: diff --git a/async_substrate_interface/sync_substrate.py b/async_substrate_interface/sync_substrate.py index 8a73207..f6d1876 100644 --- a/async_substrate_interface/sync_substrate.py +++ b/async_substrate_interface/sync_substrate.py @@ -297,7 +297,7 @@ def process_events(self): self.__error_message = { "type": "System", "name": "Token", - "docs": dispatch_error["Token"] + "docs": dispatch_error["Token"], } elif not has_transaction_fee_paid_event: