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

Feat/xcm precompile update #996

Merged
merged 20 commits into from Oct 4, 2023
Merged

Conversation

gitofdeepanshu
Copy link
Contributor

@gitofdeepanshu gitofdeepanshu commented Aug 7, 2023

Pull Request Summary
This PR adds multiple new features to xcm precompile.

Changes

  1. Add new function send_xcm() which allows to send any xcm-message to the destination chain.
  2. Add new Struct Multilocation to precompile
struct Multilocation {
    uint8 parents;
    bytes[] interior;
}

This addition helps in getting rid of function overloading for different Account types (AccountId32 and AccountKey20) supported by xcm.
3. Support for updated weight using

struct WeightV2{
        uint64 ref_time;
        uint64 proof_size;
    }

so that user can specify the proof_size of weight.
4. Addition of Xtokens Interface

Check list

  • added or updated unit tests
  • updated Astar official documentation
  • added OnRuntimeUpgrade hook for precompile revert code registration
  • updated spec version
  • updated semver

@gitofdeepanshu gitofdeepanshu added the runtime This PR/Issue is related to the topic “runtime”. label Aug 7, 2023
precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved
precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved
precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved
@gitofdeepanshu gitofdeepanshu marked this pull request as ready for review September 11, 2023 10:05
Copy link
Member

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

There's no PR summary - that's bad for any PR, and especially one with 2k+ LoC.

precompiles/xcm/XCM_v2.sol Show resolved Hide resolved
precompiles/xcm/Xtokens.sol Outdated Show resolved Hide resolved
precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved
precompiles/xcm/src/lib.rs Show resolved Hide resolved
@gitofdeepanshu
Copy link
Contributor Author

There's no PR summary - that's bad for any PR, and especially one with 2k+ LoC.

My bad, I have updated it now.

precompiles/utils/src/xcm.rs Show resolved Hide resolved
precompiles/xcm/XCM_v2.sol Show resolved Hide resolved
precompiles/xcm/Xtokens.sol Outdated Show resolved Hide resolved
precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved
precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved
precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved

let asset_id = Runtime::address_to_asset_id(currency_address.into())
.ok_or(revert("Failed to resolve fee asset id from address"))?;
let dest_weight_limit = if weight.is_max() {
Copy link
Member

@shaunxw shaunxw Oct 3, 2023

Choose a reason for hiding this comment

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

The interface docstring should cover when Unlimited would be used.

Personally, I think zero is a more conventional value. For max weight, it has indicated unlimited by using itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the info about Unlimited weight in interface.

Personally, I think zero is a more conventional value. For max weight, it has indicated unlimited by using itself.

Not sure what you mean by this.

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I think zero is a more conventional value. For max weight, it has indicated unlimited by using itself.

Not sure what you mean by this.

I mean weight max vs zero to indicate Unlimited. is_zero should be used instead of is_max.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for this case is_max make more sense imo. Can we go ahead with this?

Copy link
Member

Choose a reason for hiding this comment

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

This is part of the public API so let's be cautious.

Zero value is conventional to indicate unlimited/unstrict. Using a uint64 max value is counter-intuition and clumsy to use. In addition, when a max weight is passed, there is actually no need to convert it to Unlimited as it's unlimited itself.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with Shaun about zero as the sentinel value.

It's harder to mess up, even if in the future we change some things related to weight type (probably won't, but still). Zero will always be a zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense, I was not able to understand what exactly you meant but now I get it.
So you are saying that Weight = 0 , should result into WeightLimit::Unlimited and not u64::MAX value.
So what you are suggesting is this

let dest_weight_limit = if weight.is_zero() {
            WeightLimit::Unlimited
        } else {
            WeightLimit::Limited(weight.get_weight())
        };
        

I got the idea of using u64::MAX for Unlimited from MB but this is a better approach, I agree.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, correct.

precompiles/xcm/src/mock.rs Outdated Show resolved Hide resolved
precompiles/xcm/src/mock.rs Show resolved Hide resolved
primitives/src/xcm/constants.rs Outdated Show resolved Hide resolved
Copy link
Member

@ashutoshvarma ashutoshvarma left a comment

Choose a reason for hiding this comment

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

Now that Moonbeam's precompile-utils is included in frontier and we can remove the vendor code (precompiles-utils) after the next uplift.

precompiles/xcm/src/tests.rs Outdated Show resolved Hide resolved
precompiles/xcm/Xtokens.sol Outdated Show resolved Hide resolved
@gitofdeepanshu gitofdeepanshu added shiden related to shiden runtime astar Related to Astar shibuya related to shibuya labels Oct 3, 2023
Copy link
Member

@PierreOssun PierreOssun left a comment

Choose a reason for hiding this comment

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

Need to be updated

precompiles/xcm/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

@ashutoshvarma please create an issue to follow-up on this: #996 (review)

Comment on lines +704 to +707
let amount_of_tokens = input
.read::<U256>()?
.try_into()
.map_err(|_| revert("error converting amount_of_tokens, maybe value too large"))?;
Copy link
Member

Choose a reason for hiding this comment

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

Keeping the style consistent in the same file, that's added in its entirety in your PR, is not nit-picky.

When someone reviews a big PR such as this one, you want to make it as easy as possible.
Doing the same thing in multiple different ways doesn't help with that, nor with maintenance in the future.


let asset_id = Runtime::address_to_asset_id(currency_address.into())
.ok_or(revert("Failed to resolve fee asset id from address"))?;
let dest_weight_limit = if weight.is_max() {
Copy link
Member

Choose a reason for hiding this comment

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

Agree with Shaun about zero as the sentinel value.

It's harder to mess up, even if in the future we change some things related to weight type (probably won't, but still). Zero will always be a zero.

precompiles/xcm/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@PierreOssun PierreOssun left a comment

Choose a reason for hiding this comment

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

minor

precompiles/xcm/XCM_v2.sol Show resolved Hide resolved
precompiles/xcm/XCM_v2.sol Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

Code Coverage

Package Line Rate Branch Rate Health
primitives/src 62% 0%
chain-extensions/types/assets/src 0% 0%
precompiles/xcm/src 77% 0%
precompiles/utils/macro/src 0% 0%
precompiles/assets-erc20/src 76% 0%
pallets/collator-selection/src 69% 0%
pallets/dapps-staking/src/pallet 85% 0%
chain-extensions/pallet-assets/src 0% 0%
pallets/xvm/src 40% 0%
pallets/pallet-xcm/src 53% 0%
pallets/dapps-staking/src 81% 0%
precompiles/batch/src 80% 0%
precompiles/utils/src/testing 62% 0%
pallets/contracts-migration/src 0% 0%
precompiles/dapps-staking/src 93% 0%
chain-extensions/types/dapps-staking/src 0% 0%
primitives/src/xcm 66% 0%
precompiles/sr25519/src 79% 0%
precompiles/utils/src 65% 0%
chain-extensions/xvm/src 0% 0%
precompiles/xvm/src 75% 0%
pallets/xc-asset-config/src 53% 0%
pallets/dynamic-evm-base-fee/src 81% 0%
pallets/unified-accounts/src 80% 0%
pallets/ethereum-checked/src 48% 0%
pallets/block-reward/src 85% 0%
chain-extensions/dapps-staking/src 0% 0%
chain-extensions/types/xvm/src 0% 0%
precompiles/substrate-ecdsa/src 78% 0%
Summary 58% (2899 / 4978) 0% (0 / 0)

Minimum allowed line rate is 50%

@gitofdeepanshu gitofdeepanshu merged commit 1317df8 into master Oct 4, 2023
11 checks passed
@gitofdeepanshu gitofdeepanshu deleted the feat/xcm-precompile-update branch October 4, 2023 15:33
@gitofdeepanshu gitofdeepanshu mentioned this pull request Oct 7, 2023
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astar Related to Astar runtime This PR/Issue is related to the topic “runtime”. shibuya related to shibuya shiden related to shiden runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants