Skip to content

Commit

Permalink
remove redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
grishasobol committed Dec 21, 2023
1 parent bd9e6e9 commit 8d925ce
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 147 deletions.
23 changes: 1 addition & 22 deletions common/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use gear_core::{
use gear_wasm_instrument::parity_wasm::{self, elements::*};
use sp_io::hashing::blake2_256;
use sp_runtime::traits::Zero;
use sp_std::borrow::ToOwned;

pub fn account<AccountId: Origin>(name: &'static str, index: u32, seed: u32) -> AccountId {
let entropy = (name, index, seed).using_encoded(blake2_256);
Expand Down Expand Up @@ -61,13 +60,6 @@ pub fn create_module(num_pages: WasmPage) -> parity_wasm::elements::Module {
])
}

pub fn generate_wasm(num_pages: WasmPage) -> Result<Vec<u8>, &'static str> {
let module = create_module(num_pages);
let code = parity_wasm::serialize(module).map_err(|_| "Failed to serialize module")?;

Ok(code)
}

// A wasm module that allocates `$num_pages` in `handle` function:
// (module
// (import "env" "memory" (memory 1))
Expand All @@ -80,7 +72,7 @@ pub fn generate_wasm(num_pages: WasmPage) -> Result<Vec<u8>, &'static str> {
// (local.set $result (call $alloc (i32.const $num_pages)))
// )
// )
pub fn generate_wasm2(num_pages: WasmPage) -> Result<Vec<u8>, &'static str> {
pub fn generate_wasm(num_pages: WasmPage) -> Result<Vec<u8>, &'static str> {
let module = parity_wasm::elements::Module::new(vec![
Section::Type(TypeSection::with_types(vec![
Type::Function(FunctionType::new(
Expand Down Expand Up @@ -123,19 +115,6 @@ pub fn generate_wasm2(num_pages: WasmPage) -> Result<Vec<u8>, &'static str> {
Ok(code)
}

pub fn generate_wasm3(payload: Vec<u8>) -> Result<Vec<u8>, &'static str> {
let mut module = create_module(1.into());
module
.insert_section(Section::Custom(CustomSection::new(
"zeroed_section".to_owned(),
payload,
)))
.unwrap();
let code = parity_wasm::serialize(module).map_err(|_| "Failed to serialize module")?;

Ok(code)
}

pub fn set_program<
ProgramStorage: super::ProgramStorage<BlockNumber = BlockNumber>,
BlockNumber: Zero + Copy + Saturating,
Expand Down
46 changes: 8 additions & 38 deletions pallets/gear/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ benchmarks! {
CurrencyOf::<T>::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into());
let program_id = benchmarking::account::<T::AccountId>("program", 0, 100);
CurrencyOf::<T>::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into());
let code = benchmarking::generate_wasm2(16.into()).unwrap();
let code = benchmarking::generate_wasm(16.into()).unwrap();
benchmarking::set_program::<ProgramStorageOf::<T>, _>(program_id.clone().cast(), code, 1.into());
let original_message_id = benchmarking::account::<T::AccountId>("message", 0, 100).cast();
let gas_limit = 50000;
Expand Down Expand Up @@ -499,7 +499,7 @@ benchmarks! {
let caller = benchmarking::account("caller", 0, 0);
CurrencyOf::<T>::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into());
let minimum_balance = CurrencyOf::<T>::minimum_balance();
let code = benchmarking::generate_wasm2(16.into()).unwrap();
let code = benchmarking::generate_wasm(16.into()).unwrap();
let salt = vec![];
let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt);
Gear::<T>::upload_program(RawOrigin::Signed(caller.clone()).into(), code, salt, b"init_payload".to_vec(), 10_000_000_000, 0u32.into(), false).expect("submit program failed");
Expand All @@ -519,7 +519,7 @@ benchmarks! {
resume_session_init {
let caller = benchmarking::account("caller", 0, 0);
CurrencyOf::<T>::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into());
let code = benchmarking::generate_wasm2(16.into()).unwrap();
let code = benchmarking::generate_wasm(16.into()).unwrap();
let salt = vec![];
let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt);
Gear::<T>::upload_program(RawOrigin::Signed(caller.clone()).into(), code, salt, b"init_payload".to_vec(), 10_000_000_000, 0u32.into(), false).expect("submit program failed");
Expand All @@ -544,7 +544,7 @@ benchmarks! {
let c in 0 .. 16 * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32;
let caller = benchmarking::account("caller", 0, 0);
CurrencyOf::<T>::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into());
let code = benchmarking::generate_wasm2(16.into()).unwrap();
let code = benchmarking::generate_wasm(16.into()).unwrap();
let salt = vec![];
let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt);
Gear::<T>::upload_program(RawOrigin::Signed(caller.clone()).into(), code, salt, b"init_payload".to_vec(), 10_000_000_000, 0u32.into(), false,).expect("submit program failed");
Expand Down Expand Up @@ -580,7 +580,7 @@ benchmarks! {
let c in 0 .. (MAX_PAGES - 1) * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32;
let caller = benchmarking::account("caller", 0, 0);
CurrencyOf::<T>::deposit_creating(&caller, 400_000_000_000_000u128.unique_saturated_into());
let code = benchmarking::generate_wasm2(0.into()).unwrap();
let code = benchmarking::generate_wasm(0.into()).unwrap();
let salt = vec![];
let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt);
Gear::<T>::upload_program(RawOrigin::Signed(caller.clone()).into(), code, salt, b"init_payload".to_vec(), 10_000_000_000, 0u32.into(), false,).expect("submit program failed");
Expand Down Expand Up @@ -696,7 +696,7 @@ benchmarks! {
CurrencyOf::<T>::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into());
let minimum_balance = CurrencyOf::<T>::minimum_balance();
let program_id = benchmarking::account::<T::AccountId>("program", 0, 100).cast();
let code = benchmarking::generate_wasm2(16.into()).unwrap();
let code = benchmarking::generate_wasm(16.into()).unwrap();
benchmarking::set_program::<ProgramStorageOf::<T>, _>(program_id, code, 1.into());
let payload = vec![0_u8; p as usize];

Expand All @@ -713,7 +713,7 @@ benchmarks! {
let minimum_balance = CurrencyOf::<T>::minimum_balance();
let program_id = benchmarking::account::<T::AccountId>("program", 0, 100);
CurrencyOf::<T>::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into());
let code = benchmarking::generate_wasm2(16.into()).unwrap();
let code = benchmarking::generate_wasm(16.into()).unwrap();
benchmarking::set_program::<ProgramStorageOf::<T>, _>(program_id.clone().cast(), code, 1.into());
let original_message_id = benchmarking::account::<T::AccountId>("message", 0, 100).cast();
let gas_limit = 50000;
Expand All @@ -739,36 +739,6 @@ benchmarks! {
assert!(MailboxOf::<T>::is_empty(&caller))
}

initial_allocation {
let q in 1 .. MAX_PAGES;
let q = q as u16;
let caller: T::AccountId = benchmarking::account("caller", 0, 0);
CurrencyOf::<T>::deposit_creating(&caller, (1u128 << 60).unique_saturated_into());
let code = benchmarking::generate_wasm(q.into()).unwrap();
let salt = vec![255u8; 32];
}: {
let _ = Gear::<T>::upload_program(RawOrigin::Signed(caller).into(), code, salt, vec![], 100_000_000u64, 0u32.into(), false,);
process_queue::<T>();
}
verify {
assert!(matches!(QueueOf::<T>::dequeue(), Ok(None)));
}

alloc_in_handle {
let q in 0 .. MAX_PAGES;
let q = q as u16;
let caller: T::AccountId = benchmarking::account("caller", 0, 0);
CurrencyOf::<T>::deposit_creating(&caller, (1_u128 << 60).unique_saturated_into());
let code = benchmarking::generate_wasm2(q.into()).unwrap();
let salt = vec![255u8; 32];
}: {
let _ = Gear::<T>::upload_program(RawOrigin::Signed(caller).into(), code, salt, vec![], 100_000_000u64, 0u32.into(), false,);
process_queue::<T>();
}
verify {
assert!(matches!(QueueOf::<T>::dequeue(), Ok(None)));
}

// This benchmarks the additional weight that is charged when a program is executed the
// first time after a new schedule was deployed: For every new schedule a program needs
// to re-run the instrumentation once.
Expand Down Expand Up @@ -2857,7 +2827,7 @@ benchmarks! {
tasks_pause_program {
let c in 0 .. (MAX_PAGES - 1) * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32;

let code = benchmarking::generate_wasm2(0.into()).unwrap();
let code = benchmarking::generate_wasm(0.into()).unwrap();
let program_id = tasks::pause_program_prepare::<T>(c, code);

let mut ext_manager = ExtManager::<T>::default();
Expand Down
2 changes: 1 addition & 1 deletion pallets/gear/src/benchmarking/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
{
let caller = benchmarking::account("caller", 0, 0);
CurrencyOf::<T>::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into());
let code = benchmarking::generate_wasm2(16.into()).unwrap();
let code = benchmarking::generate_wasm(16.into()).unwrap();
let salt = vec![];
let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt);
Gear::<T>::upload_program(
Expand Down
44 changes: 1 addition & 43 deletions pallets/gear/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8d925ce

Please sign in to comment.