From 5c436127187b2a789192be5e254716cb338f1040 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Fri, 27 Sep 2024 13:54:02 +0200 Subject: [PATCH 1/2] Backwards compatibility for sort options. --- bittensor_cli/cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 2582da7d4..4e66a5ac2 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1135,10 +1135,12 @@ def wallet_overview( ), sort_by: Optional[str] = typer.Option( None, + "--sort-by", "--sort_by", help="Sort the hotkeys by the specified column title. For example: name, uid, axon.", ), sort_order: Optional[str] = typer.Option( None, + "--sort-order", "--sort_order", help="Sort the hotkeys in the specified order (ascending/asc or descending/desc/reverse).", ), include_hotkeys: str = typer.Option( From a9bc09dd40c49dc7edf9212962fbc65e54dbeaab Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Fri, 27 Sep 2024 13:54:44 +0200 Subject: [PATCH 2/2] Randomise rpc_request id to avoid possible dict duplicate keys. --- .../bittensor/async_substrate_interface.py | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/bittensor_cli/src/bittensor/async_substrate_interface.py b/bittensor_cli/src/bittensor/async_substrate_interface.py index 261cf167f..02748231e 100644 --- a/bittensor_cli/src/bittensor/async_substrate_interface.py +++ b/bittensor_cli/src/bittensor/async_substrate_interface.py @@ -1,5 +1,6 @@ import asyncio import json +import random from collections import defaultdict from dataclasses import dataclass from hashlib import blake2b @@ -897,6 +898,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 ( @@ -1693,9 +1695,10 @@ async def rpc_request( """ block_hash = await self._get_current_block_hash(block_hash, reuse_block_hash) params = params or [] + payload_id = f"{method}{random.randint(0, 7000)}" payloads = [ self.make_payload( - "rpc_request", + payload_id, method, params + [block_hash] if block_hash else params, ) @@ -1707,14 +1710,14 @@ async def rpc_request( self.type_registry, ) result = await self._make_rpc_request(payloads, runtime=runtime) - if "error" in result["rpc_request"][0]: + if "error" in result[payload_id][0]: raise SubstrateRequestException( result["rpc_request"][0]["error"]["message"] ) - if "result" in result["rpc_request"][0]: - return result["rpc_request"][0] + if "result" in result[payload_id][0]: + return result[payload_id][0] else: - raise SubstrateRequestException(result["rpc_request"][0]) + raise SubstrateRequestException(result[payload_id][0]) async def get_block_hash(self, block_id: int) -> str: return (await self.rpc_request("chain_getBlockHash", [block_id]))["result"] @@ -2193,20 +2196,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'])}"