From a3ae910575faa08b87cfd58ad9784aa3a4d15f6b Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Wed, 15 Jan 2025 18:48:50 -0800 Subject: [PATCH 1/4] Bumps version and changelog --- CHANGELOG.md | 9 ++++++++- pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07681b1..49f17f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ -## 1.0.0rc1 /2025-01-13 +# Changelog + +## 1.0.0rc2 /2025-01-15 + +## What's Changed +* Improve ScaleObj by @roman-opentensor in https://github.com/opentensor/async-substrate-interface/pull/2 + +## 1.0.0rc1 /2025-01-15 ## What's Changed * New Async Substrate Interface by @thewhaleking and @roman-opentensor in https://github.com/opentensor/async-substrate-interface/tree/main diff --git a/pyproject.toml b/pyproject.toml index 0c383d9..c82d049 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "async-substrate-interface" -version = "1.0.0rc1" +version = "1.0.0rc2" description = "Asyncio library for interacting with substrate. Mostly API-compatible with py-substrate-interface" readme = "README.md" license = { file = "LICENSE" } diff --git a/setup.py b/setup.py index 1b84e79..ddcdea7 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="async-substrate-interface", - version="1.0.0rc1", + version="1.0.0rc2", description="Asyncio library for interacting with substrate.", long_description=open("README.md").read(), long_description_content_type="text/markdown", From 7051f7b5ead048ac4b2c93e64f9bbab7a89eec31 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 16 Jan 2025 19:28:51 -0800 Subject: [PATCH 2/4] Adds nonce implementation --- async_substrate_interface/substrate_interface.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/async_substrate_interface/substrate_interface.py b/async_substrate_interface/substrate_interface.py index 66876ff..4db5c04 100644 --- a/async_substrate_interface/substrate_interface.py +++ b/async_substrate_interface/substrate_interface.py @@ -1079,6 +1079,7 @@ def __init__( ss58_format=self.ss58_format, implements_scale_info=True ) self.__metadata_cache = {} + self._nonces = {} self.metadata_version_hex = "0x0f000000" # v15 self.event_loop = event_loop or asyncio.get_event_loop() self.sync_calls = sync_calls @@ -3166,7 +3167,7 @@ async def create_signed_extrinsic( # Retrieve nonce if nonce is None: - nonce = await self.get_account_nonce(keypair.ss58_address) or 0 + nonce = await self.get_account_next_index(keypair.ss58_address) or 0 # Process era if era is None: @@ -3358,8 +3359,13 @@ async def get_account_next_index(self, account_address: str) -> int: # Unlikely to happen, this is a common RPC method raise Exception("account_nextIndex not supported") - nonce_obj = await self.rpc_request("account_nextIndex", [account_address]) - return nonce_obj["result"] + async with self._lock: + if self._nonces.get(account_address) is None: + nonce_obj = await self.rpc_request("account_nextIndex", [account_address]) + self._nonces[account_address] = nonce_obj["result"] + else: + self._nonces[account_address] += 1 + return self._nonces[account_address] async def get_metadata_constant(self, module_name, constant_name, block_hash=None): """ From 8fd6324c1aac701c5520d34e2daf4f5a35ed7cb8 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 16 Jan 2025 19:52:20 -0800 Subject: [PATCH 3/4] Bumps version and changelog --- CHANGELOG.md | 5 +++++ pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49f17f8..7c8a824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.0.0rc3 /2025-01-17 + +## What's Changed +* Adds nonce implementation @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/8 + ## 1.0.0rc2 /2025-01-15 ## What's Changed diff --git a/pyproject.toml b/pyproject.toml index c82d049..07f8c10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "async-substrate-interface" -version = "1.0.0rc2" +version = "1.0.0rc3" description = "Asyncio library for interacting with substrate. Mostly API-compatible with py-substrate-interface" readme = "README.md" license = { file = "LICENSE" } diff --git a/setup.py b/setup.py index ddcdea7..99f5555 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="async-substrate-interface", - version="1.0.0rc2", + version="1.0.0rc3", description="Asyncio library for interacting with substrate.", long_description=open("README.md").read(), long_description_content_type="text/markdown", From c52e236711c08900fbd567ef211914f3c20245f3 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 17 Jan 2025 15:30:12 -0800 Subject: [PATCH 4/4] Fixes nonce management --- async_substrate_interface/substrate_interface.py | 6 ++++-- pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/async_substrate_interface/substrate_interface.py b/async_substrate_interface/substrate_interface.py index 4db5c04..510aedd 100644 --- a/async_substrate_interface/substrate_interface.py +++ b/async_substrate_interface/substrate_interface.py @@ -3167,7 +3167,7 @@ async def create_signed_extrinsic( # Retrieve nonce if nonce is None: - nonce = await self.get_account_next_index(keypair.ss58_address) or 0 + nonce = await self.get_account_nonce(keypair.ss58_address) or 0 # Process era if era is None: @@ -3347,7 +3347,9 @@ async def get_account_nonce(self, account_address: str) -> int: async def get_account_next_index(self, account_address: str) -> int: """ - Returns next index for the given account address, taking into account the transaction pool. + This method maintains a cache of nonces for each account ss58address. + Upon subsequent calls, it will return the cached nonce + 1 instead of fetching from the chain. + This allows for correct nonce management in-case of async context when gathering co-routines. Args: account_address: SS58 formatted address diff --git a/pyproject.toml b/pyproject.toml index 07f8c10..a16f681 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "async-substrate-interface" -version = "1.0.0rc3" +version = "1.0.0rc4" description = "Asyncio library for interacting with substrate. Mostly API-compatible with py-substrate-interface" readme = "README.md" license = { file = "LICENSE" } diff --git a/setup.py b/setup.py index 99f5555..d7f6da8 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="async-substrate-interface", - version="1.0.0rc3", + version="1.0.0rc4", description="Asyncio library for interacting with substrate.", long_description=open("README.md").read(), long_description_content_type="text/markdown",