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

DryRunApi implementation doesn't seem to work properly #6041

Closed
4 of 10 tasks
HmFlashy opened this issue Dec 9, 2024 · 24 comments
Closed
4 of 10 tasks

DryRunApi implementation doesn't seem to work properly #6041

HmFlashy opened this issue Dec 9, 2024 · 24 comments
Labels
Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability. Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.

Comments

@HmFlashy
Copy link

HmFlashy commented Dec 9, 2024

Issue type:

  • Bug report
  • Feature request
  • Support request
  • Other

I saw that some time ago the dryRunApi has been implemented to be able to calculate fees for both extrinsic and XCMs.
I am trying to use this API using polkadot js library but I can't make it work.

I am getting this error:

No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.

const crossChainSendPayload: any = this.getCrossChainSendPayload(data.toAddress, amount, data.parachainId);
const extrinsicPayload = api.tx[xcmPallet][method](...Object.values(crossChainSendPayload));
const dryRunResult = await extrinsicPayload.dryRun(address);

Or
This error:
image
with this code

const crossChainSendPayload: any = this.getCrossChainSendPayload(data.toAddress, amount, data.parachainId);
const extrinsicPayload = node.tx[xcmPallet][method](...Object.values(crossChainSendPayload));
const call = node.createType('RuntimeCall', extrinsicPayload.method.toHex());

const result = await node.call.dryRunApi.dryRunCall({
    system: { signed: decodeAddress(address) },
}, extrinsicPayload.method.toHex());

I have seen the implementation here, either we need to set a blockhash or a signer. But isn't it possible to dry run without a signer and blockhash ? By just giving an address it should be enough right ?

We need to calculate the fees for both XCM and basic extrinsic so we need this call to make it consistantly working.
Thanks

  • Version:

  • Environment:

    • Node.js v20.10.0
    • Browser
    • Other (limited support for other environments)
  • Language:

    • JavaScript
    • TypeScript 5.4.5
    • Other
@TarikGul
Copy link
Member

TarikGul commented Dec 9, 2024

What version of the API are you using?

@TarikGul TarikGul added Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability. P4 - Needs Investigation Requires analysis to determine cause or feasibility. Not fully understood, needs research first. labels Dec 9, 2024
@TarikGul TarikGul moved this to P4 - Needs Investigation in Polkadot-js general project board Dec 9, 2024
@TarikGul TarikGul moved this from P4 - Needs Investigation to Support in Polkadot-js general project board Dec 9, 2024
@TarikGul TarikGul added Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance. and removed Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability. P4 - Needs Investigation Requires analysis to determine cause or feasibility. Not fully understood, needs research first. labels Dec 9, 2024
@TarikGul
Copy link
Member

TarikGul commented Dec 9, 2024

Hey so after some quick sanity checks everything works, i'll explain the mistake above - (I understand the confusion though).

The SubmittableExtrinsic.dryRun uses the system::dryRun rpc call, which is different from the dryRunApi call. The SubmittableExtrinsic.dryRun call requires the parameter to be a valid KeyringPair. This can be seen here.

If you want to use the new dryRunApi calls you need to call them separately. That would look like:

const extrinsic = api.tx[xcmPallet][method](...Object.values(crossChainSendPayload));
// Origin can be defined by https://github.com/polkadot-js/api/blob/master/packages/types-augment/src/lookup/types-kusama.ts#L24-L35
const dryRunResult = await api.call.dryRunApi.dryRunCall(<origin>, extrinsic.method);
console.log(dryRunResult)

// Conversely for xcm calls
const dryRunResult = await api.call.dryRunApi.dryRunXcm(<origin_location>, <xcm>);

@TarikGul
Copy link
Member

TarikGul commented Dec 9, 2024

Let me know if anything isn't clear.

@HmFlashy
Copy link
Author

HmFlashy commented Dec 11, 2024

Thanks a lot for your answer, indeed much clearer and working like a charm !
Now I got another issue, it seems this endpoint doesn't work on assethub westend. Looks like the result can't be decoded by westend assethub metadata

Caught unknown error: createType(Result\u003cCallDryRunEffects, XcmDryRunApiError\u003e):: decodeU8aStruct: failed at 0x031f02000000000000… on localXcm (index 3/4): Option\u003cVersionedXcm\u003e:: Unable to create Enum via index 31, in V0, V1, V2, V3, V4

@HmFlashy
Copy link
Author

And we are using last version 15.0.1

@HmFlashy
Copy link
Author

@TarikGul Do you have an idea why ?

@HmFlashy
Copy link
Author

HmFlashy commented Dec 12, 2024

We can see here when selecting xcmPaymentApi; this endpoint is missing
And if you go into dryRunApi, select dryRunCall and enter a correct payload you will get same error as me above for a XCM message

@TarikGul
Copy link
Member

Thanks a lot for your answer, indeed much clearer and working like a charm ! Now I got another issue, it seems this endpoint doesn't work on assethub westend. Looks like the result can't be decoded by westend assethub metadata

Caught unknown error: createType(Result\u003cCallDryRunEffects, XcmDryRunApiError\u003e):: decodeU8aStruct: failed at 0x031f02000000000000… on localXcm (index 3/4): Option\u003cVersionedXcm\u003e:: Unable to create Enum via index 31, in V0, V1, V2, V3, V4

I am not really sure what the actual issue is here: Any chance can share the input params you are passing so I can do some testing.

We can see here when selecting xcmPaymentApi; this endpoint is missing
And if you go into dryRunApi, select dryRunCall and enter a correct payload you will get same error as me above for a XCM message

I was seeing some odd behavior just now with the metadata versions which could be affecting the way the api initializes which could affect the runtime apis. Looking into this now.

ex: metadataVersionsAt

1: metadata.metadataVersions: Vec<u32>
[
  14
  15
  4,294,967,295
]

@HmFlashy
Copy link
Author

Here is the call I am making in hex
0x1f090301000300010100e9251828c80479f5fde8b6d50863a739b9422b58925abf440768e6d1ec1d16cd0304000000000700e87648170000000000

@HmFlashy
Copy link
Author

HmFlashy commented Dec 12, 2024

What is weird is, it is correctly decoded here so it means the message is ok, but if you use this call inside the dryRunApi dryRunCall, the result is wrongly decoded

@HmFlashy
Copy link
Author

But it works in kusama and polkadot

@TarikGul
Copy link
Member

Here is the call I am making in hex 0x1f090301000300010100e9251828c80479f5fde8b6d50863a739b9422b58925abf440768e6d1ec1d16cd0304000000000700e87648170000000000

Thank you!

What is weird is, it is correctly decoded here so it means the message is ok, but if you use this call inside the dryRunApi dryRunCall, the result is wrongly decoded

There could have been a recent runtime upgrade as well which is causing this issue in westend. I remember hearing about some upgrades in westend to fix some things with v4, and potentially introduce v5. I could be wrong here but that could very well be it as well.

@HmFlashy
Copy link
Author

when will it be fixed then ? We would need it to work in our testnet environment

@TarikGul
Copy link
Member

Not sure. I still don't know the exact source of the issue. I asked internally, and will update here with answers. If its working correctly in polkadot and kusama through PJS but not in westend assethub I would say its safe to assume there is an issue with the runtime, but I can't say for certain.

@TarikGul
Copy link
Member

In terms of query_delivery_fees not showing up I am looking into that. That might be a PJS issue.

@TarikGul
Copy link
Member

Im double checking the dryRunCall as well.

@TarikGul
Copy link
Member

Okay good news I found an issue locally with the metadataVersions - lets see if it fixes how the types are being resolved.

@TarikGul
Copy link
Member

Okay so I have a fix for the queryDeliveryFees missing!

@TarikGul
Copy link
Member

TarikGul commented Dec 13, 2024

Okay so I got a fix that also fixes the call. The execution still fails on the node that being said I let the correct individual know of the error and they are looking into it.

That being said, the above PR fixes the actual call and types itself.

@TarikGul TarikGul added the Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability. label Dec 13, 2024
@TarikGul
Copy link
Member

@HmFlashy
Copy link
Author

Thanks a lot for your time and effort, will check if it is working asap

@franciscoaguirre
Copy link

The reason the call doesn't work is you're specifying { parents: 0, interior: Here } in the assets to teleport when you're on Asset Hub. It should be { parents: 1, interior: Here }. WND is always identified by the relative location of the Westend Relay Chain. The same also happens with KSM and DOT on system parachains.

@HmFlashy
Copy link
Author

HmFlashy commented Dec 17, 2024

Yes thanks! I realised that.
Btw  @franciscoaguirre @TarikGul, is there a way to generically call any endpoint which handles different versions for a parameter ?
For example:
queryWeightToAssetFee on Westend assethub as V5 for asset but Kusama assethub doesn't have V5.
Should I manage each network independently ? It looks like a lot of work to maintain.

@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 Dec 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability. Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.
Development

No branches or pull requests

4 participants