Skip to content

Limit Call size to 200 bytes #598

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

Merged
merged 13 commits into from
Sep 2, 2021
10 changes: 10 additions & 0 deletions authority/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,13 @@ fn cancel_scheduled_dispatch_work() {
)));
});
}

#[test]
fn call_size_limit() {
assert!(
core::mem::size_of::<authority::Call::<Runtime>>() <= 200,
"size of Call is more than 200 bytes: some calls have too big arguments, use Box to \
reduce the size of Call.
If the limit is too strong, maybe consider increasing the limit",
);
Comment on lines +397 to +405
Copy link
Contributor Author

@ferrell-code ferrell-code Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests passes, yet in karura runtime the Call size for orml_authority is printed as 608 bytes, this test when printed says call size of 56 bytes. That doesn't really make sense to me

Edit: Nvm, I think I figured it out it probably is because karura sets something different in the runtime than the mock 👍

}
6 changes: 3 additions & 3 deletions xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ pub mod module {
impl<T: Config> Pallet<T> {
/// Send an XCM message as parachain sovereign.
#[pallet::weight(100_000_000)]
pub fn send_as_sovereign(origin: OriginFor<T>, dest: MultiLocation, message: Xcm<()>) -> DispatchResult {
pub fn send_as_sovereign(origin: OriginFor<T>, dest: Box<MultiLocation>, message: Box<Xcm<()>>) -> DispatchResult {
let _ = T::SovereignOrigin::ensure_origin(origin)?;
pallet_xcm::Pallet::<T>::send_xcm(MultiLocation::Null, dest.clone(), message.clone()).map_err(
pallet_xcm::Pallet::<T>::send_xcm(MultiLocation::Null, *dest.clone(), *message.clone()).map_err(
|e| match e {
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
},
)?;
Self::deposit_event(Event::Sent(MultiLocation::Null, dest, message));
Self::deposit_event(Event::Sent(MultiLocation::Null, *dest, *message));
Ok(())
}
}
Expand Down
10 changes: 5 additions & 5 deletions xtokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ pub mod module {
origin: OriginFor<T>,
currency_id: T::CurrencyId,
amount: T::Balance,
dest: MultiLocation,
dest: Box<MultiLocation>,
dest_weight: Weight,
) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_transfer(who, currency_id, amount, dest, dest_weight)
Self::do_transfer(who, currency_id, amount, *dest, dest_weight)
}

/// Transfer `MultiAsset`.
Expand All @@ -171,12 +171,12 @@ pub mod module {
#[transactional]
pub fn transfer_multiasset(
origin: OriginFor<T>,
asset: MultiAsset,
dest: MultiLocation,
asset: Box<MultiAsset>,
dest: Box<MultiLocation>,
dest_weight: Weight,
) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_transfer_multiasset(who, asset, dest, dest_weight, true)
Self::do_transfer_multiasset(who, *asset, *dest, dest_weight, true)
}
}

Expand Down
192 changes: 110 additions & 82 deletions xtokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ fn send_relay_chain_asset_to_relay_chain() {
Some(ALICE).into(),
CurrencyId::R,
500,
(
Parent,
Junction::AccountId32 {
network: NetworkId::Kusama,
id: BOB.into(),
},
)
.into(),
Box::new(
(
Parent,
Junction::AccountId32 {
network: NetworkId::Kusama,
id: BOB.into(),
},
)
.into()
),
30,
));
assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500);
Expand All @@ -77,15 +79,17 @@ fn cannot_lost_fund_on_send_failed() {
Some(ALICE).into(),
CurrencyId::A,
500,
(
Parent,
Parachain(100),
Junction::AccountId32 {
network: NetworkId::Kusama,
id: BOB.into(),
},
)
.into(),
Box::new(
(
Parent,
Parachain(100),
Junction::AccountId32 {
network: NetworkId::Kusama,
id: BOB.into(),
},
)
.into()
),
30,
),
Error::<para::Runtime>::XcmExecutionFailed
Expand All @@ -108,15 +112,17 @@ fn send_relay_chain_asset_to_sibling() {
Some(ALICE).into(),
CurrencyId::R,
500,
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into(),
Box::new(
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into()
),
30,
));
assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500);
Expand Down Expand Up @@ -149,15 +155,17 @@ fn send_sibling_asset_to_reserve_sibling() {
Some(ALICE).into(),
CurrencyId::B,
500,
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into(),
Box::new(
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into()
),
30,
));

Expand Down Expand Up @@ -187,15 +195,17 @@ fn send_sibling_asset_to_non_reserve_sibling() {
Some(ALICE).into(),
CurrencyId::B,
500,
(
Parent,
Parachain(3),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into(),
Box::new(
(
Parent,
Parachain(3),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into()
),
30
));
assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 500);
Expand Down Expand Up @@ -223,15 +233,17 @@ fn send_self_parachain_asset_to_sibling() {
Some(ALICE).into(),
CurrencyId::A,
500,
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into(),
Box::new(
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
},
)
.into()
),
30,
));

Expand All @@ -252,19 +264,21 @@ fn transfer_no_reserve_assets_fails() {
assert_noop!(
ParaXTokens::transfer_multiasset(
Some(ALICE).into(),
MultiAsset::ConcreteFungible {
Box::new(MultiAsset::ConcreteFungible {
id: GeneralKey("B".into()).into(),
amount: 100
},
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into()
}
)
.into(),
}),
Box::new(
(
Parent,
Parachain(2),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into()
}
)
.into()
),
50,
),
Error::<para::Runtime>::AssetHasNoReserve
Expand All @@ -280,19 +294,21 @@ fn transfer_to_self_chain_fails() {
assert_noop!(
ParaXTokens::transfer_multiasset(
Some(ALICE).into(),
MultiAsset::ConcreteFungible {
Box::new(MultiAsset::ConcreteFungible {
id: (Parent, Parachain(1), GeneralKey("A".into())).into(),
amount: 100
},
(
Parent,
Parachain(1),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into()
}
)
.into(),
}),
Box::new(
(
Parent,
Parachain(1),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into()
}
)
.into()
),
50,
),
Error::<para::Runtime>::NotCrossChainTransfer
Expand All @@ -308,15 +324,17 @@ fn transfer_to_invalid_dest_fails() {
assert_noop!(
ParaXTokens::transfer_multiasset(
Some(ALICE).into(),
MultiAsset::ConcreteFungible {
Box::new(MultiAsset::ConcreteFungible {
id: (Parent, Parachain(1), GeneralKey("A".into())).into(),
amount: 100,
},
(Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into()
})
.into(),
}),
Box::new(
(Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into()
})
.into()
),
50,
),
Error::<para::Runtime>::InvalidDest
Expand Down Expand Up @@ -407,3 +425,13 @@ fn send_as_sovereign_fails_if_bad_origin() {
);
});
}

#[test]
fn call_size_limit() {
assert!(
core::mem::size_of::<crate::Call::<crate::tests::para::Runtime>>() <= 200,
"size of Call is more than 200 bytes: some calls have too big arguments, use Box to \
reduce the size of Call.
If the limit is too strong, maybe consider increasing the limit",
);
}