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

XCM instructions weights should comply with evm foreign assets #2883

Merged
merged 35 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d0568a7
XCM weights: account for evm foreign assets (more expensive)
librelois Jul 25, 2024
0dfa79e
adapt rust tests cost
librelois Jul 29, 2024
a56eceb
Merge branch 'master' into elois-xcm-fees
librelois Jul 30, 2024
47179c5
xtokens cost increase for moonbeam
librelois Jul 31, 2024
a74fa83
xtokens cost increase for moonriver
librelois Jul 31, 2024
f80de1f
fix 2 ts tests files
librelois Jul 31, 2024
3e61183
Merge branch 'master' into elois-xcm-fees
librelois Aug 2, 2024
99d3969
Merge branch 'master' into elois-xcm-fees
librelois Aug 5, 2024
5150305
fix moonbase rust tests
librelois Aug 5, 2024
6d57412
fix moonbeam rust tests
librelois Aug 5, 2024
e9e81b1
fix moonriver rust tests
librelois Aug 5, 2024
f678a45
fix some mock hrmp tx ts tests
pLabarta Aug 5, 2024
8710732
fix some dev tests (shard 3)
librelois Aug 5, 2024
2a9d3fb
fix more shard 3 tests
librelois Aug 5, 2024
9a7fef1
fix most dev tests @ shard 2
pLabarta Aug 6, 2024
d2f3348
fix 2 ts tests
librelois Aug 6, 2024
940c1ef
increase weight limit for default text xcm message
librelois Aug 6, 2024
73d0a21
increase weight limit for default text xcm message
librelois Aug 6, 2024
c9319a1
fix some dev tests @ shard 4
pLabarta Aug 6, 2024
682f9ed
Merge branch 'master' into elois-xcm-fees
librelois Aug 12, 2024
37c8334
rust fmt
librelois Aug 12, 2024
43f8d36
fix ts dev test D014034
librelois Aug 12, 2024
2584f4d
fix dev test D014024
librelois Aug 12, 2024
3a5ae9a
fix dev test D014025
librelois Aug 12, 2024
9488068
fix dev test D014036
librelois Aug 12, 2024
f1dfa46
fix dev test D014027
librelois Aug 12, 2024
e4ad726
fix test D014035
librelois Aug 13, 2024
31b4b63
pretiter
librelois Aug 13, 2024
4a5c42d
use unlimited weight for xcm tracing tests
librelois Aug 13, 2024
835d745
apply review suggestions
librelois Aug 13, 2024
dff9645
Merge branch 'master' into elois-xcm-fees
librelois Aug 14, 2024
cf1a727
fix dev test D014025
librelois Aug 14, 2024
a9fb857
update polkadot-sdk pin
librelois Aug 14, 2024
bf4e0c8
fix Cargo.lock
librelois Aug 14, 2024
1910c1c
update polkadot pin
librelois Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions client/rpc/manual-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ impl ManualXcmApiServer for ManualXcm {
ClearOrigin,
BuyExecution {
fees: (Parent, 10000000000000u128).into(),
weight_limit: Limited(Weight::from_parts(4_000_000_000u64, DEFAULT_PROOF_SIZE)),
weight_limit: Limited(Weight::from_parts(
10_000_000_000u64,
DEFAULT_PROOF_SIZE,
)),
},
DepositAsset {
assets: AllCounted(1).into(),
Expand Down Expand Up @@ -114,7 +117,7 @@ impl ManualXcmApiServer for ManualXcm {
BuyExecution {
fees: ((Parent, Parachain(sender.into())), 10000000000000u128).into(),
weight_limit: Limited(Weight::from_parts(
4_000_000_000u64,
10_000_000_000u64,
DEFAULT_PROOF_SIZE,
)),
},
Expand Down
6 changes: 3 additions & 3 deletions pallets/moonbeam-foreign-assets/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const ERC20_CREATE_MAX_CALLDATA_SIZE: usize = 16 * 1024; // 16Ko

// Hardcoded gas limits (from manueal binary search)
const ERC20_CREATE_GAS_LIMIT: u64 = 3_367_000; // highest failure: 3_366_000
const ERC20_BURN_FROM_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000
const ERC20_MINT_INTO_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000
pub(crate) const ERC20_BURN_FROM_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000
pub(crate) const ERC20_MINT_INTO_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000
const ERC20_PAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500
const ERC20_TRANSFER_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000
pub(crate) const ERC20_TRANSFER_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000
const ERC20_UNPAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500

pub enum EvmError {
Expand Down
11 changes: 10 additions & 1 deletion pallets/moonbeam-foreign-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub enum AssetStatus {
#[pallet]
pub mod pallet {
use super::*;
use pallet_evm::Runner;
use pallet_evm::{GasWeightMapping, Runner};
use sp_runtime::traits::{AccountIdConversion, Convert};
use xcm_executor::traits::ConvertLocation;
use xcm_executor::traits::Error as MatchError;
Expand Down Expand Up @@ -259,6 +259,15 @@ pub mod pallet {
})
.map_err(Into::into)
}
pub fn weight_of_erc20_burn() -> Weight {
T::GasWeightMapping::gas_to_weight(evm::ERC20_BURN_FROM_GAS_LIMIT, true)
}
pub fn weight_of_erc20_mint() -> Weight {
T::GasWeightMapping::gas_to_weight(evm::ERC20_MINT_INTO_GAS_LIMIT, true)
}
pub fn weight_of_erc20_transfer() -> Weight {
T::GasWeightMapping::gas_to_weight(evm::ERC20_TRANSFER_GAS_LIMIT, true)
}
}

#[pallet::call]
Expand Down
1 change: 1 addition & 0 deletions pallets/moonbeam-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ serde = { workspace = true, optional = true }

# Moonbeam
pallet-erc20-xcm-bridge = { workspace = true }
pallet-moonbeam-foreign-assets = { workspace = true }
xcm-primitives = { workspace = true }

# Substrate
Expand Down
12 changes: 5 additions & 7 deletions pallets/moonbeam-xcm-benchmarks/src/weights/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,29 @@
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use frame_support::{traits::Get, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}};
use sp_std::marker::PhantomData;
use xcm::latest::Asset;

// Values copied from statemint benchmarks
const ASSET_BURN_MAX_PROOF_SIZE: u64 = 7242;
const ASSET_MINT_MAX_PROOF_SIZE: u64 = 7242;
const ASSET_TRANSFER_MAX_PROOF_SIZE: u64 = 13412;

/// Weights for `pallet_xcm_benchmarks::fungible`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config + pallet_erc20_xcm_bridge::Config> WeightInfo<T> {
impl<T: frame_system::Config + pallet_erc20_xcm_bridge::Config + pallet_moonbeam_foreign_assets::Config> WeightInfo<T> {
pub(crate) fn withdraw_asset(asset: &Asset) -> Weight {
if pallet_erc20_xcm_bridge::Pallet::<T>::is_erc20_asset(asset) {
pallet_erc20_xcm_bridge::Pallet::<T>::weight_of_erc20_transfer(&asset.id)

} else {
Weight::from_parts(200_000_000 as u64, ASSET_BURN_MAX_PROOF_SIZE)
pallet_moonbeam_foreign_assets::Pallet::<T>::weight_of_erc20_burn()
}
}
pub(crate) fn transfer_asset(asset: &Asset) -> Weight {
if pallet_erc20_xcm_bridge::Pallet::<T>::is_erc20_asset(asset) {
pallet_erc20_xcm_bridge::Pallet::<T>::weight_of_erc20_transfer(&asset.id)
} else {
Weight::from_parts(200_000_000 as u64, ASSET_TRANSFER_MAX_PROOF_SIZE)
pallet_moonbeam_foreign_assets::Pallet::<T>::weight_of_erc20_transfer()
}
}
pub(crate) fn transfer_reserve_asset(asset: &Asset) -> Weight {
Expand All @@ -57,7 +55,7 @@ impl<T: frame_system::Config + pallet_erc20_xcm_bridge::Config> WeightInfo<T> {
Weight::MAX
}
pub(crate) fn deposit_asset() -> Weight {
Weight::from_parts(200_000_000 as u64, ASSET_MINT_MAX_PROOF_SIZE)
pallet_moonbeam_foreign_assets::Pallet::<T>::weight_of_erc20_mint()
}
pub(crate) fn deposit_reserve_asset() -> Weight {
Weight::from_parts(200_000_000 as u64, ASSET_MINT_MAX_PROOF_SIZE)
Expand Down
4 changes: 3 additions & 1 deletion pallets/moonbeam-xcm-benchmarks/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ impl WeighMultiAssets for Assets {
pub struct XcmWeight<Runtime, Call>(core::marker::PhantomData<(Runtime, Call)>);
impl<Runtime, Call> XcmWeightInfo<Call> for XcmWeight<Runtime, Call>
where
Runtime: frame_system::Config + pallet_erc20_xcm_bridge::Config,
Runtime: frame_system::Config
+ pallet_erc20_xcm_bridge::Config
+ pallet_moonbeam_foreign_assets::Config,
{
fn withdraw_asset(assets: &Assets) -> XCMWeight {
assets.inner().iter().fold(Weight::zero(), |acc, asset| {
Expand Down
2 changes: 1 addition & 1 deletion primitives/xcm/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

pub const MAX_ASSETS: u32 = 64;
pub const MAX_ASSETS: u32 = 20;
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ fn xtokens_precompiles_transfer() {
weight: 4_000_000,
},
)
.expect_cost(211090)
.expect_cost(348090)
.expect_no_logs()
// We expect an evm subcall ERC20.burnFrom
.with_subcall_handle(move |subcall| {
Expand Down Expand Up @@ -1659,7 +1659,7 @@ fn xtokens_precompiles_transfer_multiasset() {
weight: 4_000_000,
},
)
.expect_cost(211090)
.expect_cost(348090)
.expect_no_logs()
// We expect an evm subcall ERC20.burnFrom
.with_subcall_handle(move |subcall| {
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pallet-ethereum-xcm = { workspace = true }
pallet-evm-chain-id = { workspace = true }
pallet-maintenance-mode = { workspace = true, features = ["xcm-support"] }
pallet-migrations = { workspace = true }
pallet-moonbeam-foreign-assets = { workspace = true }
pallet-moonbeam-lazy-migrations = { workspace = true }
pallet-moonbeam-orbiters = { workspace = true }
pallet-parachain-staking = { workspace = true }
Expand Down Expand Up @@ -257,6 +258,7 @@ std = [
"pallet-identity/std",
"pallet-maintenance-mode/std",
"pallet-migrations/std",
"pallet-moonbeam-foreign-assets/std",
"pallet-moonbeam-lazy-migrations/std",
"pallet-moonbeam-orbiters/std",
"pallet-multisig/std",
Expand Down Expand Up @@ -342,6 +344,7 @@ runtime-benchmarks = [
"pallet-evm/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-migrations/runtime-benchmarks",
"pallet-moonbeam-foreign-assets/runtime-benchmarks",
"pallet-moonbeam-lazy-migrations/runtime-benchmarks",
"pallet-moonbeam-orbiters/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,9 @@ construct_runtime! {
EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin, Event<T>} = 109,
Erc20XcmBridge: pallet_erc20_xcm_bridge::{Pallet} = 110,
MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event<T>} = 111,
EvmForeignAssets: pallet_moonbeam_foreign_assets::{Pallet, Call, Storage, Event<T>} = 114,

// Utils
RelayStorageRoots: pallet_relay_storage_roots::{Pallet, Storage} = 112,

// TODO should not be included in production
Expand Down
22 changes: 22 additions & 0 deletions runtime/moonbeam/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,28 @@ impl pallet_erc20_xcm_bridge::Config for Runtime {
type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
}

pub struct AccountIdToH160;
impl sp_runtime::traits::Convert<AccountId, H160> for AccountIdToH160 {
fn convert(account_id: AccountId) -> H160 {
account_id.into()
}
}

impl pallet_moonbeam_foreign_assets::Config for Runtime {
type AccountIdToH160 = AccountIdToH160;
type AssetIdFilter = Nothing;
type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
type ForeignAssetCreatorOrigin = frame_system::EnsureNever<AccountId>;
type ForeignAssetFreezerOrigin = frame_system::EnsureNever<AccountId>;
type ForeignAssetModifierOrigin = frame_system::EnsureNever<AccountId>;
type ForeignAssetUnfreezerOrigin = frame_system::EnsureNever<AccountId>;
type OnForeignAssetCreated = ();
type MaxForeignAssets = ConstU32<256>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = moonbeam_weights::pallet_moonbeam_foreign_assets::WeightInfo<Runtime>;
type XcmLocationToH160 = LocationToH160;
}

#[cfg(feature = "runtime-benchmarks")]
mod testing {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbeam/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ fn xtokens_precompile_transfer() {
weight: 4_000_000,
},
)
.expect_cost(59490)
.expect_cost(196490)
.expect_no_logs()
.execute_returns(())
})
Expand Down Expand Up @@ -1997,7 +1997,7 @@ fn xtokens_precompile_transfer_multiasset() {
weight: 4_000_000,
},
)
.expect_cost(59490)
.expect_cost(196490)
.expect_no_logs()
.execute_returns(());
})
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pallet-ethereum-xcm = { workspace = true }
pallet-evm-chain-id = { workspace = true }
pallet-maintenance-mode = { workspace = true, features = ["xcm-support"] }
pallet-migrations = { workspace = true }
pallet-moonbeam-foreign-assets = { workspace = true }
pallet-moonbeam-lazy-migrations = { workspace = true }
pallet-moonbeam-orbiters = { workspace = true }
pallet-parachain-staking = { workspace = true }
Expand Down Expand Up @@ -257,6 +258,7 @@ std = [
"pallet-identity/std",
"pallet-maintenance-mode/std",
"pallet-migrations/std",
"pallet-moonbeam-foreign-assets/std",
"pallet-moonbeam-lazy-migrations/std",
"pallet-moonbeam-orbiters/std",
"pallet-multisig/std",
Expand Down Expand Up @@ -347,6 +349,7 @@ runtime-benchmarks = [
"pallet-evm/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-migrations/runtime-benchmarks",
"pallet-moonbeam-foreign-assets/runtime-benchmarks",
"pallet-moonbeam-lazy-migrations/runtime-benchmarks",
"pallet-moonbeam-orbiters/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,9 @@ construct_runtime! {
EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin, Event<T>} = 109,
Erc20XcmBridge: pallet_erc20_xcm_bridge::{Pallet} = 110,
MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event<T>} = 111,
EvmForeignAssets: pallet_moonbeam_foreign_assets::{Pallet, Call, Storage, Event<T>} = 114,

// Utils
RelayStorageRoots: pallet_relay_storage_roots::{Pallet, Storage} = 112,
PrecompileBenchmarks: pallet_precompile_benchmarks::{Pallet} = 113,

Expand Down
22 changes: 22 additions & 0 deletions runtime/moonriver/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,28 @@ impl pallet_erc20_xcm_bridge::Config for Runtime {
type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
}

pub struct AccountIdToH160;
impl sp_runtime::traits::Convert<AccountId, H160> for AccountIdToH160 {
fn convert(account_id: AccountId) -> H160 {
account_id.into()
}
}

impl pallet_moonbeam_foreign_assets::Config for Runtime {
type AccountIdToH160 = AccountIdToH160;
type AssetIdFilter = Nothing;
type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
type ForeignAssetCreatorOrigin = frame_system::EnsureNever<AccountId>;
type ForeignAssetFreezerOrigin = frame_system::EnsureNever<AccountId>;
type ForeignAssetModifierOrigin = frame_system::EnsureNever<AccountId>;
type ForeignAssetUnfreezerOrigin = frame_system::EnsureNever<AccountId>;
type OnForeignAssetCreated = ();
type MaxForeignAssets = ConstU32<256>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = moonriver_weights::pallet_moonbeam_foreign_assets::WeightInfo<Runtime>;
type XcmLocationToH160 = LocationToH160;
}

#[cfg(feature = "runtime-benchmarks")]
mod testing {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonriver/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ fn xtokens_precompiles_transfer() {
weight: 4_000_000,
},
)
.expect_cost(59490)
.expect_cost(196490)
.expect_no_logs()
.execute_returns(())
})
Expand Down Expand Up @@ -1977,7 +1977,7 @@ fn xtokens_precompiles_transfer_multiasset() {
weight: 4_000_000,
},
)
.expect_cost(59490)
.expect_cost(196490)
.expect_no_logs()
.execute_returns(());
})
Expand Down
10 changes: 5 additions & 5 deletions test/suites/dev/moonbase/test-fees/test-fee-multiplier-xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describeSuite({
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
transferredBalance = 100_000_000_000_000_000_000n;

await expectOk(
context.createBlock(
Expand Down Expand Up @@ -177,8 +177,8 @@ describeSuite({
},
],
weight_limit: {
refTime: 4000000000n,
proofSize: 110000n,
refTime: 9_000_000_000n,
proofSize: 150_000n,
},
descend_origin: sendingAddress,
})
Expand Down Expand Up @@ -292,8 +292,8 @@ describeSuite({
},
],
weight_limit: {
refTime: 4000000000n,
proofSize: 110000n,
refTime: 9_000_000_000n,
proofSize: 150_000n,
},
descend_origin: sendingAddress,
})
Expand Down
4 changes: 2 additions & 2 deletions test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describeSuite({
},
];

const targetXcmWeight = BigInt(GAS_LIMIT) * 25000n + 25_000_000n + 800000000n;
const targetXcmWeight = BigInt(GAS_LIMIT) * 25000n + 25_000_000n + 5_000_000_000n;
const targetXcmFee = targetXcmWeight * 50_000n;
const transferCall = context
.polkadotJs()
Expand Down Expand Up @@ -192,7 +192,7 @@ describeSuite({
},
];

const targetXcmWeight = BigInt(GAS_LIMIT) * 25000n + 25_000_000n + 800000000n;
const targetXcmWeight = BigInt(GAS_LIMIT) * 25000n + 25_000_000n + 5_000_000_000n;
const targetXcmFee = targetXcmWeight * 50_000n;
const transferCall = context
.polkadotJs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ describeSuite({
},
],
weight_limit: {
refTime: 4000000000n,
proofSize: 80000n,
refTime: 9_000_000_000n,
proofSize: 100_000n,
} as any,
beneficiary: alith.address,
})
Expand Down
Loading
Loading