From 79cea95689dd462bf5a551ee642a351cababa9fc Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 30 Dec 2021 21:31:03 -0800 Subject: [PATCH 1/4] Set CurrentCodeHash before running some dispatchable benchmarks --- runtime/parachains/src/paras/benchmarking.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/parachains/src/paras/benchmarking.rs b/runtime/parachains/src/paras/benchmarking.rs index b63f67327d1f..94faf29a2dc2 100644 --- a/runtime/parachains/src/paras/benchmarking.rs +++ b/runtime/parachains/src/paras/benchmarking.rs @@ -81,6 +81,7 @@ benchmarks! { let c in 1 .. MAX_CODE_SIZE; let new_code = ValidationCode(vec![0; c as usize]); let para_id = ParaId::from(c as u32); + as Store>::CurrentCodeHash::put(¶_id, new_code.clone()); generate_disordered_pruning::(); }: _(RawOrigin::Root, para_id, new_code) verify { @@ -108,6 +109,8 @@ benchmarks! { let s in 1 .. MAX_HEAD_DATA_SIZE; let para_id = ParaId::from(1000); let new_head = HeadData(vec![0; s as usize]); + let old_code = ValidationCode(vec![0]); + as Store>::CurrentCodeHash::put(¶_id, old_code); // schedule an expired code upgrade for this `para_id` so that force_note_new_head would use // the worst possible code path let expired = frame_system::Pallet::::block_number().saturating_sub(One::one()); From 8b82284fde6fd42ad737958cf7b5679920275781 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 30 Dec 2021 21:43:20 -0800 Subject: [PATCH 2/4] Use insert instead of put --- runtime/parachains/src/paras/benchmarking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/parachains/src/paras/benchmarking.rs b/runtime/parachains/src/paras/benchmarking.rs index 94faf29a2dc2..1d0812875019 100644 --- a/runtime/parachains/src/paras/benchmarking.rs +++ b/runtime/parachains/src/paras/benchmarking.rs @@ -81,7 +81,7 @@ benchmarks! { let c in 1 .. MAX_CODE_SIZE; let new_code = ValidationCode(vec![0; c as usize]); let para_id = ParaId::from(c as u32); - as Store>::CurrentCodeHash::put(¶_id, new_code.clone()); + as Store>::CurrentCodeHash::insert(¶_id, new_code.clone()); generate_disordered_pruning::(); }: _(RawOrigin::Root, para_id, new_code) verify { @@ -110,7 +110,7 @@ benchmarks! { let para_id = ParaId::from(1000); let new_head = HeadData(vec![0; s as usize]); let old_code = ValidationCode(vec![0]); - as Store>::CurrentCodeHash::put(¶_id, old_code); + as Store>::CurrentCodeHash::insert(¶_id, old_code); // schedule an expired code upgrade for this `para_id` so that force_note_new_head would use // the worst possible code path let expired = frame_system::Pallet::::block_number().saturating_sub(One::one()); From aceeb26114f404002077c913a4005c86611a8d4c Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 30 Dec 2021 22:27:41 -0800 Subject: [PATCH 3/4] Actually hash the ValidationCode --- runtime/parachains/src/paras/benchmarking.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/parachains/src/paras/benchmarking.rs b/runtime/parachains/src/paras/benchmarking.rs index 1d0812875019..bd9106422d90 100644 --- a/runtime/parachains/src/paras/benchmarking.rs +++ b/runtime/parachains/src/paras/benchmarking.rs @@ -81,7 +81,7 @@ benchmarks! { let c in 1 .. MAX_CODE_SIZE; let new_code = ValidationCode(vec![0; c as usize]); let para_id = ParaId::from(c as u32); - as Store>::CurrentCodeHash::insert(¶_id, new_code.clone()); + as Store>::CurrentCodeHash::insert(¶_id, new_code.hash()); generate_disordered_pruning::(); }: _(RawOrigin::Root, para_id, new_code) verify { @@ -109,8 +109,8 @@ benchmarks! { let s in 1 .. MAX_HEAD_DATA_SIZE; let para_id = ParaId::from(1000); let new_head = HeadData(vec![0; s as usize]); - let old_code = ValidationCode(vec![0]); - as Store>::CurrentCodeHash::insert(¶_id, old_code); + let old_code_hash = ValidationCode(vec![0]).hash(); + as Store>::CurrentCodeHash::insert(¶_id, old_code_hash); // schedule an expired code upgrade for this `para_id` so that force_note_new_head would use // the worst possible code path let expired = frame_system::Pallet::::block_number().saturating_sub(One::one()); From b5dd50f6d050e6af7cf83761c2605d300b369f76 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Fri, 31 Dec 2021 23:52:00 +0000 Subject: [PATCH 4/4] cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_paras.rs --- .../src/weights/runtime_parachains_paras.rs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/runtime/westend/src/weights/runtime_parachains_paras.rs b/runtime/westend/src/weights/runtime_parachains_paras.rs index 7162fb5ccb93..630f51edc4e5 100644 --- a/runtime/westend/src/weights/runtime_parachains_paras.rs +++ b/runtime/westend/src/weights/runtime_parachains_paras.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for `runtime_parachains::paras` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-12-29, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-12-31, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128 // Executed Command: @@ -45,17 +45,20 @@ pub struct WeightInfo(PhantomData); impl runtime_parachains::paras::WeightInfo for WeightInfo { // Storage: Paras CurrentCodeHash (r:1 w:1) // Storage: Paras CodeByHashRefs (r:1 w:1) + // Storage: Paras PastCodeMeta (r:1 w:1) + // Storage: Paras PastCodePruning (r:1 w:1) + // Storage: Paras PastCodeHash (r:0 w:1) // Storage: Paras CodeByHash (r:0 w:1) fn force_set_current_code(c: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + .saturating_add((2_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Paras Heads (r:0 w:1) fn force_set_current_head(s: u32, ) -> Weight { - (12_596_000 as Weight) + (13_711_000 as Weight) // Standard Error: 0 .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -73,23 +76,24 @@ impl runtime_parachains::paras::WeightInfo for WeightIn fn force_schedule_code_upgrade(c: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((2_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } // Storage: Paras FutureCodeUpgrades (r:1 w:0) // Storage: Paras Heads (r:0 w:1) + // Storage: Paras UpgradeGoAheadSignal (r:0 w:1) fn force_note_new_head(s: u32, ) -> Weight { - (19_699_000 as Weight) + (18_543_000 as Weight) // Standard Error: 0 .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: ParasShared CurrentSessionIndex (r:1 w:0) // Storage: Paras ActionsQueue (r:1 w:1) fn force_queue_action() -> Weight { - (23_566_000 as Weight) + (22_153_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -98,14 +102,14 @@ impl runtime_parachains::paras::WeightInfo for WeightIn fn add_trusted_validation_code(c: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((2_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Paras CodeByHashRefs (r:1 w:0) // Storage: Paras CodeByHash (r:0 w:1) fn poke_unused_validation_code() -> Weight { - (4_736_000 as Weight) + (4_207_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) }