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

pallet-xcm: add new extrinsic for asset transfers using explicit XCM transfer types #3695

Merged
merged 37 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dda9308
pallet-xcm: deprecate unlimited_* weight extrinsics
acatangiu Mar 13, 2024
1db1cae
pallet-xcm: remove extrinsics guessed weight and rely on runtime benc…
acatangiu Mar 13, 2024
f5e1dfb
pallet-xcm: add new extrinsic for asset transfers using explicit reserve
acatangiu Mar 13, 2024
547eeee
add more trace logging to XCM transport
acatangiu Mar 13, 2024
c7ee1af
minor style fix
acatangiu Mar 13, 2024
ed77fde
integration-tests: add scenario for parachain sending asset over brid…
acatangiu Mar 13, 2024
a7a44c9
make penpal UniversalLocation configurable
acatangiu Mar 14, 2024
ffa6250
penpal: charge XCM delivery fees for accurate real-world testing
acatangiu Mar 22, 2024
4afba95
integration-tests: fix tests for penpal charging delivery fees
acatangiu Mar 22, 2024
210cdd2
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Mar 23, 2024
c918bea
fix test
acatangiu Mar 23, 2024
3db344b
add prdoc
acatangiu Mar 25, 2024
10d2c40
fix clippy
acatangiu Mar 25, 2024
5b48155
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Mar 27, 2024
dbe453d
add test for westend->rococo direction
acatangiu Mar 27, 2024
42e4041
nit
acatangiu Mar 27, 2024
e794df3
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 1, 2024
81dc911
pallet-xcm: specify explicit transfer type
acatangiu Apr 3, 2024
e1dbf7a
add more tests
acatangiu Apr 3, 2024
ef83eab
fix prdoc
acatangiu Apr 4, 2024
a2b8708
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 4, 2024
4250692
refactor tests
acatangiu Apr 4, 2024
888d403
even more tests
acatangiu Apr 4, 2024
1c86e6e
another test
acatangiu Apr 4, 2024
b82d0b9
add teleport test as well
acatangiu Apr 4, 2024
f4e88da
rename xt and update docs
acatangiu Apr 4, 2024
4f2381c
fix weights
acatangiu Apr 4, 2024
36af01f
add tests to westend
acatangiu Apr 4, 2024
bd9233a
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 4, 2024
9c7bd39
remove leftover comment
acatangiu Apr 4, 2024
adf5128
Apply suggestions from code review
acatangiu Apr 11, 2024
1347f0b
fix logs
acatangiu Apr 11, 2024
e3acff2
fix api
acatangiu Apr 11, 2024
4a44194
Merge branch 'master' into transfer-using-explicit-reserve
acatangiu Apr 11, 2024
0d407eb
Update polkadot/xcm/pallet-xcm/src/lib.rs
acatangiu Apr 12, 2024
22093d0
".git/.scripts/commands/fmt/fmt.sh"
Apr 12, 2024
a673792
Merge branch 'master' into transfer-using-explicit-reserve
acatangiu Apr 12, 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
18 changes: 17 additions & 1 deletion bridges/modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ pub mod pallet {
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Called when new message is sent (queued to local outbound XCM queue) over the bridge.
pub(crate) fn on_message_sent_to_bridge(message_size: u32) {
log::trace!(
target: "xcm::xcm_bridge_hub_router::on_message_sent_to_bridge",
"message_size: {:?}", message_size,
);
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
let _ = Bridge::<T, I>::try_mutate(|bridge| {
let is_channel_with_bridge_hub_congested = T::WithBridgeHubChannel::is_congested();
let is_bridge_congested = bridge.is_congested;
Expand Down Expand Up @@ -238,6 +242,10 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
remote_location: &InteriorLocation,
message: &Xcm<()>,
) -> Option<(Location, Option<Asset>)> {
log::trace!(
target: "xcm::xcm_bridge_hub_router::exporter_for",
"network: {:?}, remote_location: {:?}, msg: {:?}", network, remote_location, message
);
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
// ensure that the message is sent to the expected bridged network (if specified).
if let Some(bridged_network) = T::BridgedNetworkId::get() {
if *network != bridged_network {
Expand Down Expand Up @@ -300,7 +308,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {

log::info!(
target: LOG_TARGET,
"Going to send message to {:?} ({} bytes) over bridge. Computed bridge fee {:?} using fee factor {}",
"Validate send message to {:?} ({} bytes) over bridge. Computed bridge fee {:?} using fee factor {}",
(network, remote_location),
message_size,
fee,
Expand All @@ -321,6 +329,10 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
dest: &mut Option<Location>,
xcm: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
log::trace!(
target: "xcm::xcm_bridge_hub_router::validate",
"msg: {:?}, destination: {:?}", xcm, dest,
);
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
// `dest` and `xcm` are required here
let dest_ref = dest.as_ref().ok_or(SendError::MissingArgument)?;
let xcm_ref = xcm.as_ref().ok_or(SendError::MissingArgument)?;
Expand Down Expand Up @@ -366,6 +378,10 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
// increase delivery fee factor if required
Self::on_message_sent_to_bridge(message_size);

log::trace!(
target: "xcm::xcm_bridge_hub_router::deliver",
"message sent, xcm_hash: {:?}", xcm_hash,
);
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
Ok(xcm_hash)
}
}
Expand Down
5 changes: 4 additions & 1 deletion cumulus/pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,10 @@ impl<T: Config> SendXcm for Pallet<T> {
Self::deposit_event(Event::XcmpMessageSent { message_hash: hash });
Ok(hash)
},
Err(e) => Err(SendError::Transport(e.into())),
Err(e) => {
log::error!(target: "xcm::XcmpQueue::deliver", "error: {:?}", e);
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
Err(SendError::Transport(e.into()))
},
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use frame_support::traits::OnInitialize;
// Cumulus
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
impl_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain,
xcm_emulator::decl_test_parachains,
};

// Penpal Parachain declaration
Expand Down Expand Up @@ -77,3 +78,5 @@ impl_assert_events_helpers_for_parachain!(PenpalA);
impl_assert_events_helpers_for_parachain!(PenpalB);
impl_assets_helpers_for_parachain!(PenpalA);
impl_assets_helpers_for_parachain!(PenpalB);
impl_xcm_helpers_for_parachain!(PenpalA);
impl_xcm_helpers_for_parachain!(PenpalB);
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,6 @@ fn relay_limited_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult {
)
}

fn relay_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult {
<Rococo as RococoPallet>::XcmPallet::teleport_assets(
t.signed_origin,
bx!(t.args.dest.into()),
bx!(t.args.beneficiary.into()),
bx!(t.args.assets.into()),
t.args.fee_asset_item,
)
}

fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult {
<AssetHubRococo as AssetHubRococoPallet>::PolkadotXcm::limited_teleport_assets(
t.signed_origin,
Expand All @@ -266,16 +256,6 @@ fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResu
)
}

fn system_para_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult {
<AssetHubRococo as AssetHubRococoPallet>::PolkadotXcm::teleport_assets(
t.signed_origin,
bx!(t.args.dest.into()),
bx!(t.args.beneficiary.into()),
bx!(t.args.assets.into()),
t.args.fee_asset_item,
)
}

fn para_to_system_para_transfer_assets(t: ParaToSystemParaTest) -> DispatchResult {
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets(
t.signed_origin,
Expand Down Expand Up @@ -421,129 +401,6 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() {
assert_eq!(receiver_balance_after, receiver_balance_before);
}

/// Teleport of native asset from Relay Chain to the System Parachain should work
#[test]
fn teleport_native_assets_from_relay_to_system_para_works() {
// Init values for Relay Chain
let amount_to_send: Balance = ROCOCO_ED * 1000;
let dest = Rococo::child_location_of(AssetHubRococo::para_id());
let beneficiary_id = AssetHubRococoReceiver::get();
let test_args = TestContext {
sender: RococoSender::get(),
receiver: AssetHubRococoReceiver::get(),
args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send),
};

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

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

test.set_assertion::<Rococo>(relay_origin_assertions);
test.set_assertion::<AssetHubRococo>(para_dest_assertions);
test.set_dispatchable::<Rococo>(relay_teleport_assets);
test.assert();

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

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

// 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);
}

/// Teleport of native asset from System Parachains to the Relay Chain
/// should work when there is enough balance in Relay Chain's `CheckAccount`
#[test]
fn teleport_native_assets_back_from_system_para_to_relay_works() {
// Dependency - Relay Chain's `CheckAccount` should have enough balance
teleport_native_assets_from_relay_to_system_para_works();

// Init values for Relay Chain
let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000;
let destination = AssetHubRococo::parent_location();
let beneficiary_id = RococoReceiver::get();
let assets = (Parent, amount_to_send).into();

let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: RococoReceiver::get(),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

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

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

test.set_assertion::<AssetHubRococo>(para_origin_assertions);
test.set_assertion::<Rococo>(relay_dest_assertions);
test.set_dispatchable::<AssetHubRococo>(system_para_teleport_assets);
test.assert();

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

let delivery_fees = AssetHubRococo::execute_with(|| {
xcm_helpers::teleport_assets_delivery_fees::<
<AssetHubRococoXcmConfig 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);
}

/// Teleport of native asset from System Parachain to Relay Chain
/// shouldn't work when there is not enough balance in Relay Chain's `CheckAccount`
#[test]
fn teleport_native_assets_from_system_para_to_relay_fails() {
// Init values for Relay Chain
let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000;
let destination = AssetHubRococo::parent_location();
let beneficiary_id = RococoReceiver::get();
let assets = (Parent, amount_to_send).into();

let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: RococoReceiver::get(),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

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

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

test.set_assertion::<AssetHubRococo>(para_origin_assertions);
test.set_assertion::<Rococo>(relay_dest_assertions_fail);
test.set_dispatchable::<AssetHubRococo>(system_para_teleport_assets);
test.assert();

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

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

// Sender's balance is reduced
assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after);
// Receiver's balance does not change
assert_eq!(receiver_balance_after, receiver_balance_before);
}

#[test]
fn teleport_to_other_system_parachains_works() {
let amount = ASSET_HUB_ROCOCO_ED * 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ mod imports {
pub use penpal_runtime::xcm_config::{
LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub,
LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub,
XcmConfig as PenpalWestendXcmConfig,
};
pub use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig;

Expand Down
Loading
Loading