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

fix: multilocation type in pallets/foreign-assets #1408

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

Imod7
Copy link
Contributor

@Imod7 Imod7 commented Mar 6, 2024

Description of the issue

The endpoint pallets/foreign-assets throws the following error:

{
  "code": 500,
  "message": "createType(XcmV3MultiLocation):: DoNotConstruct: Cannot construct unknown type XcmV3MultiLocation",
  "stack": "Error: createType(XcmV3MultiLocation):: DoNotConstruct: Cannot construct unknown type XcmV3MultiLocation\n    at createTypeUnsafe ...",
  "level": "error"
}

Root Cause

The error is thrown when it tries to create the XcmV3MultiLocation type in this line.

Suggested Solution

First try to create the StagingXcmV3MultiLocation type and if it is not successful try the XcmV3MultiLocation type.

Testing

Tested the endpoint by connecting to Polkadot/Kusama/Rococo Asset Hub

@Imod7 Imod7 requested a review from a team as a code owner March 6, 2024 10:20
'XcmV3MultiLocation',
JSON.parse(foreignAssetMultiLocationStr),
);
const XcmV3MultiLocation = ['StagingXcmV3MultiLocation', 'XcmV3MultiLocation'];
Copy link
Contributor

@IkerAlus IkerAlus Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to create the type from hardcoded options? Bear in mind this will be an issue soon when XCM v4 is released and XCM types are renamed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, this should be already the case if foreign assets in Rococo Asset Hub are queried.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You mean retrieve dynamically the XCM Multilocation related types, check what is available and try the ones that should work right ? I haven't tried to create types this way but one thing that comes into my mind is the potential impact in the response time. 🤔 If there is such an implementation, I am guessing it will take longer to process the request (go through these steps) in order to return the expected result.
  • I just tested against Rococo Asset Hub and it returns the foreign assets correctly.

Copy link
Contributor

@IkerAlus IkerAlus Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You are right, that solution would be an overkill, but we just need keep an eye for this changes.
  • indeed, this makes sense for now, because we are talking about the storage types not the XCM types from the messages. But if Asset hub follows XCM v4 typing, then this will break again, just have it in mind.

Copy link
Contributor

@IkerAlus IkerAlus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

} catch (e) {
throw new InternalServerError(`Failed to create MultiLocation type for Foreign Asset`);
}
}

const assetMetadata = await api.query.foreignAssets.metadata<AssetMetadata>(foreignAssetMultiLocation);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to just put the multilocation in the query as an Object or string and let the API take care of the type creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirmed it can.

'XcmV3MultiLocation',
JSON.parse(foreignAssetMultiLocationStr),
);
const XcmV3MultiLocation = ['StagingXcmV3MultiLocation', 'XcmV3MultiLocation'];
Copy link
Member

@TarikGul TarikGul Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of all of this, the try catches, and the xcm multilocation array, and just pass in an object of the multilocation directly to the query. Given this comment we dont want to be using createType directly anymore unless its testing, and we want to avoid using a nested try catch at all costs.

Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check comment above.

Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Imod7 Imod7 merged commit b7136d0 into master Mar 6, 2024
15 checks passed
@Imod7 Imod7 deleted the domi-fix-multilocation branch March 6, 2024 17:10
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants