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: add xcm benchmarking #995

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
92ab89e
WIP - add xcm benchmark
dmoka Jan 16, 2025
39d7c86
make fungible xcm benchmarks work
dmoka Jan 21, 2025
fc881f3
add pallet xcm generic benchmark tests
dmoka Jan 21, 2025
dcccb56
remove temporary benchmark workaround
dmoka Jan 21, 2025
401cc4c
plug in new xcm weights to runtime
dmoka Jan 22, 2025
673a267
remove unused test
dmoka Jan 22, 2025
76cfaf5
undo temporary changes
dmoka Jan 22, 2025
904446a
clean up todos
dmoka Jan 22, 2025
0cb89d0
remove benchmark generation comments
dmoka Jan 22, 2025
f6f432b
fix exchange asset test
dmoka Jan 22, 2025
d7566b0
rebenchmark generic xcm extrinsics
dmoka Jan 22, 2025
4037379
fix exchange asset test to make it dynamic to weight changes
dmoka Jan 22, 2025
da13256
make holding worst case
dmoka Jan 22, 2025
69398a7
addd hydra reference to template file
dmoka Jan 22, 2025
fe2422a
make teleport benchmark as disabled with max value as we dont support…
dmoka Jan 22, 2025
ebcfa43
incldue worst case route execution in exchange asset benchmark
dmoka Jan 22, 2025
c42d791
adjust comment
dmoka Jan 22, 2025
e946ae0
fix reserve asset deposited benchmark as it was skipped
dmoka Jan 23, 2025
3e8d93a
fix failing test
dmoka Jan 23, 2025
e0395a1
fix weigher in integration test
dmoka Jan 23, 2025
a463865
use prod weigher in tests
dmoka Jan 23, 2025
3c67cce
merger master to feat/bench-xcm
dmoka Jan 23, 2025
d8ee173
fix weight file to prevent compilation error
dmoka Jan 23, 2025
1276bd3
make clippy happy
dmoka Jan 23, 2025
a721fde
rebench xcm on ref machine
dmoka Jan 23, 2025
6f76c4e
add negative test case for initiate teleport
dmoka Jan 23, 2025
b6b87df
remove unnecessary impls
dmoka Jan 23, 2025
fd077d0
remove todo
dmoka Jan 23, 2025
889390b
remove space
dmoka Jan 23, 2025
0463713
bump versions
dmoka Jan 23, 2025
6f40258
formatting
dmoka Jan 23, 2025
ec385d7
formatting
dmoka Jan 23, 2025
c18598d
fix test
dmoka Jan 23, 2025
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
5 changes: 3 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ ethereum = { version = "0.15.0", default-features = false, features = ["with-cod

# Polkadot dependencies
pallet-xcm = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4", default-features = false }
pallet-xcm-benchmarks = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4", default-features = false }
polkadot-cli = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
polkadot-core-primitives = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4", default-features = false }
polkadot-parachain = { package = "polkadot-parachain-primitives", git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4", default-features = false, features = [
Expand Down Expand Up @@ -509,6 +510,7 @@ xcm-fee-payment-runtime-api = { git = "https://github.com/galacticcouncil/polkad

# Polkadot dependencies
pallet-xcm = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
pallet-xcm-benchmarks = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
polkadot-cli = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
polkadot-core-primitives = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
polkadot-parachain = { package = "polkadot-parachain-primitives", git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4"}
Expand Down Expand Up @@ -664,6 +666,7 @@ xcm-fee-payment-runtime-api = { git = "https://github.com/galacticcouncil/polkad

# Polkadot dependencies
pallet-xcm = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
pallet-xcm-benchmarks = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
polkadot-cli = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
polkadot-core-primitives = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4" }
polkadot-parachain = { package = "polkadot-parachain-primitives", git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "release-polkadot-v1.11.0-patch4"}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.31.0"
version = "1.31.1"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/src/exchange_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use frame_support::{assert_ok, pallet_prelude::*};
use hydradx_runtime::AssetRegistry;
use hydradx_runtime::Router;
use hydradx_runtime::RuntimeOrigin;
use hydradx_runtime::{Omnipool, RuntimeCall};
use hydradx_traits::AssetKind;
use hydradx_traits::Create;
use orml_traits::currency::MultiCurrency;
Expand Down Expand Up @@ -1192,15 +1193,15 @@ fn half(asset: &Asset) -> Asset {
}
use pallet_broadcast::types::ExecutionType;
use rococo_runtime::xcm_config::BaseXcmWeight;
use xcm_builder::FixedWeightBounds;
use xcm_builder::{FixedWeightBounds, WeightInfoBounds};
use xcm_executor::traits::WeightBounds;

fn craft_transfer_and_swap_xcm_with_4_hops<RC: Decode + GetDispatchInfo>(
give_asset: Asset,
want_asset: Asset,
is_sell: bool,
) -> VersionedXcm<RC> {
type Weigher<RC> = FixedWeightBounds<BaseXcmWeight, RC, ConstU32<100>>;
type Weigher<RC> = hydradx_runtime::xcm::DynamicWeigher<RC>;

let give_reserve_chain = Location::new(
1,
Expand Down
102 changes: 102 additions & 0 deletions integration-tests/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,105 @@ fn unified_event_context_should_be_cleared_when_error_happens_in_xcm_prepare() {
assert!(context.is_empty())
});
}

#[test]
fn initiate_teleport_should_fail_as_disabled() {
// Arrange
TestNet::reset();

let xcm_interior_at_acala =
cumulus_primitives_core::Junctions::X1(Arc::new([cumulus_primitives_core::Junction::AccountId32 {
network: None,
id: evm_account().into(),
}]));

let xcm_origin_at_hydra = Location {
parents: 1,
interior: cumulus_primitives_core::Junctions::X2(Arc::new([
cumulus_primitives_core::Junction::Parachain(ACALA_PARA_ID),
cumulus_primitives_core::Junction::AccountId32 {
network: None,
id: evm_account().into(),
},
])),
};

let acala_account_id_at_hydra: AccountId =
HashedDescription::<AccountId, DescribeFamily<DescribeAllTerminal>>::convert_location(&xcm_origin_at_hydra)
.unwrap();

Hydra::execute_with(|| {
init_omnipool();

assert_ok!(hydradx_runtime::Balances::transfer_allow_death(
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
acala_account_id_at_hydra.clone(),
1_000 * UNITS,
));

assert_eq!(
hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra.clone())),
0
);
});

// Act
Acala::execute_with(|| {
let omni_sell =
hydradx_runtime::RuntimeCall::Omnipool(pallet_omnipool::Call::<hydradx_runtime::Runtime>::sell {
asset_in: HDX,
asset_out: DAI,
amount: UNITS,
min_buy_amount: 0,
});

let hdx_loc = Location::new(
1,
cumulus_primitives_core::Junctions::X2(Arc::new([
cumulus_primitives_core::Junction::Parachain(HYDRA_PARA_ID),
cumulus_primitives_core::Junction::GeneralIndex(0),
])),
);
let asset_to_withdraw: Asset = Asset {
id: cumulus_primitives_core::AssetId(hdx_loc.clone()),
fun: Fungible(900 * UNITS),
};
let asset_for_buy_execution: Asset = Asset {
id: cumulus_primitives_core::AssetId(hdx_loc),
fun: Fungible(800 * UNITS),
};

let message = Xcm(vec![
WithdrawAsset(asset_to_withdraw.clone().into()),
BuyExecution {
fees: asset_for_buy_execution,
weight_limit: Unlimited,
},
InitiateTeleport {
assets: asset_to_withdraw.into(),
dest: Location::here(),
xcm: Xcm::new(),
},
]);

let dest_hydradx = Location::new(
1,
cumulus_primitives_core::Junctions::X1(Arc::new([cumulus_primitives_core::Junction::Parachain(
HYDRA_PARA_ID,
)])),
);

assert_ok!(hydradx_runtime::PolkadotXcm::send_xcm(
xcm_interior_at_acala,
dest_hydradx,
message
));

assert!(!matches!(
last_hydra_events(10).first(),
Some(hydradx_runtime::RuntimeEvent::XcmpQueue(
cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }
))
));
});
}
6 changes: 5 additions & 1 deletion runtime/hydradx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-runtime"
version = "282.0.0"
version = "283.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down Expand Up @@ -118,6 +118,7 @@ parachains-common = { workspace = true }
# Polkadot dependencies
polkadot-parachain = { workspace = true }
pallet-xcm = { workspace = true }
pallet-xcm-benchmarks = { workspace = true, optional = true }
polkadot-xcm = { workspace = true }
xcm-executor = { workspace = true }
xcm-builder = { workspace = true }
Expand Down Expand Up @@ -228,6 +229,8 @@ runtime-benchmarks = [
"pallet-referenda/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"pallet-dispatcher/runtime-benchmarks",
"cumulus-primitives-utility/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks"
]
std = [
"codec/std",
Expand All @@ -247,6 +250,7 @@ std = [
"cumulus-pallet-xcmp-queue/std",
"staging-parachain-info/std",
"pallet-xcm/std",
"pallet-xcm-benchmarks?/std",
"polkadot-xcm/std",
"xcm-fee-payment-runtime-api/std",
"xcm-executor/std",
Expand Down
Loading
Loading