diff --git a/pallet/src/benchmarking.rs b/pallet/src/benchmarking.rs index 3cd616c..b0ef5ad 100644 --- a/pallet/src/benchmarking.rs +++ b/pallet/src/benchmarking.rs @@ -1,12 +1,10 @@ //! Benchmarking setup for pallet-move. use frame_benchmarking::*; -use frame_support::traits::Currency; use frame_system::{Config as SysConfig, RawOrigin}; use move_core_types::account_address::AccountAddress; use move_vm_backend::types::MAX_GAS_AMOUNT; pub use sp_core::{crypto::Ss58Codec, sr25519::Public}; -use sp_runtime::traits::Zero; use sp_std::{vec, vec::Vec}; #[cfg(test)] @@ -26,42 +24,84 @@ benchmarks! { } execute { - let n in 0 .. 3; + let n in 0 .. 7; - let bob_32: T::AccountId = Public::from_ss58check(BOB_ADDR).unwrap().into(); - let bob_mv = Pallet::::to_move_address(&bob_32).unwrap(); - let _ = T::Currency::deposit_creating(&bob_32, BalanceOf::::from(u128::MAX)); - let alice_32: T::AccountId = Public::from_ss58check(ALICE_ADDR).unwrap().into(); - let alice_mv = Pallet::::to_move_address(&alice_32).unwrap(); - let _ = T::Currency::deposit_creating(&alice_32, BalanceOf::::from(u128::MAX)); - let dave_32: T::AccountId = Public::from_ss58check(DAVE_ADDR).unwrap().into(); - let dave_mv = Pallet::::to_move_address(&dave_32).unwrap(); - let _ = T::Currency::deposit_creating(&dave_32, BalanceOf::::from(u128::MAX)); - let eve_32: T::AccountId = Public::from_ss58check(EVE_ADDR).unwrap().into(); - let eve_mv = Pallet::::to_move_address(&eve_32).unwrap(); - let _ = T::Currency::deposit_creating(&eve_32, BalanceOf::::from(u128::MAX)); - - // Prepare car-wash-example move-project on mockup. + let (bob_32, bob_mv) = account_address::(BOB_ADDR); + let (alice_32, alice_mv) = account_address::(ALICE_ADDR); + let (dave_32, dave_mv) = account_address::(DAVE_ADDR); + let (eve_32, eve_mv) = account_address::(EVE_ADDR); + + // Our benchmark plan (each is a test scenario with different parameters). + let script_bcs = [ + car_wash_initial_coin_miniting(&bob_mv), + multiple_signers_init_module(&bob_mv), + car_wash_register_new_user(&alice_mv), + car_wash_buy_coin(&alice_mv, 1), + car_wash_wash_car(&alice_mv), + multiple_signers_rent_apartment(&alice_mv, &dave_mv, &eve_mv, 1), + multiple_signers_rent_apartment(&alice_mv, &dave_mv, &eve_mv, 1), + multiple_signers_rent_apartment(&alice_mv, &dave_mv, &eve_mv, 1), + ]; + // Sequence of account-IDs who will execute each extrinsic call. + let accounts = [ + bob_32.clone(), + bob_32.clone(), + alice_32.clone(), + alice_32.clone(), + alice_32.clone(), + alice_32.clone(), + dave_32, + eve_32, + ]; + // Needed gas amounts for each script, estimated by smove. + let gas = [21, 21, 15, 31, 18, 66, 66, 66]; + + // Now we have to prepare each script execution with a proper setup. + // Publish both modules always. Pallet::::publish_module( RawOrigin::Signed(bob_32.clone()).into(), car_wash_example_module(), MAX_GAS_AMOUNT ).unwrap(); - // Prepare multiple-signers move-project on mockup. Pallet::::publish_module( RawOrigin::Signed(bob_32.clone()).into(), multiple_signers_module(), MAX_GAS_AMOUNT ).unwrap(); - let accounts = [bob_32.clone(), bob_32, alice_32.clone(), alice_32]; - let script_bcs = [ - car_wash_initial_coin_miniting(&bob_mv), - multiple_signers_init_module(&bob_mv), - car_wash_register_new_user(&alice_mv), - multiple_signers_rent_apartment(&alice_mv, &dave_mv, &eve_mv, 1), - ]; - let gas = [21, 21, 15, 66]; + // Now prepare individual situations for proper script sequences. + if n > 1 && n < 5 { + Pallet::::execute( + RawOrigin::Signed(bob_32.clone()).into(), + car_wash_initial_coin_miniting(&bob_mv), + MAX_GAS_AMOUNT, + LIMIT.into() + ).unwrap(); + if n > 2 { + Pallet::::execute( + RawOrigin::Signed(alice_32.clone()).into(), + car_wash_register_new_user(&alice_mv), + MAX_GAS_AMOUNT, + LIMIT.into() + ).unwrap(); + } + if n > 3 { + Pallet::::execute( + RawOrigin::Signed(alice_32.clone()).into(), + car_wash_buy_coin(&alice_mv, 1), + MAX_GAS_AMOUNT, + LIMIT.into() + ).unwrap(); + } + } + if n > 4 { + Pallet::::execute( + RawOrigin::Signed(bob_32.clone()).into(), + multiple_signers_init_module(&bob_mv), + MAX_GAS_AMOUNT, + LIMIT.into() + ).unwrap(); + } }: _(RawOrigin::Signed(accounts[n as usize].clone()), script_bcs[n as usize].clone(), gas[n as usize], BalanceOf::::from(LIMIT)) @@ -95,10 +135,46 @@ benchmarks! { #[cfg(test)] impl_benchmark_test_suite!( Pallet, - crate::mock::ExtBuilder::default().build(), + crate::mock::ExtBuilder::default() + .with_balances(vec![ + ( + crate::benchmarking::account::(crate::benchmarking::BOB_ADDR), + u128::MAX + ), + ( + crate::benchmarking::account::(crate::benchmarking::ALICE_ADDR), + u128::MAX + ), + ( + crate::benchmarking::account::(crate::benchmarking::DAVE_ADDR), + u128::MAX + ), + ( + crate::benchmarking::account::(crate::benchmarking::EVE_ADDR), + u128::MAX + ), + ]) + .build(), crate::mock::Test ); +#[cfg(test)] +fn account(name: &str) -> T::AccountId +where + T::AccountId: From, +{ + Public::from_ss58check(name).unwrap().into() +} + +fn account_address(name: &str) -> (T::AccountId, AccountAddress) +where + T::AccountId: From, +{ + let account: T::AccountId = Public::from_ss58check(name).unwrap().into(); + let address = Pallet::::to_move_address(&account).unwrap(); + (account, address) +} + // Move Basics Example fn move_basics_module() -> Vec { core::include_bytes!( @@ -138,6 +214,14 @@ fn car_wash_buy_coin(addr: &AccountAddress, cnt: u8) -> Vec { script_transaction!(script, no_type_args!(), addr, &cnt) } +fn car_wash_wash_car(addr: &AccountAddress) -> Vec { + let script = core::include_bytes!( + "assets/move-projects/car-wash-example/build/car-wash-example/bytecode_scripts/wash_car.mv" + ) + .to_vec(); + script_transaction!(script, no_type_args!(), addr) +} + // Multiple Signers Example fn multiple_signers_module() -> Vec { core::include_bytes!( diff --git a/pallet/src/weights.rs b/pallet/src/weights.rs index 93aeefa..be5d5a0 100644 --- a/pallet/src/weights.rs +++ b/pallet/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_move` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-04-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-04-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `michaelardtsMBP`, CPU: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -46,19 +46,19 @@ impl crate::weight_info::WeightInfo for WeightInfo { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MoveModule::ChoreOnIdleStorage` (r:1 w:1) /// Proof: `MoveModule::ChoreOnIdleStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `MoveModule::VMStorage` (r:3 w:1) + /// Storage: `MoveModule::VMStorage` (r:3 w:2) /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `n` is `[0, 3]`. + /// The range of component `n` is `[0, 7]`. fn execute(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `8649 + n * (51 ±0)` - // Estimated: `14181 + n * (1276 ±0)` - // Minimum execution time: 37_000_000 picoseconds. - Weight::from_parts(438_185_343, 0) - .saturating_add(Weight::from_parts(0, 14181)) - .saturating_add(T::DbWeight::get().reads(5)) + // Measured: `8700` + // Estimated: `14577 + n * (812 ±0)` + // Minimum execution time: 36_000_000 picoseconds. + Weight::from_parts(552_887_566, 0) + .saturating_add(Weight::from_parts(0, 14577)) + .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) - .saturating_add(Weight::from_parts(0, 1276).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(0, 812).saturating_mul(n.into())) } /// Storage: `MoveModule::VMStorage` (r:2 w:1) /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -67,11 +67,11 @@ impl crate::weight_info::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `111 + n * (3506 ±0)` // Estimated: `2180 + n * (4531 ±116)` - // Minimum execution time: 35_000_000 picoseconds. - Weight::from_parts(25_481_828, 0) + // Minimum execution time: 36_000_000 picoseconds. + Weight::from_parts(25_415_305, 0) .saturating_add(Weight::from_parts(0, 2180)) - // Standard Error: 1_176_510 - .saturating_add(Weight::from_parts(125_453_109, 0).saturating_mul(n.into())) + // Standard Error: 1_274_995 + .saturating_add(Weight::from_parts(132_265_386, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 4531).saturating_mul(n.into())) @@ -82,8 +82,8 @@ impl crate::weight_info::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `111` // Estimated: `3576` - // Minimum execution time: 155_000_000 picoseconds. - Weight::from_parts(156_000_000, 0) + // Minimum execution time: 161_000_000 picoseconds. + Weight::from_parts(168_000_000, 0) .saturating_add(Weight::from_parts(0, 3576)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -94,8 +94,8 @@ impl crate::weight_info::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `7123` // Estimated: `10588` - // Minimum execution time: 190_000_000 picoseconds. - Weight::from_parts(191_000_000, 0) + // Minimum execution time: 197_000_000 picoseconds. + Weight::from_parts(201_000_000, 0) .saturating_add(Weight::from_parts(0, 10588)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -103,24 +103,60 @@ impl crate::weight_info::WeightInfo for WeightInfo { } impl crate::weight_info::WeightInfo for () { + /// Storage: `MoveModule::MultisigStorage` (r:1 w:1) + /// Proof: `MoveModule::MultisigStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `MoveModule::ChoreOnIdleStorage` (r:1 w:1) + /// Proof: `MoveModule::ChoreOnIdleStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoveModule::VMStorage` (r:3 w:2) + /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `n` is `[0, 7]`. fn execute(n: u32, ) -> Weight { - Weight::from_parts(438_185_343, 0) - .saturating_add(Weight::from_parts(0, 14181)) - .saturating_add(Weight::from_parts(0, 1276).saturating_mul(n.into())) + // Proof Size summary in bytes: + // Measured: `8700` + // Estimated: `14577 + n * (812 ±0)` + // Minimum execution time: 36_000_000 picoseconds. + Weight::from_parts(552_887_566, 0) + .saturating_add(Weight::from_parts(0, 14577)) + .saturating_add(Weight::from_parts(0, 812).saturating_mul(n.into())) } + /// Storage: `MoveModule::VMStorage` (r:2 w:1) + /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `n` is `[0, 3]`. fn publish_module(n: u32, ) -> Weight { - Weight::from_parts(25_481_828, 0) + // Proof Size summary in bytes: + // Measured: `111 + n * (3506 ±0)` + // Estimated: `2180 + n * (4531 ±116)` + // Minimum execution time: 36_000_000 picoseconds. + Weight::from_parts(25_415_305, 0) .saturating_add(Weight::from_parts(0, 2180)) - // Standard Error: 1_176_510 - .saturating_add(Weight::from_parts(125_453_109, 0).saturating_mul(n.into())) + // Standard Error: 1_274_995 + .saturating_add(Weight::from_parts(132_265_386, 0).saturating_mul(n.into())) .saturating_add(Weight::from_parts(0, 4531).saturating_mul(n.into())) } + /// Storage: `MoveModule::VMStorage` (r:1 w:1) + /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) fn publish_module_bundle() -> Weight { - Weight::from_parts(156_000_000, 0) + // Proof Size summary in bytes: + // Measured: `111` + // Estimated: `3576` + // Minimum execution time: 161_000_000 picoseconds. + Weight::from_parts(168_000_000, 0) .saturating_add(Weight::from_parts(0, 3576)) } + /// Storage: `MoveModule::VMStorage` (r:1 w:1) + /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) fn update_stdlib_bundle() -> Weight { - Weight::from_parts(191_000_000, 0) + // Proof Size summary in bytes: + // Measured: `7123` + // Estimated: `10588` + // Minimum execution time: 197_000_000 picoseconds. + Weight::from_parts(201_000_000, 0) .saturating_add(Weight::from_parts(0, 10588)) } }