1

When submitting a stake request through the Python substrate-interface library, the extrinsic receipt comes back with the following parameters:

({'Module': {'index': 6, 'error': '0x02000000'}}, {'weight': 558355000, 'class': 'Normal', 'pays_fee': 'Yes'})

Also seen it return from the unbond endpoint with a similar response:

({'Module': {'index': 6, 'error': '0x07000000'}}, {'weight': 1163003000, 'class': 'Normal', 'pays_fee': 'Yes'})

When this map gets passed down through the error handling, it fails with a TypeError because '0x02000000' is not a valid int index on the map.

Stack trace:

File "/Users/kristian/Documents/v0MMVP/venv/lib/python3.9/site-packages/eulith_staking_manager/staking/dot/fxn_implementations/substrateCallImplementation.py", line 54, in call
    if receipt.is_success:
  File "/Users/kristian/Documents/v0MMVP/venv/lib/python3.9/site-packages/substrateinterface/base.py", line 3305, in is_success
    self.process_events()
  File "/Users/kristian/Documents/v0MMVP/venv/lib/python3.9/site-packages/substrateinterface/base.py", line 3204, in process_events
    module_error = self.substrate.metadata_decoder.get_module_error(
  File "/Users/kristian/Documents/v0MMVP/venv/lib/python3.9/site-packages/scalecodec/types.py", line 1907, in get_module_error
    return module.errors[error_index]
  File "/Users/kristian/Documents/v0MMVP/venv/lib/python3.9/site-packages/scalecodec/base.py", line 790, in __getitem__
    return self.value_object[item]
TypeError: list indices must be integers or slices, not str

What does this error code mean, and what is the correct fix to interpret the returned error?

Thank you!

3 Answers 3

1

The error encoding has changed slightly in Substrate master, specifically after this PR

In this case your results seems to match up with the recent encoding where error is 4 bytes -

  • the first byte still refers to the actual error index
  • the additional bytes are additional (encoded) error details
1
  • This indeed require a change in the error processing for the Python lib, I will follow up on the related Github issue
    – Arjan
    Commented Apr 25, 2022 at 10:52
0

I am assuming this is for the Kusama runtime?

There is a good resource for interpreting error messages here.

Index 6 in the Kusama runtime is the Staking pallet.

Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6,

0x02 in decimal is 2 and error 2 in the Staking pallet is AlreadyBonded with the message: Stash is already bonded.

0x07 in decimal is 7 and error 7 in the Staking pallet is InsufficientValue with the message Can not bond with value less than minimum balance.

You could also try something like this:

receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
print(receipt.error_message['name'])

As to why you're getting the leading zeros, I am not sure. Typically when I am working with Substrate I get error messages like this: {'Module': {'index': 6, 'error': '7'}. You could start to debug it here. Also, there was a new release of FRAME metadata recently where the scale-info was updated to v2.0.0 and the parity-scale-codec was also updated to v3.0.0. Maybe consider opening an issue in the py-substrate-interface repo.

2
  • Thanks, Bruno! I would try your solution there, but it's actually failing deeper in the substrate logic when I try to call .is_success. Example: receipt = self.active_substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True) if receipt.is_success: --> Fails Here I've opened an issue. I could submit a PR to fix this myself, but I'm not clear how you're converting the decimal. Is it always safe to trim trailing 0's? Seems to me this is an important question for knowing where to start the decimal conversion.
    – kayolord
    Commented Apr 20, 2022 at 1:52
  • Awesome. Looks like Jaco answered the question. The error field is no longer an index (u8) but a 4 byte array that encodes the error using SCALE instead of relying on a lookup. As mentioned here.
    – Bruno
    Commented Apr 20, 2022 at 13:12
0

This is indeed caused by recently released PR https://github.com/paritytech/substrate/pull/10242, updated DispatchError processing released in https://github.com/polkascan/py-substrate-interface/releases/tag/v1.2.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.