Skip to content

Commit

Permalink
XCM: Derive remote accounts according to polkadot standards (#2315)
Browse files Browse the repository at this point in the history
* update to v0.9.40

* update benchmarking weight template

* fix build

* make test compile

* Includes page heap fixes

* compile runtime-benchmarks

* make warp sync work

* toml sort

* fix editorconfig

* use new substrate version

* fix warp sync

* sort

* fix --dev

* remove duplicate SetMembersOrigin

* toml-sort

* remove kitchensink-runtime

* fix builkd

* use new weights

* set manual weights for xcm fungible

* use Weight::from_parts

* use 0 pov_size for ref_time weight

* update nimbus

* exclude generated weight files from editorconfig

* fmt

* fmt

* fix rust tests

* fix import

* fix tests

* use Weight part pov_size to 0

* make dalek test work

* fix transfer tests

* use BoundedVec for auto compound delegations

* fix modexp test

* fix modexp test

* fix tests

* fix weight tests

* fix staking tests via chunking

* fix modexp test

* fix lint and test

* fix rust weight tests

* fix partial ts tests

* temp fix for xcm v2

* Fixes weight until benchmarking is fixed

* set manual weight, fix ts tests

* Adds temp hack for xcm tests

* Use RefundSurplus as the no-op for saturating the queue, which does not have pov

* Update evm to 0.39

* Revert "Update evm to 0.39"

This reverts commit 882b85e.

* upgrade polkadot for better support of xcm v2

* prettier

* prettier

* Revert temp fix for XCM weight

* upgrade polkadot fork

* Fixing hrmp-mock tests

* clean up

* update polkadot fork to expose ForeignChainAliasAccount

* Generate remote accounts according to polkadot standards

* prettier

* fix rust test

* ts tests first pass

---------

Co-authored-by: Nisheeth Barthwal <nbaztec@gmail.com>
Co-authored-by: crystalin <alan.sapede@gmail.com>
Co-authored-by: girazoki <gorka.irazoki@gmail.com>
Co-authored-by: tgmichel <telmo@purestake.com>
  • Loading branch information
5 people authored May 30, 2023
1 parent 3178fdc commit a59057c
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 167 deletions.
122 changes: 61 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions primitives/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ impl Into<[u8; 20]> for AccountId20 {
}
}

impl From<[u8; 32]> for AccountId20 {
fn from(bytes: [u8; 32]) -> Self {
let mut buffer = [0u8; 20];
buffer.copy_from_slice(&bytes[..20]);
Self(buffer)
}
}

impl From<H160> for AccountId20 {
fn from(h160: H160) -> Self {
Self(h160.0)
Expand Down
3 changes: 0 additions & 3 deletions primitives/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ pub use constants::*;
mod fee_handlers;
pub use fee_handlers::*;

mod location_conversion;
pub use location_conversion::*;

mod origin_conversion;
pub use origin_conversion::*;

Expand Down
43 changes: 0 additions & 43 deletions primitives/xcm/src/location_conversion.rs

This file was deleted.

4 changes: 2 additions & 2 deletions runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<polkadot_parachain::primitives::Sibling, AccountId>,
// If we receive a MultiLocation of type AccountKey20, just generate a native account
AccountKey20Aliases<RelayNetwork, AccountId>,
// The rest of multilocations convert via hashing it
xcm_primitives::Account20Hash<AccountId>,
// Generate remote accounts according to polkadot standards
xcm_builder::ForeignChainAliasAccount<AccountId>,
);

/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`.
Expand Down
9 changes: 5 additions & 4 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use precompile_utils::testing::MockHandle;
use std::str::from_utf8;
use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia};
use xcm_executor::traits::Convert as XcmConvert;
use xcm_primitives::Account20Hash;

use moonbeam_xcm_benchmarks::weights::XcmWeight;
use nimbus_primitives::NimbusId;
Expand Down Expand Up @@ -3028,9 +3027,11 @@ fn test_xcm_utils_ml_tp_account() {
),
);
let expected_address_alice_in_parachain_2000: H160 =
Account20Hash::<AccountId>::convert_ref(alice_in_parachain_2000_multilocation.clone())
.unwrap()
.into();
xcm_builder::ForeignChainAliasAccount::<AccountId>::convert_ref(
alice_in_parachain_2000_multilocation.clone(),
)
.unwrap()
.into();

Precompiles::new()
.prepare_test(
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountKey20Aliases<RelayNetwork, AccountId>,
// The rest of multilocations convert via hashing it
xcm_primitives::Account20Hash<AccountId>,
xcm_builder::ForeignChainAliasAccount<AccountId>,
);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down
8 changes: 4 additions & 4 deletions runtime/moonbase/tests/xcm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ fn transact_through_signed_multilocation_para_to_para() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2843,7 +2843,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2969,7 +2969,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -3091,7 +3091,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/test-fees/test-fee-multiplier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createContract, createContractExecution } from "../../util/transactions
import {
RawXcmMessage,
XcmFragment,
descendOriginFromAddress,
descendOriginFromAddress20,
injectHrmpMessageAndSeal,
} from "../../util/xcm";
import { expectOk } from "../../util/expect";
Expand Down Expand Up @@ -208,7 +208,7 @@ describeDevMoonbeam("Fee Multiplier - XCM Executions", (context) => {
let balancesPalletIndex: number;

before("Suite Setup", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/test-precompile/test-precompile-xcm-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { describeDevMoonbeamAllEthTxTypes, describeDevMoonbeam } from "../../uti
import { generateKeyringPair } from "../../util/accounts";
import { BN } from "@polkadot/util";
import type { XcmVersionedXcm } from "@polkadot/types/lookup";
import { descendOriginFromAddress } from "../../util/xcm";
import { descendOriginFromAddress20 } from "../../util/xcm";
import { ALITH_TRANSACTION_TEMPLATE, createTransaction } from "../../util/transactions";
import { expectEVMResult, extractRevertReason } from "../../util/eth-transactions";

Expand Down Expand Up @@ -102,7 +102,7 @@ describeDevMoonbeamAllEthTxTypes("Precompiles - xcm utils", (context) => {
]),
});

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
expect(result.result).to.equal(`0x${descendOriginAddress.slice(2).padStart(64, "0")}`);
});

Expand Down
24 changes: 12 additions & 12 deletions tests/tests/test-xcm/test-mock-hrmp-transact-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ethers } from "ethers";
import { alith, charleth, generateKeyringPair } from "../../util/accounts";
import { getCompiled } from "../../util/contracts";
import {
descendOriginFromAddress,
descendOriginFromAddress20,
registerForeignAsset,
injectHrmpMessageAndSeal,
RawXcmMessage,
Expand All @@ -30,7 +30,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (transfer)"
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -168,7 +168,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (call)", (c

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -315,7 +315,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (asset fee)

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendedAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -478,7 +478,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (proxy)", (
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -611,7 +611,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (proxy)", (
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address
);
Expand Down Expand Up @@ -753,7 +753,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (proxy)", (
let random: KeyringPair;

before("Should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address
);
Expand Down Expand Up @@ -924,7 +924,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM (proxy) disabled switch", (con
let random: KeyringPair;

before("Should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address
);
Expand Down Expand Up @@ -1099,7 +1099,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM (non-proxy) disabled switch",
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -1267,7 +1267,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM input size check succeeds", (c

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
transferredBalance = 10_000_000_000_000_000_000n;

Expand Down Expand Up @@ -1391,7 +1391,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM input size check fails", (cont

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
transferredBalance = 10_000_000_000_000_000_000n;

Expand Down Expand Up @@ -1511,7 +1511,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (transfer)"
let random: KeyringPair;

before("should receive ethereum transact and account weight used", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/test-xcm/test-mock-hrmp-transact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from "chai";

import { generateKeyringPair } from "../../util/accounts";
import {
descendOriginFromAddress,
descendOriginFromAddress20,
injectHrmpMessageAndSeal,
RawXcmMessage,
XcmFragment,
Expand All @@ -22,7 +22,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact", (context) => {
let random: KeyringPair;

before("Should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -105,7 +105,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact with two Descends",
let random: KeyringPair;

before("Should receive transact action with two DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -189,7 +189,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact without withdraw", (
let random: KeyringPair;

before("Should receive transact action without Withdraw", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -271,7 +271,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact without buy executio
let random: KeyringPair;

before("Should receive transact action without buy execution", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down
6 changes: 3 additions & 3 deletions tests/tracing-tests/test-trace-ethereum-xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from "chai";

import { generateKeyringPair, alith } from "../util/accounts";
import {
descendOriginFromAddress,
descendOriginFromAddress20,
injectHrmpMessage,
injectHrmpMessageAndSeal,
RawXcmMessage,
Expand All @@ -27,7 +27,7 @@ describeDevMoonbeam("Trace ethereum xcm #1", (context) => {
const { contract, rawTx } = await createContract(context, "Incrementor");
await expectOk(context.createBlock(rawTx));

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
const sendingAddress = originAddress;
const random = generateKeyringPair();
const transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -145,7 +145,7 @@ describeDevMoonbeam("Trace ethereum xcm #2", (context) => {
);
await expectOk(context.createBlock(xcm_rawTx));

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
ethereumXcmDescendedOrigin = descendOriginAddress;
xcmContractAddress = xcm_contract.options.address;
const sendingAddress = originAddress;
Expand Down
Loading

0 comments on commit a59057c

Please sign in to comment.