polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
240 stars 114 forks source link

substrate.get_events() convenience method not returning all events in a block (different number of events to System.Events storage function) #229

Closed olliecorbisiero closed 2 years ago

olliecorbisiero commented 2 years ago

@arjanz @emielvanderhoek

Just noticed that each time I run substrate.get_events() convenience method on block 11359835 I get a different number of events in the block. The number is also different to the number of events returned by System.Events storage function for block 11359835.

Attaching image and pasting code.

Subscan for block 11359835

#get_events convenience method attempt 1
substrate = SubstrateInterface(url='wss://rpc.polkadot.io')
substrate.get_block_hash(11359835)
result = substrate.get_events()
len(result)

#get_events convenience method attempt 2
substrate = SubstrateInterface(url='wss://rpc.polkadot.io')
substrate.get_block_hash(11359835)
result = substrate.get_events()
len(result)

#querying System.Events storage function
substrate = SubstrateInterface(url='wss://rpc.polkadot.io')
query_result = substrate.query(
    module='System',
    storage_function='Events',
    block_hash = substrate.get_block_hash(11359835))
len(query_result)
image
arjanz commented 2 years ago

Hi @olliecorbisiero, I think you forgot to pass the retrieved block_hash to the get_events() function:

block_hash = substrate.get_block_hash(11359835)
result = substrate.get_events(block_hash=block_hash)

Please let me know if there are still any unexpected results

olliecorbisiero commented 2 years ago

Yes a colleague informed me of this - apologies for taking up your time with this!