Skip to content

Commit ffa9c5f

Browse files
authored
Limit Call size to 200 bytes (#598)
* xtokens reduce Call size * fmt * limit to 200 * xcm and authority * fmt * add sp_std Box * xtoken tests * add xcm size limit test * authority * Revert "add xcm size limit test" This reverts commit 4613a9a. * Revert "Revert "add xcm size limit test"" This reverts commit 951cb9b. * Revert "authority" This reverts commit 1832f55. * authority lower call size
1 parent 7f86adc commit ffa9c5f

File tree

6 files changed

+165
-108
lines changed

6 files changed

+165
-108
lines changed

authority/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub mod module {
267267
#[pallet::weight(T::WeightInfo::fast_track_scheduled_dispatch())]
268268
pub fn fast_track_scheduled_dispatch(
269269
origin: OriginFor<T>,
270-
initial_origin: T::PalletsOrigin,
270+
initial_origin: Box<T::PalletsOrigin>,
271271
task_id: ScheduleTaskIndex,
272272
when: DispatchTime<T::BlockNumber>,
273273
) -> DispatchResult {
@@ -285,15 +285,15 @@ pub mod module {
285285
T::Scheduler::reschedule_named((&initial_origin, task_id).encode(), when)
286286
.map_err(|_| Error::<T>::FailedToFastTrack)?;
287287

288-
Self::deposit_event(Event::FastTracked(initial_origin, task_id, dispatch_at));
288+
Self::deposit_event(Event::FastTracked(*initial_origin, task_id, dispatch_at));
289289
Ok(())
290290
}
291291

292292
/// Delay a scheduled dispatchable.
293293
#[pallet::weight(T::WeightInfo::delay_scheduled_dispatch())]
294294
pub fn delay_scheduled_dispatch(
295295
origin: OriginFor<T>,
296-
initial_origin: T::PalletsOrigin,
296+
initial_origin: Box<T::PalletsOrigin>,
297297
task_id: ScheduleTaskIndex,
298298
additional_delay: T::BlockNumber,
299299
) -> DispatchResult {
@@ -308,21 +308,21 @@ pub mod module {
308308
let now = frame_system::Pallet::<T>::block_number();
309309
let dispatch_at = now.saturating_add(additional_delay);
310310

311-
Self::deposit_event(Event::Delayed(initial_origin, task_id, dispatch_at));
311+
Self::deposit_event(Event::Delayed(*initial_origin, task_id, dispatch_at));
312312
Ok(())
313313
}
314314

315315
/// Cancel a scheduled dispatchable.
316316
#[pallet::weight(T::WeightInfo::cancel_scheduled_dispatch())]
317317
pub fn cancel_scheduled_dispatch(
318318
origin: OriginFor<T>,
319-
initial_origin: T::PalletsOrigin,
319+
initial_origin: Box<T::PalletsOrigin>,
320320
task_id: ScheduleTaskIndex,
321321
) -> DispatchResult {
322322
T::AuthorityConfig::check_cancel_schedule(origin, &initial_origin)?;
323323
T::Scheduler::cancel_named((&initial_origin, task_id).encode()).map_err(|_| Error::<T>::FailedToCancel)?;
324324

325-
Self::deposit_event(Event::Cancelled(initial_origin, task_id));
325+
Self::deposit_event(Event::Cancelled(*initial_origin, task_id));
326326
Ok(())
327327
}
328328
}

authority/src/tests.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn fast_track_scheduled_dispatch_work() {
207207
let pallets_origin = schedule_origin.caller().clone();
208208
assert_ok!(Authority::fast_track_scheduled_dispatch(
209209
Origin::root(),
210-
pallets_origin,
210+
Box::new(pallets_origin),
211211
0,
212212
DispatchTime::At(4),
213213
));
@@ -234,7 +234,7 @@ fn fast_track_scheduled_dispatch_work() {
234234

235235
assert_ok!(Authority::fast_track_scheduled_dispatch(
236236
Origin::root(),
237-
frame_system::RawOrigin::Root.into(),
237+
Box::new(frame_system::RawOrigin::Root.into()),
238238
1,
239239
DispatchTime::At(4),
240240
));
@@ -284,7 +284,7 @@ fn delay_scheduled_dispatch_work() {
284284
let pallets_origin = schedule_origin.caller().clone();
285285
assert_ok!(Authority::delay_scheduled_dispatch(
286286
Origin::root(),
287-
pallets_origin,
287+
Box::new(pallets_origin),
288288
0,
289289
4,
290290
));
@@ -311,7 +311,7 @@ fn delay_scheduled_dispatch_work() {
311311

312312
assert_ok!(Authority::delay_scheduled_dispatch(
313313
Origin::root(),
314-
frame_system::RawOrigin::Root.into(),
314+
Box::new(frame_system::RawOrigin::Root.into()),
315315
1,
316316
4,
317317
));
@@ -358,7 +358,11 @@ fn cancel_scheduled_dispatch_work() {
358358
};
359359

360360
let pallets_origin = schedule_origin.caller().clone();
361-
assert_ok!(Authority::cancel_scheduled_dispatch(Origin::root(), pallets_origin, 0));
361+
assert_ok!(Authority::cancel_scheduled_dispatch(
362+
Origin::root(),
363+
Box::new(pallets_origin),
364+
0
365+
));
362366
System::assert_last_event(mock::Event::Authority(Event::Cancelled(
363367
OriginCaller::Authority(DelayedOrigin {
364368
delay: 1,
@@ -381,7 +385,7 @@ fn cancel_scheduled_dispatch_work() {
381385

382386
assert_ok!(Authority::cancel_scheduled_dispatch(
383387
Origin::root(),
384-
frame_system::RawOrigin::Root.into(),
388+
Box::new(frame_system::RawOrigin::Root.into()),
385389
1
386390
));
387391
System::assert_last_event(mock::Event::Authority(Event::Cancelled(
@@ -390,3 +394,13 @@ fn cancel_scheduled_dispatch_work() {
390394
)));
391395
});
392396
}
397+
398+
#[test]
399+
fn call_size_limit() {
400+
assert!(
401+
core::mem::size_of::<authority::Call::<Runtime>>() <= 200,
402+
"size of Call is more than 200 bytes: some calls have too big arguments, use Box to \
403+
reduce the size of Call.
404+
If the limit is too strong, maybe consider increasing the limit",
405+
);
406+
}

xcm/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2018"
99

1010
[dependencies]
1111
codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false }
12+
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
1213

1314
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
1415
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
@@ -20,6 +21,7 @@ pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release
2021
default = ["std"]
2122
std = [
2223
"codec/std",
24+
"sp-std/std",
2325
"frame-support/std",
2426
"frame-system/std",
2527
"xcm/std",

xcm/src/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use frame_support::{pallet_prelude::*, traits::EnsureOrigin};
77
use frame_system::pallet_prelude::*;
8+
use sp_std::boxed::Box;
89

910
use xcm::v0::prelude::*;
1011

@@ -48,15 +49,19 @@ pub mod module {
4849
impl<T: Config> Pallet<T> {
4950
/// Send an XCM message as parachain sovereign.
5051
#[pallet::weight(100_000_000)]
51-
pub fn send_as_sovereign(origin: OriginFor<T>, dest: MultiLocation, message: Xcm<()>) -> DispatchResult {
52+
pub fn send_as_sovereign(
53+
origin: OriginFor<T>,
54+
dest: Box<MultiLocation>,
55+
message: Box<Xcm<()>>,
56+
) -> DispatchResult {
5257
let _ = T::SovereignOrigin::ensure_origin(origin)?;
53-
pallet_xcm::Pallet::<T>::send_xcm(MultiLocation::Null, dest.clone(), message.clone()).map_err(
58+
pallet_xcm::Pallet::<T>::send_xcm(MultiLocation::Null, *dest.clone(), *message.clone()).map_err(
5459
|e| match e {
5560
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
5661
_ => Error::<T>::SendFailure,
5762
},
5863
)?;
59-
Self::deposit_event(Event::Sent(MultiLocation::Null, dest, message));
64+
Self::deposit_event(Event::Sent(MultiLocation::Null, *dest, *message));
6065
Ok(())
6166
}
6267
}

xtokens/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ pub mod module {
148148
origin: OriginFor<T>,
149149
currency_id: T::CurrencyId,
150150
amount: T::Balance,
151-
dest: MultiLocation,
151+
dest: Box<MultiLocation>,
152152
dest_weight: Weight,
153153
) -> DispatchResult {
154154
let who = ensure_signed(origin)?;
155-
Self::do_transfer(who, currency_id, amount, dest, dest_weight)
155+
Self::do_transfer(who, currency_id, amount, *dest, dest_weight)
156156
}
157157

158158
/// Transfer `MultiAsset`.
@@ -171,12 +171,12 @@ pub mod module {
171171
#[transactional]
172172
pub fn transfer_multiasset(
173173
origin: OriginFor<T>,
174-
asset: MultiAsset,
175-
dest: MultiLocation,
174+
asset: Box<MultiAsset>,
175+
dest: Box<MultiLocation>,
176176
dest_weight: Weight,
177177
) -> DispatchResult {
178178
let who = ensure_signed(origin)?;
179-
Self::do_transfer_multiasset(who, asset, dest, dest_weight, true)
179+
Self::do_transfer_multiasset(who, *asset, *dest, dest_weight, true)
180180
}
181181
}
182182

0 commit comments

Comments
 (0)