polkascan / py-substrate-interface

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

Decoding problem - parity struct change #368

Closed mokrzesa closed 9 months ago

mokrzesa commented 9 months ago

Hello 👋 Happy to contribute to the library ! Due to updated version of ContractResult: https://github.com/paritytech/polkadot-sdk/blob/9f5221cc2f7f10adfd22b293ceed060617468936/substrate/frame/contracts/src/primitives.rs#L41

Problems that I've encountered on test networks running the new changes:

scalecodec.exceptions.RemainingScaleBytesNotEmptyException: Decoding <ContractExecResultTo267> - Current offset: 364 / length: 515

and after running: substrate.reload_type_registry(), with:

NotImplementedError: Decoder class for "Weight" not found

I can also help with the implementation if you want 👍

arjanz commented 9 months ago

Actually I had already prepared this change by adding the type:

https://github.com/polkascan/py-scale-codec/blob/17ddfd80ec380ecd6f58fb1bc8a25993719bb59d/scalecodec/type_registry/core.json#L1641

On which network did you encountered this issue?

I didn't really track which networks already updated to the latest version of the contract pallet, so I probably need to update the type registry for that network..

Until then, what you could do to apply the latest version of ContractResult:

substrate = SubstrateInterface(
        url="ws://127.0.0.1:9944",
        type_registry={
            "types": {
                "ContractExecResult": "ContractExecResultTo269"
            }
        }
)

Thanks for pointing this out, let me know if this works!

mokrzesa commented 9 months ago

@arjanz thanks for super quick response 🙏

I've encountered this issue on Aleph Zero Testnet --> https://testnet.alephzero.org/

I can confirm with the fix you suggested it is working ! 🏅 Thank you very much! If you would need any help with the development I'm happy to help!

With best regards, Mikołaj

arjanz commented 9 months ago

No problem, glad it could be fixed easily.

I will add a type registry for the Alephzero testnet pointing to ContractExecResultTo269.

How about mainnet of Alephzero, does that still have the older version or same issues there? It would help if you could give me a sign when the runtime upgrade will take place, so I can update the type reg file for the mainnet as well..

mokrzesa commented 9 months ago

@arjanz the answer that I've got from A0 team regarding your question:


The change will be there once Aleph Zero mainnet updates to version 12.x, currently only testnet is on 12.x and mainnet still 11.x

Which type should be used can be determined based on StorageVersion for pallet contract though.
arjanz commented 9 months ago

The latest release https://github.com/polkascan/py-substrate-interface/releases/tag/v1.7.5 has automatic type detection by pallet version, as the guys at Aleph Zero suggested. This shouldn't be an issue then anymore.