From 0acc0b6bb008f16ab27f5f78a280ceb70009c187 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 15 Apr 2025 17:55:31 +0200 Subject: [PATCH 1/5] Adds additional exception for catching --- async_substrate_interface/async_substrate.py | 3 ++- async_substrate_interface/errors.py | 4 ++++ async_substrate_interface/sync_substrate.py | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index e8a95aa..c40d628 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -39,6 +39,7 @@ SubstrateRequestException, ExtrinsicNotFound, BlockNotFound, + MaxRetriesExceeded, ) from async_substrate_interface.types import ( ScaleObj, @@ -1910,7 +1911,7 @@ async def _make_rpc_request( logger.warning( f"Timed out waiting for RPC requests {attempt} times. Exiting." ) - raise SubstrateRequestException("Max retries reached.") + raise MaxRetriesExceeded("Max retries reached.") else: self.ws.last_received = time.time() await self.ws.connect(force=True) diff --git a/async_substrate_interface/errors.py b/async_substrate_interface/errors.py index 9de753b..98114fe 100644 --- a/async_substrate_interface/errors.py +++ b/async_substrate_interface/errors.py @@ -8,6 +8,10 @@ class SubstrateRequestException(Exception): pass +class MaxRetriesExceeded(SubstrateRequestException): + pass + + class StorageFunctionNotFound(ValueError): pass diff --git a/async_substrate_interface/sync_substrate.py b/async_substrate_interface/sync_substrate.py index f463f2f..8a3fa16 100644 --- a/async_substrate_interface/sync_substrate.py +++ b/async_substrate_interface/sync_substrate.py @@ -21,6 +21,7 @@ ExtrinsicNotFound, SubstrateRequestException, BlockNotFound, + MaxRetriesExceeded, ) from async_substrate_interface.types import ( SubstrateMixin, @@ -1611,7 +1612,7 @@ def _make_rpc_request( logger.warning( f"Timed out waiting for RPC requests {attempt} times. Exiting." ) - raise SubstrateRequestException("Max retries reached.") + raise MaxRetriesExceeded("Max retries reached.") else: return self._make_rpc_request( payloads, From 78ec657d20fbe85ffa4b92e7e0d013437395b013 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 15 Apr 2025 23:01:30 +0200 Subject: [PATCH 2/5] Uses a `random.Random` random number generator instead of the hidden instantiation of this --- async_substrate_interface/async_substrate.py | 8 ++++++-- async_substrate_interface/sync_substrate.py | 8 ++++++-- async_substrate_interface/utils/__init__.py | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index e8a95aa..6b50d90 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -7,7 +7,6 @@ import asyncio import inspect import logging -import random import ssl import time from hashlib import blake2b @@ -48,7 +47,12 @@ SubstrateMixin, Preprocessed, ) -from async_substrate_interface.utils import hex_to_bytes, json, get_next_id +from async_substrate_interface.utils import ( + hex_to_bytes, + json, + get_next_id, + rng as random, +) from async_substrate_interface.utils.cache import async_sql_lru_cache from async_substrate_interface.utils.decoding import ( _determine_if_old_runtime_call, diff --git a/async_substrate_interface/sync_substrate.py b/async_substrate_interface/sync_substrate.py index f463f2f..339e9b6 100644 --- a/async_substrate_interface/sync_substrate.py +++ b/async_substrate_interface/sync_substrate.py @@ -1,6 +1,5 @@ import functools import logging -import random from hashlib import blake2b from typing import Optional, Union, Callable, Any @@ -30,7 +29,12 @@ Preprocessed, ScaleObj, ) -from async_substrate_interface.utils import hex_to_bytes, json, get_next_id +from async_substrate_interface.utils import ( + hex_to_bytes, + json, + get_next_id, + rng as random, +) from async_substrate_interface.utils.decoding import ( _determine_if_old_runtime_call, _bt_decode_to_dict_or_list, diff --git a/async_substrate_interface/utils/__init__.py b/async_substrate_interface/utils/__init__.py index e295e02..d0ad6eb 100644 --- a/async_substrate_interface/utils/__init__.py +++ b/async_substrate_interface/utils/__init__.py @@ -5,13 +5,15 @@ id_cycle = cycle(range(1, 999)) +rng = random.Random() + def get_next_id() -> str: """ Generates a pseudo-random ID by returning the next int of a range from 1-998 prepended with two random ascii characters. """ - random_letters = "".join(random.choices(string.ascii_letters, k=2)) + random_letters = "".join(rng.choices(string.ascii_letters, k=2)) return f"{random_letters}{next(id_cycle)}" From a917755dd838370ae839547a41f61da9e96856aa Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 16 Apr 2025 15:21:37 +0200 Subject: [PATCH 3/5] Removes the requirements/torch.txt line as this no longer exists and doesn't do anything that isn't already covered by dev --- .github/workflows/check-sdk-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check-sdk-tests.yml b/.github/workflows/check-sdk-tests.yml index 4bcd4ff..1e2e295 100644 --- a/.github/workflows/check-sdk-tests.yml +++ b/.github/workflows/check-sdk-tests.yml @@ -229,7 +229,6 @@ jobs: git fetch origin staging python3 -m pip install --upgrade pip python3 -m pip install '.[dev]' - python3 -m pip install -r requirements/torch.txt - name: Clone async-substrate-interface repo run: git clone https://github.com/opentensor/async-substrate-interface.git From 47c062e3319e39c57aa91f2144d9b355fa93ad5b Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 16 Apr 2025 16:21:35 +0200 Subject: [PATCH 4/5] Updates the maintainer info with emails that exist. --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 71f0fd3..2ebe653 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,12 +20,12 @@ requires-python = ">=3.9,<3.14" authors = [ { name = "Opentensor Foundation" }, - { name = "BD Himes", email = "benhimes@opentensor.dev" } + { name = "BD Himes", email = "b@latent.to" } ] maintainers = [ - { name = "Opentensor Foundation", email = "benhimes@opentensor.dev" }, - { name = "BD Himes", email = "benhimes@opentensor.dev" } + { name = "Latent Holdings" }, + { name = "BD Himes", email = "b@latent.to" } ] classifiers = [ From 6c3d5ca261543bd07db7166851008dfed08638c0 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Sat, 26 Apr 2025 23:45:22 -0700 Subject: [PATCH 5/5] bumps version and changelog --- CHANGELOG.md | 10 ++++++++++ pyproject.toml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cc35d..3454ca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 1.1.1 /2025-04-26 + +## What's Changed +* State-Safe RNG by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/97 +* Fix tests requirements by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/98 +* Update maintainers emails by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/99 +* Adds additional exception for catching by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/96 + +**Full Changelog**: https://github.com/opentensor/async-substrate-interface/compare/v1.1.0...v1.1.1 + ## 1.1.0 /2025-04-07 ## What's Changed diff --git a/pyproject.toml b/pyproject.toml index 2ebe653..8fe5ee8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "async-substrate-interface" -version = "1.1.0" +version = "1.1.1" description = "Asyncio library for interacting with substrate. Mostly API-compatible with py-substrate-interface" readme = "README.md" license = { file = "LICENSE" }