From 5fef9178fb010203b3800776f19103c40818de58 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Thu, 26 Sep 2024 21:33:21 +0200 Subject: [PATCH] Remove call to chain_finalised_head for metadata registry loading, handle SSL errors. --- bittensor_cli/cli.py | 5 ++++- .../bittensor/async_substrate_interface.py | 21 +++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 2582da7d4..024778f9e 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3,6 +3,7 @@ import curses import os.path import re +import ssl import sys from pathlib import Path from typing import Coroutine, Optional @@ -756,16 +757,18 @@ async def _run(): else: result = await cmd return result - except ConnectionRefusedError: + except (ConnectionRefusedError, ssl.SSLError): err_console.print( f"Unable to connect to the chain: {self.not_subtensor}" ) asyncio.create_task(cmd).cancel() raise typer.Exit() except ConnectionClosed: + asyncio.create_task(cmd).cancel() raise typer.Exit() except SubstrateRequestException as e: err_console.print(str(e)) + asyncio.create_task(cmd).cancel() raise typer.Exit() if sys.version_info < (3, 10): diff --git a/bittensor_cli/src/bittensor/async_substrate_interface.py b/bittensor_cli/src/bittensor/async_substrate_interface.py index 261cf167f..fa33270bd 100644 --- a/bittensor_cli/src/bittensor/async_substrate_interface.py +++ b/bittensor_cli/src/bittensor/async_substrate_interface.py @@ -845,11 +845,7 @@ async def _get_current_block_hash( async def load_registry(self): metadata_rpc_result = await self.rpc_request( "state_call", - [ - "Metadata_metadata_at_version", - self.metadata_version_hex, - await self.get_chain_finalised_head(), - ], + ["Metadata_metadata_at_version", self.metadata_version_hex], ) metadata_option_hex_str = metadata_rpc_result["result"] metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:]) @@ -897,6 +893,7 @@ async def init_runtime( :returns: Runtime object """ + async def get_runtime(block_hash, block_id) -> Runtime: # Check if runtime state already set to current block if (block_hash and block_hash == self.last_block_hash) or ( @@ -2193,20 +2190,16 @@ async def runtime_call( params = {} try: - runtime_call_def = self.runtime_config.type_registry["runtime_api"][ - api - ]["methods"][method] + runtime_call_def = self.runtime_config.type_registry["runtime_api"][api][ + "methods" + ][method] runtime_api_types = self.runtime_config.type_registry["runtime_api"][ api ].get("types", {}) except KeyError: - raise ValueError( - f"Runtime API Call '{api}.{method}' not found in registry" - ) + raise ValueError(f"Runtime API Call '{api}.{method}' not found in registry") - if isinstance(params, list) and len(params) != len( - runtime_call_def["params"] - ): + if isinstance(params, list) and len(params) != len(runtime_call_def["params"]): raise ValueError( f"Number of parameter provided ({len(params)}) does not " f"match definition {len(runtime_call_def['params'])}"