Skip to content

Commit 45855f2

Browse files
author
Arjan Zijderveld
committed
Added checks to improve performance
1 parent afab51a commit 45855f2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

substrateinterface/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import sr25519
4141

4242

43-
log = logging.getLogger(__name__)
43+
logger = logging.getLogger(__name__)
4444

4545

4646
class Keypair:
@@ -198,6 +198,7 @@ def __init__(self, url, address_type=None, type_registry=None, type_registry_pre
198198
self.transaction_version = None
199199

200200
self.block_hash = None
201+
self.block_id = None
201202

202203
self.metadata_cache = {}
203204
self.type_registry_cache = {}
@@ -207,7 +208,7 @@ def __init__(self, url, address_type=None, type_registry=None, type_registry_pre
207208
self.debug = False
208209

209210
def debug_message(self, message):
210-
log.debug(message)
211+
logger.debug(message)
211212

212213
def rpc_request(self, method, params, result_handler=None):
213214
"""
@@ -583,7 +584,7 @@ def generate_storage_hash(self, storage_module, storage_function, params=None, h
583584
584585
"""
585586

586-
if metadata_version and metadata_version >= 9:
587+
if not metadata_version or metadata_version >= 9:
587588
storage_hash = xxh128(storage_module.encode()) + xxh128(storage_function.encode())
588589

589590
if params:
@@ -684,13 +685,22 @@ def init_runtime(self, block_hash=None, block_id=None):
684685
if block_id and block_hash:
685686
raise ValueError('Cannot provide block_hash and block_id at the same time')
686687

688+
# Check if runtime state already set to current block
689+
if (block_hash and block_hash == self.block_hash) or (block_id and block_id == self.block_id):
690+
return
691+
687692
if block_id:
688693
block_hash = self.get_block_hash(block_id)
689694

690695
self.block_hash = block_hash
696+
self.block_id = block_id
691697

692698
runtime_info = self.get_block_runtime_version(block_hash=self.block_hash)
693699

700+
# Check if runtime state already set to current block
701+
if runtime_info.get("specVersion") == self.runtime_version:
702+
return
703+
694704
self.runtime_version = runtime_info.get("specVersion")
695705
self.transaction_version = runtime_info.get("transactionVersion")
696706

0 commit comments

Comments
 (0)