Skip to content

Commit

Permalink
Limit max call size of Rialto/Millau runtimes (paritytech#1187)
Browse files Browse the repository at this point in the history
* max call size <= 230 bytes

* fix benchmarks
  • Loading branch information
svyatonik authored and serban300 committed Apr 10, 2024
1 parent 6058585 commit c436dcd
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 141 deletions.
4 changes: 1 addition & 3 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,7 @@ mod tests {

#[test]
fn call_size() {
// pallets that are (to be) used by polkadot runtime
const MAX_CALL_SIZE: usize = 230; // value from polkadot-runtime tests
assert!(core::mem::size_of::<pallet_bridge_grandpa::Call<Runtime>>() <= MAX_CALL_SIZE);
assert!(core::mem::size_of::<pallet_bridge_messages::Call<Runtime>>() <= MAX_CALL_SIZE);
assert!(core::mem::size_of::<Call>() <= MAX_CALL_SIZE);
}
}
4 changes: 1 addition & 3 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,7 @@ mod tests {

#[test]
fn call_size() {
// pallets that are (to be) used by polkadot runtime
const MAX_CALL_SIZE: usize = 230; // value from polkadot-runtime tests
assert!(core::mem::size_of::<pallet_bridge_grandpa::Call<Runtime>>() <= MAX_CALL_SIZE);
assert!(core::mem::size_of::<pallet_bridge_messages::Call<Runtime>>() <= MAX_CALL_SIZE);
assert!(core::mem::size_of::<Call>() <= MAX_CALL_SIZE);
}
}
10 changes: 5 additions & 5 deletions bridges/modules/ethereum/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ benchmarks_instance_pallet! {
header
},
);
}: import_unsigned_header(RawOrigin::None, header, None)
}: import_unsigned_header(RawOrigin::None, Box::new(header), None)
verify {
let storage = BridgeStorage::<T, I>::new();
assert_eq!(storage.best_block().0.number, 1);
Expand Down Expand Up @@ -91,7 +91,7 @@ benchmarks_instance_pallet! {
// Need to make sure that the header we're going to import hasn't been inserted
// into storage already
let header = HeaderBuilder::with_parent(&last_header).sign_by(&last_authority);
}: import_unsigned_header(RawOrigin::None, header, None)
}: import_unsigned_header(RawOrigin::None, Box::new(header), None)
verify {
let storage = BridgeStorage::<T, I>::new();
assert_eq!(storage.best_block().0.number, (num_blocks + 1) as u64);
Expand Down Expand Up @@ -132,7 +132,7 @@ benchmarks_instance_pallet! {
// Need to make sure that the header we're going to import hasn't been inserted
// into storage already
let header = HeaderBuilder::with_parent(&last_header).sign_by(&last_authority);
}: import_unsigned_header(RawOrigin::None, header, None)
}: import_unsigned_header(RawOrigin::None, Box::new(header), None)
verify {
let storage = BridgeStorage::<T, I>::new();
assert_eq!(storage.best_block().0.number, (num_blocks + 1) as u64);
Expand Down Expand Up @@ -167,7 +167,7 @@ benchmarks_instance_pallet! {
}

let header = HeaderBuilder::with_parent(&parent).sign_by_set(&validators);
}: import_unsigned_header(RawOrigin::None, header, None)
}: import_unsigned_header(RawOrigin::None, Box::new(header), None)
verify {
let storage = BridgeStorage::<T, I>::new();
let max_pruned: u64 = (n - 1) as _;
Expand Down Expand Up @@ -209,7 +209,7 @@ benchmarks_instance_pallet! {
header
},
);
}: import_unsigned_header(RawOrigin::None, header, Some(receipts))
}: import_unsigned_header(RawOrigin::None, Box::new(header), Some(receipts))
verify {
let storage = BridgeStorage::<T, I>::new();
assert_eq!(storage.best_block().0.number, 2);
Expand Down
6 changes: 3 additions & 3 deletions bridges/modules/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use bp_eth_poa::{
use codec::{Decode, Encode};
use frame_support::traits::Get;
use sp_runtime::RuntimeDebug;
use sp_std::{cmp::Ord, collections::btree_map::BTreeMap, prelude::*};
use sp_std::{boxed::Box, cmp::Ord, collections::btree_map::BTreeMap, prelude::*};

pub use validators::{ValidatorsConfiguration, ValidatorsSource};

Expand Down Expand Up @@ -406,7 +406,7 @@ pub mod pallet {
#[pallet::weight(0)] // TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
pub fn import_unsigned_header(
origin: OriginFor<T>,
header: AuraHeader,
header: Box<AuraHeader>,
receipts: Option<Vec<Receipt>>,
) -> DispatchResult {
frame_system::ensure_none(origin)?;
Expand All @@ -417,7 +417,7 @@ pub mod pallet {
&T::AuraConfiguration::get(),
&T::ValidatorsConfiguration::get(),
None,
header,
*header,
&T::ChainTime::default(),
receipts,
)
Expand Down
35 changes: 21 additions & 14 deletions bridges/modules/token-swap/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

use crate::{
swap_account_id, target_account_at_this_chain, BridgedAccountIdOf, BridgedAccountPublicOf,
BridgedAccountSignatureOf, BridgedBalanceOf, Call, Pallet, ThisChainBalance, TokenSwapOf,
BridgedAccountSignatureOf, BridgedBalanceOf, Call, Pallet, ThisChainBalance,
TokenSwapCreationOf, TokenSwapOf,
};

use bp_token_swap::{TokenSwap, TokenSwapState, TokenSwapType};
use bp_token_swap::{TokenSwap, TokenSwapCreation, TokenSwapState, TokenSwapType};
use codec::Encode;
use frame_benchmarking::{account, benchmarks_instance_pallet};
use frame_support::{traits::Currency, Parameter};
Expand Down Expand Up @@ -62,21 +63,11 @@ benchmarks_instance_pallet! {

let sender = funded_account::<T, I>("source_account_at_this_chain", 0);
let swap: TokenSwapOf<T, I> = test_swap::<T, I>(sender.clone(), true);
let target_public_at_bridged_chain = target_public_at_bridged_chain::<T, I>();
let swap_delivery_and_dispatch_fee = swap_delivery_and_dispatch_fee::<T, I>();
let bridged_chain_spec_version = 0;
let bridged_currency_transfer = Vec::new();
let bridged_currency_transfer_weight = 0;
let bridged_currency_transfer_signature = bridged_currency_transfer_signature::<T, I>();
let swap_creation: TokenSwapCreationOf<T, I> = test_swap_creation::<T, I>();
}: create_swap(
RawOrigin::Signed(sender.clone()),
swap,
target_public_at_bridged_chain,
swap_delivery_and_dispatch_fee,
bridged_chain_spec_version,
bridged_currency_transfer,
bridged_currency_transfer_weight,
bridged_currency_transfer_signature
Box::new(swap_creation)
)
verify {
assert!(crate::PendingSwaps::<T, I>::contains_key(test_swap_hash::<T, I>(sender, true)));
Expand Down Expand Up @@ -144,6 +135,22 @@ fn test_swap_hash<T: Config<I>, I: 'static>(sender: T::AccountId, is_create: boo
test_swap::<T, I>(sender, is_create).using_encoded(blake2_256).into()
}

/// Returns test token swap creation params.
fn test_swap_creation<T: Config<I>, I: 'static>() -> TokenSwapCreationOf<T, I>
where
BridgedAccountPublicOf<T, I>: Default,
BridgedAccountSignatureOf<T, I>: Default,
{
TokenSwapCreation {
target_public_at_bridged_chain: target_public_at_bridged_chain::<T, I>(),
swap_delivery_and_dispatch_fee: swap_delivery_and_dispatch_fee::<T, I>(),
bridged_chain_spec_version: 0,
bridged_currency_transfer: Vec::new(),
bridged_currency_transfer_weight: 0,
bridged_currency_transfer_signature: bridged_currency_transfer_signature::<T, I>(),
}
}

/// Account that has some balance.
fn funded_account<T: Config<I>, I: 'static>(name: &'static str, index: u32) -> T::AccountId {
let account: T::AccountId = account(name, index, SEED);
Expand Down
Loading

0 comments on commit c436dcd

Please sign in to comment.