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

refactor(xcm)!: restrict reserves to AssetHub, remove relay chain support #423

Merged
merged 10 commits into from
Jan 16, 2025
Merged
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- name: Check Build
run: |
cargo check --release --locked --features=runtime-benchmarks,try-runtime
cargo check --release --locked --workspace --exclude integration-tests --features=runtime-benchmarks,try-runtime
peterwht marked this conversation as resolved.
Show resolved Hide resolved

check-ismp:
needs: lint
Expand All @@ -52,7 +52,7 @@ jobs:
- uses: "./.github/actions/init"
- name: Check Build with ISMP
run: |
cargo check --release --locked --features=ismp,runtime-benchmarks,try-runtime
cargo check --release --locked --workspace --exclude integration-tests --features=ismp,runtime-benchmarks,try-runtime

clippy:
needs: lint
Expand All @@ -71,7 +71,7 @@ jobs:
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --release --locked --features=runtime-benchmarks
args: --release --locked --workspace --exclude integration-tests --features=runtime-benchmarks

clippy-ismp:
needs: lint
Expand All @@ -90,7 +90,7 @@ jobs:
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --release --locked --features=runtime-benchmarks,ismp
args: --release --locked --workspace --exclude integration-tests --features=runtime-benchmarks,ismp
peterwht marked this conversation as resolved.
Show resolved Hide resolved

test:
needs: lint
Expand All @@ -101,18 +101,24 @@ jobs:
- uses: "./.github/actions/init"

- name: Run tests
run: cargo test --release --locked --workspace --features=runtime-benchmarks --exclude integration-tests
run: cargo test --release --locked --workspace --exclude integration-tests --features=runtime-benchmarks

integration-tests:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
features:
- "westend,testnet"
- "paseo,testnet"
steps:
- uses: actions/checkout@v4

- uses: "./.github/actions/init"

- name: Run integration tests
run: cargo test --release --locked --package integration-tests
working-directory: integration-tests
run: cargo test --release --locked --features "${{ matrix.features }}"

api-tests:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

11 changes: 7 additions & 4 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ westend-runtime-constants = { workspace = true, optional = true }
pop-runtime-common.workspace = true
pop-runtime-devnet.workspace = true
pop-runtime-mainnet.workspace = true
pop-runtime-testnet.workspace = true

[features]
default = [ "westend" ]
mainnet = [ "pop-runtime-mainnet/default" ]
default = [ "std" ]
devnet = [ "pop-runtime-devnet/std" ]
mainnet = [ "pop-runtime-mainnet/std" ]
paseo = [
"asset-hub-paseo-runtime",
"paseo-runtime",
"paseo-runtime-constants",
"std",
]
runtime-benchmarks = [
"asset-hub-paseo-runtime?/runtime-benchmarks",
Expand All @@ -75,6 +76,7 @@ runtime-benchmarks = [
"pop-runtime-common/runtime-benchmarks",
"pop-runtime-devnet/runtime-benchmarks",
"pop-runtime-mainnet/runtime-benchmarks",
"pop-runtime-testnet/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"westend-runtime?/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
Expand Down Expand Up @@ -107,6 +109,7 @@ std = [
"xcm-executor/std",
"xcm/std",
]
testnet = [ "pop-runtime-testnet/std" ]
try-runtime = [
"asset-hub-paseo-runtime?/try-runtime",
"asset-hub-westend-runtime?/try-runtime",
Expand All @@ -117,12 +120,12 @@ try-runtime = [
"paseo-runtime?/try-runtime",
"pop-runtime-devnet/try-runtime",
"pop-runtime-mainnet/try-runtime",
"pop-runtime-testnet/try-runtime",
"sp-runtime/try-runtime",
"westend-runtime?/try-runtime",
]
westend = [
"asset-hub-westend-runtime",
"std",
"westend-runtime",
"westend-runtime-constants",
]
8 changes: 8 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
In order to run the integration tests you have to specify what Relay and Pop runtime to use. The first also determines the Asset Hub runtime.
peterwht marked this conversation as resolved.
Show resolved Hide resolved
```shell
cargo test --features=<relay>,<pop_runtime>
```
For example:
```shell
cargo test --features=paseo,testnet
```
4 changes: 3 additions & 1 deletion integration-tests/src/chains/pop_network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use emulated_integration_tests_common::{
impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
};
use frame_support::traits::OnInitialize;
#[cfg(not(feature = "mainnet"))]
#[cfg(feature = "devnet")]
use pop_runtime_devnet as runtime;
#[cfg(feature = "mainnet")]
use pop_runtime_mainnet as runtime;
#[cfg(feature = "testnet")]
use pop_runtime_testnet as runtime;

// PopNetwork Parachain declaration
decl_test_parachains! {
Expand Down
127 changes: 2 additions & 125 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ decl_test_sender_receiver_accounts_parameter_types! {
type RelayToParaTest = Test<RelayRelay, PopNetworkPara>;
type SystemParaToParaTest = Test<AssetHubPara, PopNetworkPara>;
type ParaToSystemParaTest = Test<PopNetworkPara, AssetHubPara>;
type ParaToRelayTest = Test<PopNetworkPara, RelayRelay>;

fn relay_to_para_sender_assertions(t: RelayToParaTest) {
type RuntimeEvent = <RelayRelay as Chain>::RuntimeEvent;
Expand Down Expand Up @@ -124,24 +123,6 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) {
);
}

fn para_to_relay_sender_assertions(t: ParaToRelayTest) {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
type RuntimeEvent = <PopNetworkPara as Chain>::RuntimeEvent;
PopNetworkPara::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(
864_610_000,
8_799,
)));
assert_expected_events!(
PopNetworkPara,
vec![
// Amount to reserve transfer is transferred to Parachain's Sovereign account
RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount }) => {
who: *who == t.sender.account_id,
amount: *amount == t.args.amount,
},
]
);
}

fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <AssetHubPara as Chain>::RuntimeEvent;
let sov_pop_net_on_ahr = AssetHubPara::sovereign_account_id_of(
Expand All @@ -165,29 +146,6 @@ fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) {
);
}

fn para_to_relay_receiver_assertions(t: ParaToRelayTest) {
type RuntimeEvent = <RelayRelay as Chain>::RuntimeEvent;
let sov_pop_net_on_relay = RelayRelay::sovereign_account_id_of(RelayRelay::child_location_of(
PopNetworkPara::para_id(),
));
assert_expected_events!(
RelayRelay,
vec![
// Amount to reserve transfer is withdrawn from Parachain's Sovereign account
RuntimeEvent::Balances(
pallet_balances::Event::Burned { who, amount }
) => {
who: *who == sov_pop_net_on_relay.clone().into(),
amount: *amount == t.args.amount,
},
RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {},
RuntimeEvent::MessageQueue(
pallet_message_queue::Event::Processed { success: true, .. }
) => {},
]
);
}

fn relay_to_para_reserve_transfer_assets(t: RelayToParaTest) -> DispatchResult {
<RelayRelay as RelayPallet>::XcmPallet::limited_reserve_transfer_assets(
t.signed_origin,
Expand Down Expand Up @@ -221,35 +179,6 @@ fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> Dispa
)
}

fn para_to_relay_reserve_transfer_assets(t: ParaToRelayTest) -> DispatchResult {
<PopNetworkPara as PopNetworkParaPallet>::PolkadotXcm::limited_reserve_transfer_assets(
t.signed_origin,
bx!(t.args.dest.into()),
bx!(t.args.beneficiary.into()),
bx!(t.args.assets.into()),
t.args.fee_asset_item,
t.args.weight_limit,
)
}

// Funds Pop with relay tokens
fn fund_pop_from_relay(
sender: sp_runtime::AccountId32,
amount_to_send: Balance,
beneficiary: sp_runtime::AccountId32,
) {
let destination = RelayRelay::child_location_of(PopNetworkPara::para_id());
let test_args = TestContext {
sender,
receiver: beneficiary.clone(),
args: TestArgs::new_relay(destination, beneficiary, amount_to_send),
};

let mut test = RelayToParaTest::new(test_args);
test.set_dispatchable::<RelayRelay>(relay_to_para_reserve_transfer_assets);
test.assert();
}

// Funds Pop with relay tokens from system para
fn fund_pop_from_system_para(
sender: sp_runtime::AccountId32,
Expand All @@ -271,7 +200,8 @@ fn fund_pop_from_system_para(

/// Reserve Transfers of native asset from Relay to Parachain should work
#[test]
fn reserve_transfer_native_asset_from_relay_to_para() {
#[should_panic]
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
fn reserve_transfer_native_asset_from_relay_to_para_should_fail() {
init_tracing();

// Init values for Relay
Expand Down Expand Up @@ -316,59 +246,6 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
assert!(receiver_balance_after < receiver_balance_before + amount_to_send);
}

/// Reserve Transfers of native asset from Parachain to Relay should work
#[test]
fn reserve_transfer_native_asset_from_para_to_relay() {
init_tracing();

// Setup: reserve transfer from relay to Pop, so that sovereign account accurate for return
// transfer
let amount_to_send: Balance = RELAY_ED * 1_000;
fund_pop_from_relay(RelayRelaySender::get(), amount_to_send, PopNetworkParaReceiver::get()); // alice on relay > bob on pop

// Init values for Pop Network Parachain
let destination = PopNetworkPara::parent_location(); // relay
let beneficiary_id = RelayRelayReceiver::get(); // bob on relay
let amount_to_send = PopNetworkPara::account_data_of(PopNetworkParaReceiver::get()).free; // bob on pop balance
let assets = (Parent, amount_to_send).into();

let test_args = TestContext {
sender: PopNetworkParaReceiver::get(), // bob on pop
receiver: RelayRelayReceiver::get(), // bob on relay
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = ParaToRelayTest::new(test_args);

let sender_balance_before = test.sender.balance;
let receiver_balance_before = test.receiver.balance;

test.set_assertion::<PopNetworkPara>(para_to_relay_sender_assertions);
test.set_assertion::<RelayRelay>(para_to_relay_receiver_assertions);
test.set_dispatchable::<PopNetworkPara>(para_to_relay_reserve_transfer_assets);
test.assert();

let sender_balance_after = test.sender.balance;
let receiver_balance_after = test.receiver.balance;

let delivery_fees = PopNetworkPara::execute_with(|| {
xcm_helpers::teleport_assets_delivery_fees::<
<PopNetworkXcmConfig as xcm_executor::Config>::XcmSender,
>(
test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest
)
});

// Sender's balance is reduced
assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after);
// Receiver's balance is increased
assert!(receiver_balance_after > receiver_balance_before);
// Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`;
// `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown
// but should be non-zero
assert!(receiver_balance_after < receiver_balance_before + amount_to_send);
}

/// Reserve Transfers of native asset from System Parachain to Parachain should work
#[test]
fn reserve_transfer_native_asset_from_system_para_to_para() {
Expand Down
30 changes: 25 additions & 5 deletions runtime/devnet/src/config/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds,
FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
FrameTransactionalProcessor, FungibleAdapter, IsConcrete, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
UsingComponents, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::XcmExecutor;

Expand Down Expand Up @@ -91,14 +91,14 @@
pub const MaxAssetsIntoHolding: u32 = 64;
}

pub struct ParentOrParentsExecutivePlurality;

Check warning on line 94 in runtime/devnet/src/config/xcm.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct

warning: missing documentation for a struct --> runtime/devnet/src/config/xcm.rs:94:1 | 94 | pub struct ParentOrParentsExecutivePlurality; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
impl Contains<Location> for ParentOrParentsExecutivePlurality {
fn contains(location: &Location) -> bool {
matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }]))
}
}

pub type Barrier = TrailingSetTopicAsId<(

Check warning on line 101 in runtime/devnet/src/config/xcm.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a type alias

warning: missing documentation for a type alias --> runtime/devnet/src/config/xcm.rs:101:1 | 101 | pub type Barrier = TrailingSetTopicAsId<( | ^^^^^^^^^^^^^^^^
TakeWeightCredit,
AllowKnownQueryResponses<PolkadotXcm>,
WithComputedOrigin<
Expand All @@ -123,9 +123,29 @@
if *asset_loc == Location::from(Parent))
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
}
}
pub type TrustedReserves = (NativeAsset, NativeAssetFrom<AssetHub>);
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved

/// Accepts native assets, except from the relay because AH functions as the reserve.
pub struct NativeAssetExceptRelay;
impl ContainsPair<Asset, Location> for NativeAssetExceptRelay {
fn contains(asset: &Asset, origin: &Location) -> bool {
log::trace!(
target: "xcm::contains",
"asset: {:?}, origin: {:?}",
asset,
origin
);
// Exclude the relay location.
if matches!(origin, Location { parents: 1, interior: Here }) {
return false;
}
matches!(asset.id, AssetId(ref id) if id == origin)
}
}

/// Combinations of (Asset, Location) pairs which we trust as reserves.
pub type TrustedReserves = (NativeAssetFrom<AssetHub>, NativeAssetExceptRelay);

pub struct XcmConfig;

Check warning on line 148 in runtime/devnet/src/config/xcm.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct

warning: missing documentation for a struct --> runtime/devnet/src/config/xcm.rs:148:1 | 148 | pub struct XcmConfig; | ^^^^^^^^^^^^^^^^^^^^
impl xcm_executor::Config for XcmConfig {
type Aliasers = Nothing;
type AssetClaims = PolkadotXcm;
Expand Down
1 change: 1 addition & 0 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ substrate-wasm-builder.workspace = true

[dependencies]
codec.workspace = true
log.workspace = true
scale-info.workspace = true
smallvec.workspace = true

Expand Down
Loading
Loading