Unverified Commit b17ab4f0 authored by thiolliere's avatar thiolliere Committed by GitHub
Browse files

companion: for call usage https://github.com/paritytech/substrate/pull/9418 (#3522)

* add test for call size

* fix box arg

* fix xcm variant length + increase limit a bit

* fix para sudo wrapper call length

* reorganize

* fmt

* fix tests

* update Substrate

Co-authored-by: parity-processbot <>
parent b0e58d19
Pipeline #151680 passed with stages
in 41 minutes and 49 seconds
This diff is collapsed.
......@@ -26,6 +26,7 @@ use runtime_parachains::{
paras::{self, ParaGenesisArgs},
ump, ParaLifecycle,
};
use sp_std::boxed::Box;
#[frame_support::pallet]
pub mod pallet {
......@@ -132,7 +133,7 @@ pub mod pallet {
pub fn sudo_queue_downward_xcm(
origin: OriginFor<T>,
id: ParaId,
xcm: xcm::opaque::VersionedXcm,
xcm: Box<xcm::opaque::VersionedXcm>,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(<paras::Pallet<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
......
......@@ -168,3 +168,13 @@ fn era_payout_should_give_sensible_results() {
assert_eq!(era_payout(75, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (10, 0));
assert_eq!(era_payout(80, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (6, 4));
}
#[test]
fn call_size() {
assert!(
core::mem::size_of::<Call>() <= 230,
"size of Call is more than 230 bytes: some calls have too big arguments, use Box to reduce \
the size of Call.
If the limit is too strong, maybe consider increase the limit to 300.",
);
}
......@@ -1683,3 +1683,18 @@ mod test_fees {
assert!(active > target_voters, "we need to reevaluate the weight of the election system");
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn call_size() {
assert!(
core::mem::size_of::<Call>() <= 230,
"size of Call is more than 230 bytes: some calls have too big arguments, use Box to \
reduce the size of Call.
If the limit is too strong, maybe consider increase the limit",
);
}
}
......@@ -39,3 +39,13 @@ fn sample_size_is_sensible() {
BlockWeights::get().max_block
);
}
#[test]
fn call_size() {
assert!(
core::mem::size_of::<Call>() <= 230,
"size of Call is more than 230 bytes: some calls have too big arguments, use Box to reduce \
the size of Call.
If the limit is too strong, maybe consider increase the limit to 300.",
);
}
......@@ -78,7 +78,7 @@ macro_rules! construct_runtime_prelude {
let crate::signer::Signer { account, pair, .. } = signer;
let local_call = EPMCall::<Runtime>::submit(raw_solution, witness);
let local_call = EPMCall::<Runtime>::submit(Box::new(raw_solution), witness);
let call: Call = <EPMCall<Runtime> as std::convert::TryInto<Call>>::try_into(local_call)
.expect("election provider pallet must exist in the runtime, thus \
inner call can be converted, qed."
......
......@@ -114,15 +114,19 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(100_000_000)]
pub fn send(origin: OriginFor<T>, dest: MultiLocation, message: Xcm<()>) -> DispatchResult {
pub fn send(
origin: OriginFor<T>,
dest: Box<MultiLocation>,
message: Box<Xcm<()>>,
) -> DispatchResult {
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
Self::send_xcm(origin_location.clone(), dest.clone(), message.clone()).map_err(
Self::send_xcm(origin_location.clone(), *dest.clone(), *message.clone()).map_err(
|e| match e {
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
},
)?;
Self::deposit_event(Event::Sent(origin_location, dest, message));
Self::deposit_event(Event::Sent(origin_location, *dest, *message));
Ok(())
}
......@@ -144,7 +148,7 @@ pub mod pallet {
assets: assets.clone(),
effects: sp_std::vec![ InitiateTeleport {
assets: Wild(All),
dest: dest.clone(),
dest: *dest.clone(),
effects: sp_std::vec![],
} ]
};
......@@ -152,8 +156,8 @@ pub mod pallet {
})]
pub fn teleport_assets(
origin: OriginFor<T>,
dest: MultiLocation,
beneficiary: MultiLocation,
dest: Box<MultiLocation>,
beneficiary: Box<MultiLocation>,
assets: MultiAssets,
fee_asset_item: u32,
dest_weight: Weight,
......@@ -176,7 +180,7 @@ pub mod pallet {
assets,
effects: vec![InitiateTeleport {
assets: Wild(All),
dest,
dest: *dest,
effects: vec![
BuyExecution {
fees,
......@@ -187,7 +191,7 @@ pub mod pallet {
orders: vec![],
instructions: vec![],
},
DepositAsset { assets: Wild(All), max_assets, beneficiary },
DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary },
],
}],
};
......@@ -216,15 +220,15 @@ pub mod pallet {
#[pallet::weight({
let mut message = Xcm::TransferReserveAsset {
assets: assets.clone(),
dest: dest.clone(),
dest: *dest.clone(),
effects: sp_std::vec![],
};
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000 + w)
})]
pub fn reserve_transfer_assets(
origin: OriginFor<T>,
dest: MultiLocation,
beneficiary: MultiLocation,
dest: Box<MultiLocation>,
beneficiary: Box<MultiLocation>,
assets: MultiAssets,
fee_asset_item: u32,
dest_weight: Weight,
......@@ -245,7 +249,7 @@ pub mod pallet {
let assets = assets.into();
let mut message = Xcm::TransferReserveAsset {
assets,
dest,
dest: *dest,
effects: vec![
BuyExecution {
fees,
......@@ -256,7 +260,7 @@ pub mod pallet {
orders: vec![],
instructions: vec![],
},
DepositAsset { assets: Wild(All), max_assets, beneficiary },
DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary },
],
};
let weight =
......
......@@ -46,7 +46,11 @@ fn send_works() {
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: sender.clone() },
],
};
assert_ok!(XcmPallet::send(Origin::signed(ALICE), RelayLocation::get(), message.clone()));
assert_ok!(XcmPallet::send(
Origin::signed(ALICE),
Box::new(RelayLocation::get()),
Box::new(message.clone())
));
assert_eq!(
sent_xcm(),
vec![(
......@@ -83,7 +87,7 @@ fn send_fails_when_xcm_router_blocks() {
assert_noop!(
XcmPallet::send(
Origin::signed(ALICE),
X8(
Box::new(X8(
Junction::Parent,
Junction::Parent,
Junction::Parent,
......@@ -92,8 +96,8 @@ fn send_fails_when_xcm_router_blocks() {
Junction::Parent,
Junction::Parent,
Junction::Parent
),
message.clone()
)),
Box::new(message.clone())
),
crate::Error::<Test>::SendFailure
);
......@@ -113,8 +117,8 @@ fn teleport_assets_works() {
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
assert_ok!(XcmPallet::teleport_assets(
Origin::signed(ALICE),
RelayLocation::get(),
X1(AccountId32 { network: Any, id: BOB.into() }),
Box::new(RelayLocation::get()),
Box::new(X1(AccountId32 { network: Any, id: BOB.into() })),
(Here, SEND_AMOUNT).into(),
0,
weight,
......@@ -142,8 +146,8 @@ fn reserve_transfer_assets_works() {
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
assert_ok!(XcmPallet::reserve_transfer_assets(
Origin::signed(ALICE),
Parachain(PARA_ID).into(),
dest.clone(),
Box::new(Parachain(PARA_ID).into()),
Box::new(dest.clone()),
(Here, SEND_AMOUNT).into(),
0,
weight
......
......@@ -190,8 +190,8 @@ mod tests {
Relay::execute_with(|| {
assert_ok!(RelayChainPalletXcm::reserve_transfer_assets(
relay_chain::Origin::signed(ALICE),
X1(Parachain(1)),
X1(AccountId32 { network: Any, id: ALICE.into() }),
Box::new(X1(Parachain(1))),
Box::new(X1(AccountId32 { network: Any, id: ALICE.into() })),
(Here, 123).into(),
0,
3,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment