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

Convenient way to invoke runtime API #4930

Closed
xlc opened this issue Jun 12, 2022 · 4 comments · Fixed by #4987
Closed

Convenient way to invoke runtime API #4930

xlc opened this issue Jun 12, 2022 · 4 comments · Fixed by #4987

Comments

@xlc
Copy link
Contributor

xlc commented Jun 12, 2022

Context: paritytech/substrate-connect#1096

We would like to replace custom RPC with state_call but we need a better API to invoke runtime APIs.

We should be able to supply a definition (similar to RPC defs) and polkadot.js should be able to use it to generate methods like api.call.evm.execute(contract_addr, input) and return the decoded response.

In future, if we can make metadata to include runtime API defs, then we can automatically generate those methods from metadata.

@jacogr
Copy link
Member

jacogr commented Jun 12, 2022

Sounds sane, but I have no idea what you want here and what it would look like. PRs are welcome.

(This is really the best approach, since it needs to be tested and since it is something I won't use myself, would need guidance - worst is "guess work")

@jacogr
Copy link
Member

jacogr commented Jun 19, 2022

Looked at this a bit - as always, we seem to be opening a small can of worms here which is not that easy to untangle since we don't have metadata info for the state_call, as you rightly indicated above. (And have logged).

With that outstanding it makes sense to do this in tranches, the first being api.call('GrandpaApi_current_set_id', ...params) => Promise<result> (with team-specified definitions and correct input/output encoding/decoding) before attempting to decorate api.call.<section>.<method> in the future.

The first gets the infrastructure in-place, the second would basically require a whole lot of untangling when it hits metadata, so basically would requiring doing the same work twice and differently.

In neither of these will be actually add "base definitions" (never say never... this is "as of now") to the types/interfaces so it won't auto-decorate what is known, i.e. it may not be there, the interfaces could be different, etc. (This adds quite serious maintenance overhead keeping in-line with the various runtimes)

@tomaka
Copy link
Contributor

tomaka commented Jun 22, 2022

To give some additional info:

Right now the versioning of the runtime calls is done through the apis field of the runtime spec. For example, if the runtime supports the Foo API, then you'll have the blake8 hash of Foo in the apis field.

If a runtime developer modifies the signature of a function (or logic, in a significant way), they're supposed to update the version of the API.
So ideally what PolkadotJS (or a JSON-RPC client in general) would do is first check whether the API in the runtime spec matches what is expected.

The risk of not doing so is that your parameters get misinterpreted, or that you misinterpret the return value. If you're unlucky, it will seem that everything is working, but you'll actually get garbage values.

Of course, this API version check is necessary only because the function signatures are not found in the metadata.

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jul 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants