Skip to content
Draft
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
12 changes: 10 additions & 2 deletions async_substrate_interface/sync_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import socket
from threading import Lock
from hashlib import blake2b
from typing import Optional, Union, Callable, Any
from unittest.mock import MagicMock
Expand Down Expand Up @@ -578,6 +579,8 @@ def __init__(
self.runtime_cache = RuntimeCache()
self.metadata_version_hex = "0x0f000000" # v15
self._mock = _mock
self._nonces: dict[str, int] = {}
self._nonce_lock = Lock()
self.log_raw_websockets = _log_raw_websockets
if not _mock:
self.ws = self.connect(init=True)
Expand Down Expand Up @@ -2678,8 +2681,13 @@ 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 = self.rpc_request("account_nextIndex", [account_address])
return nonce_obj["result"]
with self._nonce_lock:
if self._nonces.get(account_address) is None:
nonce_obj = 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]

def get_metadata_constants(self, block_hash=None) -> list[dict]:
"""
Expand Down