polkascan / py-substrate-interface

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

extrinsic_idx is None for some blocks #255

Closed KarimJedda closed 1 year ago

KarimJedda commented 1 year ago

Example: block 2314800 on Statemint.

from substrateinterface import SubstrateInterface
substrate = SubstrateInterface(
    url="statemint_wss"
)
block_hash = substrate.get_block_hash(2314800)
raw_block = substrate.get_block(block_hash=block_hash)
# debug events
events = substrate.get_events(block_hash=block_hash)

This is what is in events:

[
<scale_info::16(value={'phase': 'Initialization', 'extrinsic_idx': None, 'event': {'event_index': '1600', 'module_id': 'Session', 'event_id': 'NewSession', 'attributes': 1117}, 'event_index': 22, 'module_id': 'Session', 'event_id': 'NewSession', 'attributes': 1117, 'topics': []})>, 
<scale_info::16(value={'phase': 'ApplyExtrinsic', 'extrinsic_idx': 0, 'event': {'event_index': '0000', 'module_id': 'System', 'event_id': 'ExtrinsicSuccess', 'attributes': {'weight': 0, 'class': 'Mandatory', 'pays_fee': 'No'}}, 'event_index': 0, 'module_id': 'System', 'event_id': 'ExtrinsicSuccess', 'attributes': {'weight': 0, 'class': 'Mandatory', 'pays_fee': 'No'}, 'topics': []})>, 
<scale_info::16(value={'phase': 'ApplyExtrinsic', 'extrinsic_idx': 1, 'event': {'event_index': '0000', 'module_id': 'System', 'event_id': 'ExtrinsicSuccess', 'attributes': {'weight': 131737000, 'class': 'Mandatory', 'pays_fee': 'Yes'}}, 'event_index': 0, 'module_id': 'System', 'event_id': 'ExtrinsicSuccess', 'attributes': {'weight': 131737000, 'class': 'Mandatory', 'pays_fee': 'Yes'}, 'topics': []})>
]

Is there a specific reason this happens? Is it something specific to the NewSession event?

Thank you very much

arjanz commented 1 year ago

It means that specific event is not explicitly triggered by an extrinsic, but by another internal process of the chain (in this case a start of a new session). Also notice the 'phase' of the event, if it's ApplyExtrinsic then you can assume the extrinsic_idx is filled.

KarimJedda commented 1 year ago

Understood, thank you very much for the explanation!