Skip to content

Add MetadataAtVersionNotFound error #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions async_substrate_interface/async_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ExtrinsicNotFound,
BlockNotFound,
MaxRetriesExceeded,
MetadataAtVersionNotFound,
)
from async_substrate_interface.protocols import Keypair
from async_substrate_interface.types import (
Expand Down Expand Up @@ -817,10 +818,7 @@ async def _load_registry_at_block(
"Client error: Execution failed: Other: Exported method Metadata_metadata_at_version is not found"
in e.args
):
raise SubstrateRequestException(
"You are attempting to call a block too old for this version of async-substrate-interface. Please"
" instead use legacy py-substrate-interface for these very old blocks."
)
raise MetadataAtVersionNotFound
else:
raise e
metadata_option_hex_str = metadata_rpc_result["result"]
Expand Down
10 changes: 10 additions & 0 deletions async_substrate_interface/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class MaxRetriesExceeded(SubstrateRequestException):
pass


class MetadataAtVersionNotFound(SubstrateRequestException):
def __init__(self):
message = (
"Exported method Metadata_metadata_at_version is not found. This indicates the block is quite old, and is"
"not supported by async-substrate-interface. If you need this, we recommend using the legacy "
"substrate-interface (https://github.com/JAMdotTech/py-polkadot-sdk)."
)
super().__init__(message)


class StorageFunctionNotFound(ValueError):
pass

Expand Down
20 changes: 15 additions & 5 deletions async_substrate_interface/sync_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
SubstrateRequestException,
BlockNotFound,
MaxRetriesExceeded,
MetadataAtVersionNotFound,
)
from async_substrate_interface.protocols import Keypair
from async_substrate_interface.types import (
Expand Down Expand Up @@ -617,11 +618,20 @@ def _get_current_block_hash(
def _load_registry_at_block(self, block_hash: Optional[str]) -> MetadataV15:
# Should be called for any block that fails decoding.
# Possibly the metadata was different.
metadata_rpc_result = self.rpc_request(
"state_call",
["Metadata_metadata_at_version", self.metadata_version_hex],
block_hash=block_hash,
)
try:
metadata_rpc_result = self.rpc_request(
"state_call",
["Metadata_metadata_at_version", self.metadata_version_hex],
block_hash=block_hash,
)
except SubstrateRequestException as e:
if (
"Client error: Execution failed: Other: Exported method Metadata_metadata_at_version is not found"
in e.args
):
raise MetadataAtVersionNotFound
else:
raise e
metadata_option_hex_str = metadata_rpc_result["result"]
metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
metadata = MetadataV15.decode_from_metadata_option(metadata_option_bytes)
Expand Down
Loading