Skip to content
Prev Previous commit
Next Next commit
Re-use validate_xcm_nesting for ChildParachainRouter
  • Loading branch information
bkontur committed Apr 22, 2024
commit d5a78ab8dce8df9a9f30e73ea2a07b78afe24121
5 changes: 4 additions & 1 deletion polkadot/runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use primitives::{
MAX_CODE_SIZE,
};
use runtime_parachains::{
configuration, origin, paras, shared, Origin as ParaOrigin, ParaLifecycle,
configuration, dmp, origin, paras, shared, Origin as ParaOrigin, ParaLifecycle,
};
use sp_core::H256;
use sp_io::TestExternalities;
Expand Down Expand Up @@ -84,6 +84,7 @@ frame_support::construct_runtime!(
Paras: paras,
ParasShared: shared,
ParachainsOrigin: origin,
Dmp: dmp,

// Para Onboarding Pallets
Registrar: paras_registrar,
Expand Down Expand Up @@ -201,6 +202,8 @@ impl shared::Config for Test {
type DisabledValidators = ();
}

impl dmp::Config for Test {}

impl origin::Config for Test {}

parameter_types! {
Expand Down
44 changes: 42 additions & 2 deletions polkadot/runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ where
let config = configuration::ActiveConfig::<T>::get();
let para = id.into();
let price = P::price_for_delivery(para, &xcm);
let blob = W::wrap_version(&d, xcm).map_err(|()| DestinationUnsupported)?.encode();
let versioned_xcm = W::wrap_version(&d, xcm).map_err(|()| DestinationUnsupported)?;
versioned_xcm.validate_xcm_nesting().map_err(|()| ExceedsMaxMessageSize)?;
let blob = versioned_xcm.encode();
dmp::Pallet::<T>::can_queue_downward_message(&config, &para, &blob)
.map_err(Into::<SendError>::into)?;

Expand Down Expand Up @@ -236,9 +238,11 @@ impl EnsureForParachain for () {
#[cfg(test)]
mod tests {
use super::*;
use frame_support::parameter_types;
use crate::integration_tests::new_test_ext;
use frame_support::{assert_ok, parameter_types};
use runtime_parachains::FeeTracker;
use sp_runtime::FixedU128;
use xcm::MAX_XCM_DECODE_DEPTH;

parameter_types! {
pub const BaseDeliveryFee: u128 = 300_000_000;
Expand Down Expand Up @@ -297,4 +301,40 @@ mod tests {
(FeeAssetId::get(), result).into()
);
}

#[test]
fn child_parachain_router_validate_nested_xcm_works() {
let dest = Parachain(5555);

type Router = ChildParachainRouter<
crate::integration_tests::Test,
(),
NoPriceForMessageDelivery<ParaId>,
>;

// Message that is not too deeply nested:
let mut good = Xcm(vec![ClearOrigin]);
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
good = Xcm(vec![SetAppendix(good)]);
}

new_test_ext().execute_with(|| {
configuration::ActiveConfig::<crate::integration_tests::Test>::mutate(|c| {
c.max_downward_message_size = u32::MAX;
});

// Check that the good message is validated:
assert_ok!(<Router as SendXcm>::validate(
&mut Some(dest.into()),
&mut Some(good.clone())
));

// Nesting the message one more time should reject it:
let bad = Xcm(vec![SetAppendix(good)]);
assert_eq!(
Err(ExceedsMaxMessageSize),
<Router as SendXcm>::validate(&mut Some(dest.into()), &mut Some(bad))
);
});
}
}