Skip to content

Commit

Permalink
Added checks to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Zijderveld committed Jun 30, 2020
1 parent afab51a commit 45855f2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions substrateinterface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import sr25519


log = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


class Keypair:
Expand Down Expand Up @@ -198,6 +198,7 @@ def __init__(self, url, address_type=None, type_registry=None, type_registry_pre
self.transaction_version = None

self.block_hash = None
self.block_id = None

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

def debug_message(self, message):
log.debug(message)
logger.debug(message)

def rpc_request(self, method, params, result_handler=None):
"""
Expand Down Expand Up @@ -583,7 +584,7 @@ def generate_storage_hash(self, storage_module, storage_function, params=None, h
"""

if metadata_version and metadata_version >= 9:
if not metadata_version or metadata_version >= 9:
storage_hash = xxh128(storage_module.encode()) + xxh128(storage_function.encode())

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

# Check if runtime state already set to current block
if (block_hash and block_hash == self.block_hash) or (block_id and block_id == self.block_id):
return

if block_id:
block_hash = self.get_block_hash(block_id)

self.block_hash = block_hash
self.block_id = block_id

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

# Check if runtime state already set to current block
if runtime_info.get("specVersion") == self.runtime_version:
return

self.runtime_version = runtime_info.get("specVersion")
self.transaction_version = runtime_info.get("transactionVersion")

Expand Down

0 comments on commit 45855f2

Please sign in to comment.