Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract interactions not supported on Weight V2 chains #334

Closed
DamianStraszak opened this issue Apr 28, 2023 · 6 comments · Fixed by #337
Closed

Contract interactions not supported on Weight V2 chains #334

DamianStraszak opened this issue Apr 28, 2023 · 6 comments · Fixed by #337

Comments

@DamianStraszak
Copy link
Contributor

First of all -- huge kudos for developing this library -- it's absolutely great, I have been using it quite a lot.

As for the issue I encountered. It seems to me that the support for WeightsV2 is not there yet for Smart Contracts (ContractInstance and related classes). In particular the example https://github.com/polkascan/py-substrate-interface/blob/master/examples/create_and_exec_contract.py does not work on WeightsV2 chains.

I have dug into it a little, and it seems that's because in places like

def read(self, keypair: Keypair, method: str, args: dict = None,
or more specifically there is still a one-dimensional gas_limit.

Changing this unfortunately does not fix the problem, there is something else to fix also -- which I haven't figured out yet.

The question is whether there is a plan to add this support? My two comments here:

  • I think it's fine to drop the compatibility with WeightsV1 for Contracts, because there will never be a chain that launches Contracts on the old Weights. Currently the only production chains that have contracts are Aleph Zero and Astar, both on WeightsV2
  • I can try sending you a PR with the fix for this issue once I figure out what all needs to be done. But in such a case, there might be some work required for a reviewer on your side to help me bring it to an acceptable form, as I'm not python-native :P
@arjanz
Copy link
Member

arjanz commented Apr 28, 2023

Thanks for the compliment :)

I haven't given the contract interface much attention recently, so this would be a good opportunity to update to the latest specs of the contracts pallet.

Dropping WeightV1 support is a good one. If there are no production chains atm using it and therefor no one will in the future, that will make things a lot easier.

I will have a look to see what the exact issues are. Do you have an test endpoint (or otherwise Docker image) where I can test the version of the contract pallet you are using?

@DamianStraszak
Copy link
Contributor Author

Thanks for a quick response!

You can use Aleph Zero testnet: wss://ws.test.azero.dev (https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fws.test.azero.dev#/explorer). Currently Alice has funds there, but in case someone takes them here is a faucet https://faucet.test.azero.dev/

The version of pallet contracts that production chains currently use is substrate polkadot-v0.9.38 https://github.com/paritytech/substrate/tree/polkadot-v0.9.38 -- you can alternatively build and run a substrate node from this branch.

@arjanz
Copy link
Member

arjanz commented May 1, 2023

I ran some tests, my findings:

  • There is a check for WeightV2, but too naive. It just convert the old int version to {'ref_time': gas_limit, 'proof_size': 0}.
  • In current example (create_and_exec_contract.py) this will lead to Exception {'code': 1010, 'message': 'Invalid Transaction', 'data': 'Transaction would exhaust the block limits'}, because of a too high ref_time and no proof_size.
  • When I hard-code here the numbers generated by PolkadotJS:

Screenshot 2023-05-01 at 14 14 58

to {'ref_time': 25990000000, 'proof_size': 11990383647911208550}, I can successfully deploy. But then also run into problems with the ContractsApi.call runtime call.

So basically I will have to:

  • Refactor the whole contract interface and drop the old contract support.
  • This will include to determine the correct WeightV2 values (examine how PolkadotJS does this).
  • Debug and fix SCALE decoding issues with the ContractsApi.call runtime call. This is likely due to type mismatch; types in runtime APIs still need manual administration. These types will be included in the future, when Parity releases MetadataV15.

This will be quitte some work, I think I can start somewhere this week, but it will probably take at least a week before this is available.

@DamianStraszak
Copy link
Contributor Author

Thanks for working on this! If I can be of any help -- testing stuff, or review, then let me know.

I'm also eagerly awaiting metadata V15 -- will be really useful for libraries like this one.

@arjanz
Copy link
Member

arjanz commented May 3, 2023

I'm working on a PR, for now I have a workaround to read and exec contract methods, until the new release. Add the following type registry override to the init:

substrate = SubstrateInterface(
        url="wss://ws.test.azero.dev",
        type_registry={
            "types": {
                "ContractExecResult": "ContractExecResultTo267"
            }
        }
    )

@arjanz arjanz linked a pull request May 4, 2023 that will close this issue
5 tasks
@arjanz
Copy link
Member

arjanz commented May 8, 2023

Released: https://github.com/polkascan/py-substrate-interface/releases/tag/v1.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

2 participants