diff --git a/pallet/src/assets/move-projects/gas-costs/Move.toml b/pallet/src/assets/move-projects/gas-costs/Move.toml index 814a666..c6ae1f6 100644 --- a/pallet/src/assets/move-projects/gas-costs/Move.toml +++ b/pallet/src/assets/move-projects/gas-costs/Move.toml @@ -5,7 +5,9 @@ version = "0.0.0" [dependencies] MoveStdlib = { git = "https://github.com/eigerco/move-stdlib", rev = "main" } car-wash-example = { local = "../car-wash-example/" } +basic_coin = { local = "../basic_coin" } [addresses] std = "0x1" DeveloperBob = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" +CafeAccount = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" diff --git a/pallet/src/assets/move-projects/gas-costs/build.sh b/pallet/src/assets/move-projects/gas-costs/build.sh index 00b9a4d..5f785b0 100755 --- a/pallet/src/assets/move-projects/gas-costs/build.sh +++ b/pallet/src/assets/move-projects/gas-costs/build.sh @@ -1,9 +1,9 @@ #!/bin/sh cd $(dirname $0) ALICE=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY -sh ./gen_cal_scripts.sh # Build the project smove build +sh ./gen_cal_scripts.sh # Create all Script-Transactions smove create-transaction --compiled-script-path build/gas-costs/bytecode_scripts/short_cheap_script.mv smove create-transaction --compiled-script-path build/gas-costs/bytecode_scripts/short_expensive_script.mv --args signer:$ALICE diff --git a/pallet/src/assets/move-projects/gas-costs/gen_cal_scripts.sh b/pallet/src/assets/move-projects/gas-costs/gen_cal_scripts.sh index 0619bbd..14113ae 100755 --- a/pallet/src/assets/move-projects/gas-costs/gen_cal_scripts.sh +++ b/pallet/src/assets/move-projects/gas-costs/gen_cal_scripts.sh @@ -1,41 +1,19 @@ #!/bin/sh cd $(dirname $0) -MOVE_SRC="./sources/Calibration.move" BASH_SH="./gen_smove_instr.sh" ITERATIONS=25 - -function write_method() { - printf "script {\n" >> $MOVE_SRC - printf " fun cal_gas_cost_$1(v0: u8" >> $MOVE_SRC - if [ $1 -gt 0 ] - then - for i in $(seq 1 $1) - do - printf ", v$i: u8" >> $MOVE_SRC - done - fi - printf ") {\n" >> $MOVE_SRC - for i in $(seq 0 $1) - do - printf " assert!(v$i == $i, $i);\n" >> $MOVE_SRC - done - printf " }\n" >> $MOVE_SRC - printf "}\n" >> $MOVE_SRC -} +ALICE=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY +BOB=5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty function write_smove_cmd() { - printf "\nsmove create-transaction -c build/gas-costs/bytecode_scripts/cal_gas_cost_$1.mv --args" >> $BASH_SH - for i in $(seq 0 $1) - do - printf " u8:$i" >> $BASH_SH - done + cp build/gas-costs/bytecode_scripts/mint.mv build/gas-costs/bytecode_scripts/mint_$1.mv + printf "\nsmove create-transaction -c build/gas-costs/bytecode_scripts/mint_$1.mv --args signer:$BOB address:$ALICE u64:$1" >> $BASH_SH } -printf "" > $MOVE_SRC printf "#!/bin/sh" > $BASH_SH -for i in $(seq 0 $(($ITERATIONS-1))) +for i in $(seq 1 $(($ITERATIONS))) do - write_method $i write_smove_cmd $i done +printf "\nsmove create-transaction -c build/gas-costs/bytecode_scripts/publish_basic_balance.mv --args signer:$ALICE" >> $BASH_SH diff --git a/pallet/src/assets/move-projects/gas-costs/sources/GetCoin.move b/pallet/src/assets/move-projects/gas-costs/sources/GetCoin.move new file mode 100644 index 0000000..708ad10 --- /dev/null +++ b/pallet/src/assets/move-projects/gas-costs/sources/GetCoin.move @@ -0,0 +1,21 @@ +script { + use CafeAccount::BasicCoin; + + fun publish_basic_balance(s: signer) { + BasicCoin::publish_balance(&s); + } +} + +script { + use CafeAccount::BasicCoin; + + fun mint(module_owner: signer, rx_addr: address, amount: u64) { + //BasicCoin::mint(&module_owner, rx_addr, amount); + + let i = 1; + while (i <= amount) { + BasicCoin::mint(&module_owner, rx_addr, 1); + i = i + 1 + }; + } +} diff --git a/pallet/src/benchmarking.rs b/pallet/src/benchmarking.rs index 0d2588b..86b2445 100644 --- a/pallet/src/benchmarking.rs +++ b/pallet/src/benchmarking.rs @@ -8,6 +8,8 @@ use crate::{mock_utils as utils, *}; type SourceOf = <::Lookup as sp_runtime::traits::StaticLookup>::Source; +const MAX_GAS_AMOUNT: u32 = u32::MAX; + macro_rules! impl_gas_costs_cal_fns { ($name:tt) => { pub fn $name() -> &'static [u8] { @@ -30,47 +32,61 @@ mod benchmarks { use super::*; /// Because it is challenging to determine a reliable and fixed relation between gas costs and - /// Substrate weights, we created Move scripts with known gas costs and increasing steps of 20. - /// Twenty-five scripts with rising gas costs of about 20 for each iteration step were used as - /// input for this benchmark. Therefore, the original output was divided by 20 afterwards. + /// Substrate weights, we created Move scripts with known gas costs and increasing steps of 403. + /// Twenty-five scripts with rising gas costs of about 403 for each iteration step were used as + /// input for this benchmark. #[benchmark] fn execute(n: Linear<0, 24>) { let alice_32 = utils::account::(utils::ALICE_ADDR); + let bob_32 = utils::account::(utils::BOB_ADDR); // Our benchmark plan (each is a test scenario with different parameters). let script_bcs = [ - cal_gas_cost_0().to_vec(), - cal_gas_cost_1().to_vec(), - cal_gas_cost_2().to_vec(), - cal_gas_cost_3().to_vec(), - cal_gas_cost_4().to_vec(), - cal_gas_cost_5().to_vec(), - cal_gas_cost_6().to_vec(), - cal_gas_cost_7().to_vec(), - cal_gas_cost_8().to_vec(), - cal_gas_cost_9().to_vec(), - cal_gas_cost_10().to_vec(), - cal_gas_cost_11().to_vec(), - cal_gas_cost_12().to_vec(), - cal_gas_cost_13().to_vec(), - cal_gas_cost_14().to_vec(), - cal_gas_cost_15().to_vec(), - cal_gas_cost_16().to_vec(), - cal_gas_cost_17().to_vec(), - cal_gas_cost_18().to_vec(), - cal_gas_cost_19().to_vec(), - cal_gas_cost_20().to_vec(), - cal_gas_cost_21().to_vec(), - cal_gas_cost_22().to_vec(), - cal_gas_cost_23().to_vec(), - cal_gas_cost_24().to_vec(), + mint_1().to_vec(), + mint_2().to_vec(), + mint_3().to_vec(), + mint_4().to_vec(), + mint_5().to_vec(), + mint_6().to_vec(), + mint_7().to_vec(), + mint_8().to_vec(), + mint_9().to_vec(), + mint_10().to_vec(), + mint_11().to_vec(), + mint_12().to_vec(), + mint_13().to_vec(), + mint_14().to_vec(), + mint_15().to_vec(), + mint_16().to_vec(), + mint_17().to_vec(), + mint_18().to_vec(), + mint_19().to_vec(), + mint_20().to_vec(), + mint_21().to_vec(), + mint_22().to_vec(), + mint_23().to_vec(), + mint_24().to_vec(), + mint_25().to_vec(), ]; + Pallet::::publish_module( + RawOrigin::Signed(bob_32.clone()).into(), + publish_basic_coin().to_vec(), + MAX_GAS_AMOUNT, + ).unwrap(); + + Pallet::::execute( + RawOrigin::Signed(alice_32.clone()).into(), + publish_basic_balance().to_vec(), + MAX_GAS_AMOUNT, + 0u128.into(), + ).unwrap(); + #[extrinsic_call] execute( - RawOrigin::Signed(alice_32), + RawOrigin::Signed(bob_32), script_bcs[n as usize].clone(), - (n + 1) * 20, + 19 + (n + 1) * 403, 0u128.into(), ) } @@ -187,29 +203,42 @@ mod benchmark_only { ) } - impl_gas_costs_cal_fns!(cal_gas_cost_0); - impl_gas_costs_cal_fns!(cal_gas_cost_1); - impl_gas_costs_cal_fns!(cal_gas_cost_2); - impl_gas_costs_cal_fns!(cal_gas_cost_3); - impl_gas_costs_cal_fns!(cal_gas_cost_4); - impl_gas_costs_cal_fns!(cal_gas_cost_5); - impl_gas_costs_cal_fns!(cal_gas_cost_6); - impl_gas_costs_cal_fns!(cal_gas_cost_7); - impl_gas_costs_cal_fns!(cal_gas_cost_8); - impl_gas_costs_cal_fns!(cal_gas_cost_9); - impl_gas_costs_cal_fns!(cal_gas_cost_10); - impl_gas_costs_cal_fns!(cal_gas_cost_11); - impl_gas_costs_cal_fns!(cal_gas_cost_12); - impl_gas_costs_cal_fns!(cal_gas_cost_13); - impl_gas_costs_cal_fns!(cal_gas_cost_14); - impl_gas_costs_cal_fns!(cal_gas_cost_15); - impl_gas_costs_cal_fns!(cal_gas_cost_16); - impl_gas_costs_cal_fns!(cal_gas_cost_17); - impl_gas_costs_cal_fns!(cal_gas_cost_18); - impl_gas_costs_cal_fns!(cal_gas_cost_19); - impl_gas_costs_cal_fns!(cal_gas_cost_20); - impl_gas_costs_cal_fns!(cal_gas_cost_21); - impl_gas_costs_cal_fns!(cal_gas_cost_22); - impl_gas_costs_cal_fns!(cal_gas_cost_23); - impl_gas_costs_cal_fns!(cal_gas_cost_24); + // Basic Coin Example + pub fn publish_basic_coin() -> &'static [u8] { + core::include_bytes!( + "assets/move-projects/gas-costs/build/gas-costs/bytecode_modules/dependencies/basic_coin/BasicCoin.mv" + ) + } + + pub fn publish_basic_balance() -> &'static [u8] { + core::include_bytes!( + "assets/move-projects/gas-costs/build/gas-costs/script_transactions/publish_basic_balance.mvt" + ) + } + + impl_gas_costs_cal_fns!(mint_1); + impl_gas_costs_cal_fns!(mint_2); + impl_gas_costs_cal_fns!(mint_3); + impl_gas_costs_cal_fns!(mint_4); + impl_gas_costs_cal_fns!(mint_5); + impl_gas_costs_cal_fns!(mint_6); + impl_gas_costs_cal_fns!(mint_7); + impl_gas_costs_cal_fns!(mint_8); + impl_gas_costs_cal_fns!(mint_9); + impl_gas_costs_cal_fns!(mint_10); + impl_gas_costs_cal_fns!(mint_11); + impl_gas_costs_cal_fns!(mint_12); + impl_gas_costs_cal_fns!(mint_13); + impl_gas_costs_cal_fns!(mint_14); + impl_gas_costs_cal_fns!(mint_15); + impl_gas_costs_cal_fns!(mint_16); + impl_gas_costs_cal_fns!(mint_17); + impl_gas_costs_cal_fns!(mint_18); + impl_gas_costs_cal_fns!(mint_19); + impl_gas_costs_cal_fns!(mint_20); + impl_gas_costs_cal_fns!(mint_21); + impl_gas_costs_cal_fns!(mint_22); + impl_gas_costs_cal_fns!(mint_23); + impl_gas_costs_cal_fns!(mint_24); + impl_gas_costs_cal_fns!(mint_25); } diff --git a/pallet/src/weights.rs b/pallet/src/weights.rs index d37b754..821511d 100644 --- a/pallet/src/weights.rs +++ b/pallet/src/weights.rs @@ -4,7 +4,7 @@ //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 //! DATE: 2024-05-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `michaeleberhardts-MacBook-Pro.local`, CPU: `` +//! HOSTNAME: `bonka-MacBook-Pro.local`, CPU: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: @@ -33,31 +33,29 @@ use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; -// Note: The weights have not only been generated by the Substrate benchmarks with a template-node. -// A couple of manual and additional modifications have been done which are marked in the -// comments. - /// Weight functions for `pallet_move`. pub struct SubstrateWeight(PhantomData); impl crate::weight_info::WeightInfo for SubstrateWeight { - /// Because it is challenging to determine a reliable and fixed relation between gas costs and - /// Substrate weights, we created Move scripts with known gas costs and increasing steps of 20. - /// Twenty-five scripts with rising gas costs of about 20 for each iteration step were used as - /// input for this benchmark. Therefore, the original output was divided by 20 afterwards. + /// 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::VMStorage` (r:3 w:1) + /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `n` is `[0, 24]`. fn execute(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 46_000_000 picoseconds. - Weight::from_parts(44_730_881, 0) - .saturating_add(Weight::from_parts(0, 0)) - // Standard Error: 9_543 - // Manually divided original output by 20: 13_002_180 / 20 = 650_109 - .saturating_add(Weight::from_parts(650_109, 0).saturating_mul(n.into())) - // Manuelly added: - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + // Measured: `8622` + // Estimated: `17037` + // Minimum execution time: 345_000_000 picoseconds. + Weight::from_parts(348_832_865, 0) + .saturating_add(Weight::from_parts(0, 17037)) + // Standard Error: 25_764 + .saturating_add(Weight::from_parts(5_607_737, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `MoveModule::VMStorage` (r:1 w:1) /// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -66,11 +64,11 @@ impl crate::weight_info::WeightInfo for SubstrateWeight // Proof Size summary in bytes: // Measured: `7796` // Estimated: `14073` - // Minimum execution time: 44_000_000 picoseconds. - Weight::from_parts(318_442_817, 0) + // Minimum execution time: 42_000_000 picoseconds. + Weight::from_parts(310_274_033, 0) .saturating_add(Weight::from_parts(0, 14073)) - // Standard Error: 3_649_708 - .saturating_add(Weight::from_parts(4_313_812, 0).saturating_mul(n.into())) + // Standard Error: 3_569_607 + .saturating_add(Weight::from_parts(4_038_397, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -81,11 +79,11 @@ impl crate::weight_info::WeightInfo for SubstrateWeight // Proof Size summary in bytes: // Measured: `7796` // Estimated: `14073` - // Minimum execution time: 44_000_000 picoseconds. - Weight::from_parts(319_610_220, 0) + // Minimum execution time: 43_000_000 picoseconds. + Weight::from_parts(311_709_392, 0) .saturating_add(Weight::from_parts(0, 14073)) - // Standard Error: 3_670_322 - .saturating_add(Weight::from_parts(4_522_651, 0).saturating_mul(n.into())) + // Standard Error: 3_599_218 + .saturating_add(Weight::from_parts(4_712_707, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -95,8 +93,8 @@ impl crate::weight_info::WeightInfo for SubstrateWeight // Proof Size summary in bytes: // Measured: `7796` // Estimated: `11261` - // Minimum execution time: 204_000_000 picoseconds. - Weight::from_parts(206_000_000, 0) + // Minimum execution time: 198_000_000 picoseconds. + Weight::from_parts(200_000_000, 0) .saturating_add(Weight::from_parts(0, 11261)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1))