Skip to content

Commit

Permalink
Fixed incorrect decoding of blocks containing runtime upgrade, metada…
Browse files Browse the repository at this point in the history
…ta and type registry is now fetched from parent block #48
  • Loading branch information
Arjan Zijderveld committed Nov 13, 2020
1 parent fb31c04 commit a850826
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions substrateinterface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,17 @@ def init_runtime(self, block_hash=None, block_id=None):
self.block_hash = block_hash
self.block_id = block_id

runtime_info = self.get_block_runtime_version(block_hash=self.block_hash)
# In fact calls and storage functions are decoded against runtime of previous block, therefor retrieve
# metadata and apply type registry of runtime of parent block
block_header = self.get_block_header(block_hash=self.block_hash) or {}
parent_block_hash = block_header.get('parentHash')

if parent_block_hash == '0x0000000000000000000000000000000000000000000000000000000000000000':
runtime_block_hash = self.block_hash
else:
runtime_block_hash = parent_block_hash

runtime_info = self.get_block_runtime_version(block_hash=runtime_block_hash)

# Check if runtime state already set to current block
if runtime_info.get("specVersion") == self.runtime_version:
Expand All @@ -820,7 +830,7 @@ def init_runtime(self, block_hash=None, block_id=None):
self.debug_message('Retrieved metadata for {} from memory'.format(self.runtime_version))
self.metadata_decoder = self.metadata_cache[self.runtime_version]
else:
self.metadata_decoder = self.get_block_metadata(block_hash=self.block_hash, decode=True)
self.metadata_decoder = self.get_block_metadata(block_hash=runtime_block_hash, decode=True)
self.debug_message('Retrieved metadata for {} from Substrate node'.format(self.runtime_version))

# Update metadata cache
Expand Down

0 comments on commit a850826

Please sign in to comment.