Introduce hard limit on XCM assets (#3579)

This commit is contained in:
Gavin Wood
2021-08-05 23:51:52 +02:00
committed by GitHub
parent 68c03f66f3
commit 3e9b8b47b3
+7
View File
@@ -81,6 +81,9 @@ pub mod pallet {
type LocationInverter: InvertLocation; type LocationInverter: InvertLocation;
} }
/// The maximum number of distinct assets allowed to be transferred in a single helper extrinsic.
const MAX_ASSETS_FOR_TRANSFER: usize = 2;
#[pallet::event] #[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)] #[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> { pub enum Event<T: Config> {
@@ -100,6 +103,8 @@ pub mod pallet {
Empty, Empty,
/// Could not reanchor the assets to declare the fees for the destination chain. /// Could not reanchor the assets to declare the fees for the destination chain.
CannotReanchor, CannotReanchor,
/// Too many assets have been attempted for transfer.
TooManyAssets,
} }
#[pallet::hooks] #[pallet::hooks]
@@ -152,6 +157,7 @@ pub mod pallet {
dest_weight: Weight, dest_weight: Weight,
) -> DispatchResult { ) -> DispatchResult {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?; let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
ensure!(assets.len() <= MAX_ASSETS_FOR_TRANSFER, Error::<T>::TooManyAssets);
let value = (origin_location, assets); let value = (origin_location, assets);
ensure!(T::XcmTeleportFilter::contains(&value), Error::<T>::Filtered); ensure!(T::XcmTeleportFilter::contains(&value), Error::<T>::Filtered);
let (origin_location, assets) = value; let (origin_location, assets) = value;
@@ -214,6 +220,7 @@ pub mod pallet {
dest_weight: Weight, dest_weight: Weight,
) -> DispatchResult { ) -> DispatchResult {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?; let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
ensure!(assets.len() <= MAX_ASSETS_FOR_TRANSFER, Error::<T>::TooManyAssets);
let value = (origin_location, assets); let value = (origin_location, assets);
ensure!(T::XcmReserveTransferFilter::contains(&value), Error::<T>::Filtered); ensure!(T::XcmReserveTransferFilter::contains(&value), Error::<T>::Filtered);
let (origin_location, assets) = value; let (origin_location, assets) = value;