polkascan/py-scale-codec

Unable to get events

pavelrib opened this issue · 6 comments

Calling get_events with block_hash = '0x1e5a94476abf191c4c54a47d20744cc684d0a21ae6c2c51085774ead4f5cac39' (block number = 7708105), results in the following error:

../env/lib/python3.7/site-packages/substrateinterface/base.py:1344: in get_events
    storage_obj = self.query(module="System", storage_function="Events", block_hash=block_hash)
../env/lib/python3.7/site-packages/substrateinterface/base.py:1316: in query
    obj.decode()
../env/lib/python3.7/site-packages/scalecodec/base.py:658: in decode
    self.value_serialized = self.process()
../env/lib/python3.7/site-packages/scalecodec/types.py:796: in process
    element = self.process_type(self.sub_type, metadata=self.metadata)
../env/lib/python3.7/site-packages/scalecodec/base.py:741: in process_type
    obj.decode(check_remaining=False)
../env/lib/python3.7/site-packages/scalecodec/base.py:658: in decode
    self.value_serialized = self.process()
../env/lib/python3.7/site-packages/scalecodec/types.py:2500: in process
    value = super().process()
../env/lib/python3.7/site-packages/scalecodec/types.py:471: in process
    field_obj = self.process_type(data_type, metadata=self.metadata)
../env/lib/python3.7/site-packages/scalecodec/base.py:741: in process_type
    obj.decode(check_remaining=False)
../env/lib/python3.7/site-packages/scalecodec/base.py:658: in decode
    self.value_serialized = self.process()
../env/lib/python3.7/site-packages/scalecodec/types.py:2434: in process
    arg_type_obj = self.process_type(arg_type)
../env/lib/python3.7/site-packages/scalecodec/base.py:740: in process_type
    obj = self.runtime_config.create_scale_object(type_string, self.data, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <scalecodec.base.RuntimeConfigurationObject object at 0x7f473c2b3dd0>
type_string = 'xcm::latest::Outcome'
data = <ScaleBytes(data=0x2000000000000000c0d786090000000002000000010000002c01d0070000cd5f6d68c0e6aeae6e09a9821b9f0f699f065de...fe5f85a2fe671ba028b35be25c83fd58758ef5642051113c018d8360400000000000000000000000000020000000000000e270700000000000000)>
kwargs = {}, decoder_class = None

    def create_scale_object(self, type_string: str, data=None, **kwargs) -> 'ScaleType':
        """
    
        Returns
        -------
        ScaleType
        """
        decoder_class = self.get_decoder_class(type_string)
    
        if decoder_class:
            return decoder_class(data=data, **kwargs)
    
>       raise NotImplementedError('Decoder class for "{}" not found'.format(type_string))
E       NotImplementedError: Decoder class for "xcm::latest::Outcome" not found

../env/lib/python3.7/site-packages/scalecodec/base.py:158: NotImplementedError

get_events still fails for block 7231772 on polkadot mainnet:

/app_dir/env/lib/python3.7/site-packages/substrateinterface/base.py:1344: in get_events
    storage_obj = self.query(module="System", storage_function="Events", block_hash=block_hash)
/app_dir/env/lib/python3.7/site-packages/substrateinterface/base.py:1316: in query
    obj.decode()
/app_dir/env/lib/python3.7/site-packages/scalecodec/base.py:658: in decode
    self.value_serialized = self.process()
/app_dir/env/lib/python3.7/site-packages/scalecodec/types.py:796: in process
    element = self.process_type(self.sub_type, metadata=self.metadata)
/app_dir/env/lib/python3.7/site-packages/scalecodec/base.py:741: in process_type
    obj.decode(check_remaining=False)
/app_dir/env/lib/python3.7/site-packages/scalecodec/base.py:658: in decode
    self.value_serialized = self.process()
/app_dir/env/lib/python3.7/site-packages/scalecodec/types.py:2483: in process
    value = super().process()
/app_dir/env/lib/python3.7/site-packages/scalecodec/types.py:471: in process
    field_obj = self.process_type(data_type, metadata=self.metadata)
/app_dir/env/lib/python3.7/site-packages/scalecodec/base.py:741: in process_type
    obj.decode(check_remaining=False)
/app_dir/env/lib/python3.7/site-packages/scalecodec/base.py:658: in decode
    self.value_serialized = self.process()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <scale_info::20(value=None)>

    def process(self):
    
        super().process()
    
        self.event_index = bytes([self.index, self.value_object[1].index]).hex()
    
        return {
            'event_index': self.event_index,
            'module_id': self.value_object[0],
            'event_id': self.value_object[1][0],
>           'attributes': self.value_object[1][1].value,
        }
E       AttributeError: 'NoneType' object has no attribute 'value'

We get the following errors for get_events on Polkadot and Westend:

    events = self._substrate.get_events(block_hash)
  File "/usr/local/lib/python3.8/site-packages/substrateinterface/base.py", line 1344, in get_events
    storage_obj = self.query(module="System", storage_function="Events", block_hash=block_hash)
  File "/usr/local/lib/python3.8/site-packages/substrateinterface/base.py", line 1316, in query
    obj.decode()
  File "/usr/local/lib/python3.8/site-packages/scalecodec/base.py", line 658, in decode
    self.value_serialized = self.process()
  File "/usr/local/lib/python3.8/site-packages/scalecodec/types.py", line 796, in process
    element = self.process_type(self.sub_type, metadata=self.metadata)
  File "/usr/local/lib/python3.8/site-packages/scalecodec/base.py", line 741, in process_type
    obj.decode(check_remaining=False)
  File "/usr/local/lib/python3.8/site-packages/scalecodec/base.py", line 658, in decode
    self.value_serialized = self.process()
  File "/usr/local/lib/python3.8/site-packages/scalecodec/types.py", line 2483, in process
    value = super().process()
  File "/usr/local/lib/python3.8/site-packages/scalecodec/types.py", line 471, in process
    field_obj = self.process_type(data_type, metadata=self.metadata)
  File "/usr/local/lib/python3.8/site-packages/scalecodec/base.py", line 741, in process_type
    obj.decode(check_remaining=False)
  File "/usr/local/lib/python3.8/site-packages/scalecodec/base.py", line 658, in decode
    self.value_serialized = self.process()
  File "/usr/local/lib/python3.8/site-packages/scalecodec/types.py", line 1030, in process
    result_obj = self.process_type(enum_type_mapping[1], metadata=self.metadata)
  File "/usr/local/lib/python3.8/site-packages/scalecodec/base.py", line 740, in process_type
    obj = self.runtime_config.create_scale_object(type_string, self.data, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/scalecodec/base.py", line 158, in create_scale_object
    raise NotImplementedError('Decoder class for "{}" not found'.format(type_string))

I didn't copy the most important line at the end of the error:
NotImplementedError: Decoder class for "scale_info::4" not found

We see this and the NoneType exception @pavelrib experiences for a lot of blocks

Okay, just to update that the scale_info errors stopped after we removed all references to reloading the configuration (as part of a flow we had for updating the type registry).

The NoneType exceptions for some blocks (like:
https://polkadot.subscan.io/block/0x8d6d4a37288f4207c3e0302bdb3e3fc01421ac0883a6d69cdb00c001e0dde9bd
for polkadot) still persist.

@maayank this was caused because a hotfix in master was not merged into the v1.0 branch, where the online type registry are retrieved from. This is now also merged into the v1.0 branch.

Regarding other issues, although weeks of work to prepare the upgrade to MetadataV14 runtimes, there are unfortunately still some unexpected differences between the initial implementation and current state. We are currently working to resolve this and will keep you posted when there is progress.