From cabf674d1e5bfeda9ee49933e382ad347df6fe99 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Wed, 26 Apr 2023 18:29:12 +0400 Subject: [PATCH 01/13] paras: unconditionally precheck pvfs --- runtime/parachains/src/builder.rs | 8 +- runtime/parachains/src/hrmp/tests.rs | 7 +- runtime/parachains/src/paras/mod.rs | 27 +---- runtime/parachains/src/paras/tests.rs | 131 ++++++++++++++-------- runtime/parachains/src/scheduler/tests.rs | 10 +- 5 files changed, 106 insertions(+), 77 deletions(-) diff --git a/runtime/parachains/src/builder.rs b/runtime/parachains/src/builder.rs index 452c4c255ecf..f9908e30ad03 100644 --- a/runtime/parachains/src/builder.rs +++ b/runtime/parachains/src/builder.rs @@ -340,16 +340,22 @@ impl BenchBuilder { // make sure parachains exist prior to session change. for i in 0..cores { let para_id = ParaId::from(i as u32); + let validation_code = mock_validation_code(); paras::Pallet::::schedule_para_initialize( para_id, paras::ParaGenesisArgs { genesis_head: Self::mock_head_data(), - validation_code: mock_validation_code(), + validation_code: validation_code.clone(), para_kind: ParaKind::Parachain, }, ) .unwrap(); + paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + ) + .unwrap(); } } diff --git a/runtime/parachains/src/hrmp/tests.rs b/runtime/parachains/src/hrmp/tests.rs index 65602782b1d3..c396260d2c30 100644 --- a/runtime/parachains/src/hrmp/tests.rs +++ b/runtime/parachains/src/hrmp/tests.rs @@ -23,7 +23,7 @@ use crate::{ paras::ParaKind, }; use frame_support::{assert_noop, assert_ok, traits::Currency as _}; -use primitives::BlockNumber; +use primitives::{BlockNumber, ValidationCode}; use std::collections::BTreeMap; fn run_to_block(to: BlockNumber, new_session: Option>) { @@ -130,14 +130,17 @@ fn default_genesis_config() -> MockGenesisConfig { } fn register_parachain_with_balance(id: ParaId, balance: Balance) { + let validation_code: ValidationCode = vec![1].into(); assert_ok!(Paras::schedule_para_initialize( id, crate::paras::ParaGenesisArgs { para_kind: ParaKind::Parachain, genesis_head: vec![1].into(), - validation_code: vec![1].into(), + validation_code: validation_code.clone(), }, )); + + assert_ok!(Paras::add_trusted_validation_code(RuntimeOrigin::root(), validation_code)); ::Currency::make_free_balance_be(&id.into_account_truncating(), balance); } diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index b4818e86c278..d5731e6c605b 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -602,9 +602,6 @@ pub mod pallet { PvfCheckDoubleVote, /// The given PVF does not exist at the moment of process a vote. PvfCheckSubjectInvalid, - /// The PVF pre-checking statement cannot be included since the PVF pre-checking mechanism - /// is disabled. - PvfCheckDisabled, /// Parachain cannot currently schedule a code upgrade. CannotUpgradeCode, } @@ -970,12 +967,6 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { ensure_none(origin)?; - // Make sure that PVF pre-checking is enabled. - ensure!( - configuration::Pallet::::config().pvf_checking_enabled, - Error::::PvfCheckDisabled, - ); - let validators = shared::Pallet::::active_validator_keys(); let current_session = shared::Pallet::::session_index(); if stmt.session_index < current_session { @@ -1062,10 +1053,6 @@ pub mod pallet { _ => return InvalidTransaction::Call.into(), }; - if !configuration::Pallet::::config().pvf_checking_enabled { - return InvalidTransaction::Custom(INVALID_TX_PVF_CHECK_DISABLED).into() - } - let current_session = shared::Pallet::::session_index(); if stmt.session_index < current_session { return InvalidTransaction::Stale.into() @@ -1126,7 +1113,6 @@ pub mod pallet { const INVALID_TX_BAD_VALIDATOR_IDX: u8 = 1; const INVALID_TX_BAD_SUBJECT: u8 = 2; const INVALID_TX_DOUBLE_VOTE: u8 = 3; -const INVALID_TX_PVF_CHECK_DISABLED: u8 = 4; impl Pallet { /// This is a call to schedule code upgrades for parachains which is safe to be called @@ -1828,9 +1814,7 @@ impl Pallet { /// Makes sure that the given code hash has passed pre-checking. /// /// If the given code hash has already passed pre-checking, then the approval happens - /// immediately. Similarly, if the pre-checking is turned off, the update is scheduled immediately - /// as well. In this case, the behavior is similar to the previous, i.e. the upgrade sequence - /// is purely time-based. + /// immediately. /// /// If the code is unknown, but the pre-checking for that PVF is already running then we perform /// "coalescing". We save the cause for this PVF pre-check request and just add it to the @@ -1859,12 +1843,9 @@ impl Pallet { let known_code = CodeByHash::::contains_key(&code_hash); weight += T::DbWeight::get().reads(1); - if !cfg.pvf_checking_enabled || known_code { - // Either: - // - the code is known and there is no active PVF vote for it meaning it is - // already checked, or - // - the PVF checking is diabled - // In any case: fast track the PVF checking into the accepted state + if known_code { + // The code is known and there is no active PVF vote for it meaning it is + // already checked -- fast track the PVF checking into the accepted state. weight += T::DbWeight::get().reads(1); let now = >::block_number(); weight += Self::enact_pvf_accepted(now, &code_hash, &[cause], 0, cfg); diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index d8988ab6a3d3..c69c68d1f68e 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -420,7 +420,9 @@ fn code_upgrade_applied_after_delay() { let para_id = ParaId::from(0); let new_code = ValidationCode(vec![4, 5, 6]); - run_to_block(2, None); + // Wait for at least one session change to set active validators. + const EXPECTED_SESSION: SessionIndex = 1; + run_to_block(2, Some(vec![1])); assert_eq!(Paras::current_code(¶_id), Some(original_code.clone())); let expected_at = { @@ -428,6 +430,16 @@ fn code_upgrade_applied_after_delay() { let expected_at = 1 + validation_upgrade_delay; let next_possible_upgrade_at = 1 + validation_upgrade_cooldown; Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); + // Include votes for super-majority. + IntoIterator::into_iter([0, 1, 2, 3]) + .map(|i| PvfCheckStatement { + accept: true, + subject: new_code.hash(), + session_index: EXPECTED_SESSION, + validator_index: i.into(), + }) + .for_each(sign_and_include_pvf_check_statement); + Paras::note_new_head(para_id, Default::default(), 1); assert!(Paras::past_code_meta(¶_id).most_recent_change().is_none()); @@ -515,7 +527,9 @@ fn code_upgrade_applied_after_delay_even_when_late() { let para_id = ParaId::from(0); let new_code = ValidationCode(vec![4, 5, 6]); - run_to_block(2, None); + // Wait for at least one session change to set active validators. + const EXPECTED_SESSION: SessionIndex = 1; + run_to_block(2, Some(vec![1])); assert_eq!(Paras::current_code(¶_id), Some(original_code.clone())); let expected_at = { @@ -523,6 +537,16 @@ fn code_upgrade_applied_after_delay_even_when_late() { let expected_at = 1 + validation_upgrade_delay; let next_possible_upgrade_at = 1 + validation_upgrade_cooldown; Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); + // Include votes for super-majority. + IntoIterator::into_iter([0, 1, 2, 3]) + .map(|i| PvfCheckStatement { + accept: true, + subject: new_code.hash(), + session_index: EXPECTED_SESSION, + validator_index: i.into(), + }) + .for_each(sign_and_include_pvf_check_statement); + Paras::note_new_head(para_id, Default::default(), 1); assert!(Paras::past_code_meta(¶_id).most_recent_change().is_none()); @@ -595,8 +619,21 @@ fn submit_code_change_when_not_allowed_is_err() { let new_code = ValidationCode(vec![4, 5, 6]); let newer_code = ValidationCode(vec![4, 5, 6, 7]); - run_to_block(1, None); + // Wait for at least one session change to set active validators. + const EXPECTED_SESSION: SessionIndex = 1; + run_to_block(1, Some(vec![1])); + Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); + // Include votes for super-majority. + IntoIterator::into_iter([0, 1, 2, 3]) + .map(|i| PvfCheckStatement { + accept: true, + subject: new_code.hash(), + session_index: EXPECTED_SESSION, + validator_index: i.into(), + }) + .for_each(sign_and_include_pvf_check_statement); + assert_eq!(FutureCodeUpgrades::::get(¶_id), Some(1 + validation_upgrade_delay)); assert_eq!(FutureCodeHash::::get(¶_id), Some(new_code.hash())); check_code_is_stored(&new_code); @@ -625,7 +662,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { // rather an artifact of the current implementation and not necessarily something we want // to keep in the future. // - // This test exists that this is not accidentially changed. + // This test exists that this is not accidentally changed. let code_retention_period = 10; let validation_upgrade_delay = 7; @@ -660,8 +697,21 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { let new_code = ValidationCode(vec![4, 5, 6]); let newer_code = ValidationCode(vec![4, 5, 6, 7]); - run_to_block(1, None); + // Wait for at least one session change to set active validators. + const EXPECTED_SESSION: SessionIndex = 1; + run_to_block(1, Some(vec![1])); + Paras::schedule_code_upgrade(para_id, new_code.clone(), 0, &Configuration::config()); + // Include votes for super-majority. + IntoIterator::into_iter([0, 1, 2, 3]) + .map(|i| PvfCheckStatement { + accept: true, + subject: new_code.hash(), + session_index: EXPECTED_SESSION, + validator_index: i.into(), + }) + .for_each(sign_and_include_pvf_check_statement); + Paras::note_new_head(para_id, dummy_head_data(), 0); assert_eq!( UpgradeRestrictionSignal::::get(¶_id), @@ -722,7 +772,10 @@ fn full_parachain_cleanup_storage() { let para_id = ParaId::from(0); let new_code = ValidationCode(vec![4, 5, 6]); - run_to_block(2, None); + // Wait for at least one session change to set active validators. + const EXPECTED_SESSION: SessionIndex = 1; + run_to_block(2, Some(vec![1])); + assert_eq!(Paras::current_code(¶_id), Some(original_code.clone())); check_code_is_stored(&original_code); @@ -730,6 +783,16 @@ fn full_parachain_cleanup_storage() { // this parablock is in the context of block 1. let expected_at = 1 + validation_upgrade_delay; Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); + // Include votes for super-majority. + IntoIterator::into_iter([0, 1, 2, 3]) + .map(|i| PvfCheckStatement { + accept: true, + subject: new_code.hash(), + session_index: EXPECTED_SESSION, + validator_index: i.into(), + }) + .for_each(sign_and_include_pvf_check_statement); + Paras::note_new_head(para_id, Default::default(), 1); assert!(Paras::past_code_meta(¶_id).most_recent_change().is_none()); @@ -985,10 +1048,23 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { }; new_test_ext(genesis_config).execute_with(|| { + // Wait for at least one session change to set active validators. + run_to_block(2, Some(vec![1])); + const EXPECTED_SESSION: SessionIndex = 1; + let para_id = ParaId::from(0); let old_code: ValidationCode = vec![1, 2, 3].into(); let new_code: ValidationCode = vec![4, 5, 6].into(); Paras::schedule_code_upgrade(para_id, new_code.clone(), 0, &Configuration::config()); + // Include votes for super-majority. + IntoIterator::into_iter([0, 1, 2, 3]) + .map(|i| PvfCheckStatement { + accept: true, + subject: new_code.hash(), + session_index: EXPECTED_SESSION, + validator_index: i.into(), + }) + .for_each(sign_and_include_pvf_check_statement); // The new validation code can be applied but a new parablock hasn't gotten in yet, // so the old code should still be current. @@ -998,7 +1074,7 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { run_to_block(10, None); Paras::note_new_head(para_id, Default::default(), 7); - assert_eq!(Paras::past_code_meta(¶_id).upgrade_times, vec![upgrade_at(2, 10)]); + assert_eq!(Paras::past_code_meta(¶_id).upgrade_times, vec![upgrade_at(4, 10)]); assert_eq!(Paras::current_code(¶_id), Some(new_code.clone())); // Make sure that the old code is available **before** the code retion period passes. @@ -1253,47 +1329,6 @@ fn pvf_check_upgrade_reject() { }); } -#[test] -fn pvf_check_submit_vote_while_disabled() { - let genesis_config = MockGenesisConfig { - configuration: crate::configuration::GenesisConfig { - config: HostConfiguration { pvf_checking_enabled: false, ..Default::default() }, - ..Default::default() - }, - ..Default::default() - }; - - new_test_ext(genesis_config).execute_with(|| { - // This will set the session index to 1 and seed the validators. - run_to_block(1, Some(vec![1])); - - let stmt = PvfCheckStatement { - accept: false, - subject: ValidationCode(vec![1, 2, 3]).hash(), - session_index: 1, - validator_index: 1.into(), - }; - - let signature: ValidatorSignature = - Sr25519Keyring::Alice.sign(&stmt.signing_payload()).into(); - - let call = - Call::include_pvf_check_statement { stmt: stmt.clone(), signature: signature.clone() }; - - let validate_unsigned = - ::validate_unsigned(TransactionSource::InBlock, &call); - assert_eq!( - validate_unsigned, - InvalidTransaction::Custom(INVALID_TX_PVF_CHECK_DISABLED).into() - ); - - assert_err!( - Paras::include_pvf_check_statement(None.into(), stmt.clone(), signature.clone()), - Error::::PvfCheckDisabled - ); - }); -} - #[test] fn pvf_check_submit_vote() { let code_a: ValidationCode = vec![3, 2, 1].into(); diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index cde7fa6534de..f1daf85d5ce1 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -18,26 +18,30 @@ use super::*; use frame_support::assert_ok; use keyring::Sr25519Keyring; -use primitives::{BlockNumber, CollatorId, SessionIndex, ValidatorId}; +use primitives::{BlockNumber, CollatorId, SessionIndex, ValidationCode, ValidatorId}; use crate::{ configuration::HostConfiguration, initializer::SessionChangeNotification, mock::{ - new_test_ext, Configuration, MockGenesisConfig, Paras, ParasShared, Scheduler, System, Test, + new_test_ext, Configuration, MockGenesisConfig, Paras, ParasShared, RuntimeOrigin, + Scheduler, System, Test, }, paras::{ParaGenesisArgs, ParaKind}, }; fn schedule_blank_para(id: ParaId, parakind: ParaKind) { + let validation_code: ValidationCode = vec![1, 2, 3].into(); assert_ok!(Paras::schedule_para_initialize( id, ParaGenesisArgs { genesis_head: Vec::new().into(), - validation_code: vec![1, 2, 3].into(), + validation_code: validation_code.clone(), para_kind: parakind, } )); + + assert_ok!(Paras::add_trusted_validation_code(RuntimeOrigin::root(), validation_code)); } fn run_to_block( From 3e16133851e753c03a843551ecf94605ba70c306 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Wed, 26 Apr 2023 22:50:54 +0400 Subject: [PATCH 02/13] Update integration tests --- Cargo.lock | 1 + runtime/common/Cargo.toml | 1 + runtime/common/src/integration_tests.rs | 158 +++++++++++++++++++----- runtime/parachains/src/shared.rs | 4 +- 4 files changed, 128 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d53e89163464..12bd435b08a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7760,6 +7760,7 @@ dependencies = [ "sp-core", "sp-inherents", "sp-io", + "sp-keyring", "sp-keystore", "sp-npos-elections", "sp-runtime", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 8cb7aa7f9808..517b600eeea6 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -56,6 +56,7 @@ frame-support-test = { git = "https://github.com/paritytech/substrate", branch = pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } serde_json = "1.0.96" libsecp256k1 = "0.7.0" test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../primitives/test-helpers" } diff --git a/runtime/common/src/integration_tests.rs b/runtime/common/src/integration_tests.rs index c1c4eaa153e4..eef77ea83222 100644 --- a/runtime/common/src/integration_tests.rs +++ b/runtime/common/src/integration_tests.rs @@ -31,12 +31,16 @@ use frame_support::{ use frame_support_test::TestRandomness; use frame_system::EnsureRoot; use parity_scale_codec::Encode; -use primitives::{BlockNumber, HeadData, Header, Id as ParaId, ValidationCode, LOWEST_PUBLIC_ID}; +use primitives::{ + BlockNumber, HeadData, Header, Id as ParaId, PvfCheckStatement, SessionIndex, ValidationCode, + LOWEST_PUBLIC_ID, +}; use runtime_parachains::{ configuration, origin, paras, shared, Origin as ParaOrigin, ParaLifecycle, }; use sp_core::H256; use sp_io::TestExternalities; +use sp_keyring::Sr25519Keyring; use sp_keystore::{testing::MemoryKeystore, KeystoreExt}; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup, One}, @@ -298,13 +302,39 @@ pub fn new_test_ext_with_offset(n: BlockNumber) -> TestExternalities { const BLOCKS_PER_SESSION: u32 = 10; +const VALIDATORS: &[Sr25519Keyring] = &[ + Sr25519Keyring::Alice, + Sr25519Keyring::Bob, + Sr25519Keyring::Charlie, + Sr25519Keyring::Dave, + Sr25519Keyring::Ferdie, +]; + fn maybe_new_session(n: u32) { if n % BLOCKS_PER_SESSION == 0 { - shared::Pallet::::set_session_index(shared::Pallet::::session_index() + 1); + let session_index = shared::Pallet::::session_index() + 1; + let validators_pub_keys = VALIDATORS.iter().map(|v| v.public().into()).collect(); + + shared::Pallet::::set_session_index(session_index); + shared::Pallet::::set_active_validators_ascending(validators_pub_keys); Paras::test_on_new_session(); } } +fn conclude_pvf_checking(validation_code: &ValidationCode, session_index: SessionIndex) { + VALIDATORS.iter().enumerate().take(4).for_each(|(idx, key)| { + let validator_index = idx as u32; + let statement = PvfCheckStatement { + accept: true, + subject: validation_code.hash(), + session_index, + validator_index: validator_index.into(), + }; + let signature = key.sign(&statement.signing_payload()); + Paras::include_pvf_check_statement(None.into(), statement, signature.into()).unwrap(); + }) +} + fn test_genesis_head(size: usize) -> HeadData { HeadData(vec![0u8; size]) } @@ -357,6 +387,10 @@ fn basic_end_to_end_works() { let para_1 = LOWEST_PUBLIC_ID; let para_2 = LOWEST_PUBLIC_ID + 1; assert!(System::block_number().is_one()); + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + let start_block = System::block_number(); + // User 1 and 2 will own parachains Balances::make_free_balance_be(&account_id(1), 1_000_000_000); Balances::make_free_balance_be(&account_id(2), 1_000_000_000); @@ -370,6 +404,7 @@ fn basic_end_to_end_works() { genesis_head.clone(), validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); assert_ok!(Registrar::reserve(signed(2))); assert_ok!(Registrar::register( signed(2), @@ -392,7 +427,7 @@ fn basic_end_to_end_works() { )); // 2 sessions later they are parathreads - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); assert_eq!(Paras::lifecycle(ParaId::from(para_1)), Some(ParaLifecycle::Parathread)); assert_eq!(Paras::lifecycle(ParaId::from(para_2)), Some(ParaLifecycle::Parathread)); @@ -411,7 +446,7 @@ fn basic_end_to_end_works() { let crowdloan_account = Crowdloan::fund_account_id(fund_2.fund_index); // Auction ending begins on block 100 + offset, so we make a bid before then. - run_to_block(90 + offset); + run_to_block(start_block + 90 + offset); Balances::make_free_balance_be(&account_id(10), 1_000_000_000); Balances::make_free_balance_be(&account_id(20), 1_000_000_000); @@ -431,7 +466,7 @@ fn basic_end_to_end_works() { assert_ok!(Crowdloan::contribute(signed(2), ParaId::from(para_2), 920, None)); // Auction ends at block 110 + offset - run_to_block(109 + offset); + run_to_block(start_block + 109 + offset); assert!(contains_event( crowdloan::Event::::HandleBidResult { para_id: ParaId::from(para_2), @@ -439,7 +474,7 @@ fn basic_end_to_end_works() { } .into() )); - run_to_block(110 + offset); + run_to_block(start_block + 110 + offset); assert_eq!( last_event(), auctions::Event::::AuctionClosed { auction_index: 1 }.into() @@ -473,7 +508,7 @@ fn basic_end_to_end_works() { ); // New leases will start on block 400 - let lease_start_block = 400 + offset; + let lease_start_block = start_block + 400 + offset; run_to_block(lease_start_block); // First slot, Para 1 should be transitioning to Parachain @@ -587,19 +622,24 @@ fn competing_slots() { let max_bids = 10u32; let para_id = LOWEST_PUBLIC_ID; + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // Create n paras and owners + let validation_code = Registrar::worst_validation_code(); for n in 1..=max_bids { Balances::make_free_balance_be(&account_id(n), 1_000_000_000); let genesis_head = Registrar::worst_head_data(); - let validation_code = Registrar::worst_validation_code(); assert_ok!(Registrar::reserve(signed(n))); assert_ok!(Registrar::register( signed(n), para_id + n - 1, genesis_head, - validation_code, + validation_code.clone(), )); } + // The code undergoing the prechecking is the same for all paras. + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Start a new auction in the future let duration = 149u32; @@ -611,7 +651,7 @@ fn competing_slots() { )); // Paras should be onboarded - run_to_block(20); // session 2 + run_to_session(START_SESSION_INDEX + 2); for n in 1..=max_bids { // Increment block number @@ -645,7 +685,7 @@ fn competing_slots() { } // Auction should be done after ending period - run_to_block(160); + run_to_block(180); // Appropriate Paras should have won slots // 900 + 4500 + 2x 8100 = 21,600 @@ -683,23 +723,28 @@ fn competing_bids() { new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + let start_para = LOWEST_PUBLIC_ID - 1; // Create 3 paras and owners + let validation_code = Registrar::worst_validation_code(); for n in 1..=3 { Balances::make_free_balance_be(&account_id(n), 1_000_000_000); let genesis_head = Registrar::worst_head_data(); - let validation_code = Registrar::worst_validation_code(); assert_ok!(Registrar::reserve(signed(n))); assert_ok!(Registrar::register( signed(n), ParaId::from(start_para + n), genesis_head, - validation_code, + validation_code.clone(), )); } + // The code undergoing the prechecking is the same for all paras. + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Finish registration of paras. - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); // Start a new auction in the future let starting_block = System::block_number(); @@ -785,24 +830,33 @@ fn basic_swap_works() { // This test will test a swap between a parachain and parathread works successfully. new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); /* So events are emitted */ + + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // User 1 and 2 will own paras Balances::make_free_balance_be(&account_id(1), 1_000_000_000); Balances::make_free_balance_be(&account_id(2), 1_000_000_000); // First register 2 parathreads with different data + let validation_code = test_validation_code(10); assert_ok!(Registrar::reserve(signed(1))); assert_ok!(Registrar::register( signed(1), ParaId::from(2000), test_genesis_head(10), - test_validation_code(10), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + let validation_code = test_validation_code(20); assert_ok!(Registrar::reserve(signed(2))); assert_ok!(Registrar::register( signed(2), ParaId::from(2001), test_genesis_head(20), - test_validation_code(20), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Paras should be onboarding assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding)); @@ -818,7 +872,7 @@ fn basic_swap_works() { )); // 2 sessions later they are parathreads - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Parathread)); assert_eq!(Paras::lifecycle(ParaId::from(2001)), Some(ParaLifecycle::Parathread)); @@ -938,24 +992,33 @@ fn parachain_swap_works() { // This test will test a swap between two parachains works successfully. new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); /* So events are emitted */ + + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // User 1 and 2 will own paras Balances::make_free_balance_be(&account_id(1), 1_000_000_000); Balances::make_free_balance_be(&account_id(2), 1_000_000_000); // First register 2 parathreads with different data + let validation_code = test_validation_code(10); assert_ok!(Registrar::reserve(signed(1))); assert_ok!(Registrar::register( signed(1), ParaId::from(2000), test_genesis_head(10), - test_validation_code(10), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + let validation_code = test_validation_code(20); assert_ok!(Registrar::reserve(signed(2))); assert_ok!(Registrar::register( signed(2), ParaId::from(2001), test_genesis_head(20), - test_validation_code(20), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Paras should be onboarding assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding)); @@ -1100,24 +1163,34 @@ fn parachain_swap_works() { fn crowdloan_ending_period_bid() { new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); /* So events are emitted */ + + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // User 1 and 2 will own paras Balances::make_free_balance_be(&account_id(1), 1_000_000_000); Balances::make_free_balance_be(&account_id(2), 1_000_000_000); + // First register 2 parathreads + let validation_code = test_validation_code(10); assert_ok!(Registrar::reserve(signed(1))); assert_ok!(Registrar::register( signed(1), ParaId::from(2000), test_genesis_head(10), - test_validation_code(10), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + let validation_code = test_validation_code(20); assert_ok!(Registrar::reserve(signed(2))); assert_ok!(Registrar::register( signed(2), ParaId::from(2001), test_genesis_head(20), - test_validation_code(20), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Paras should be onboarding assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding)); @@ -1125,6 +1198,7 @@ fn crowdloan_ending_period_bid() { // Start a new auction in the future let duration = 99u32; + let ends_at = System::block_number() + duration; let lease_period_index_start = 4u32; assert_ok!(Auctions::new_auction( RuntimeOrigin::root(), @@ -1133,7 +1207,7 @@ fn crowdloan_ending_period_bid() { )); // 2 sessions later they are parathreads - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Parathread)); assert_eq!(Paras::lifecycle(ParaId::from(2001)), Some(ParaLifecycle::Parathread)); @@ -1172,9 +1246,9 @@ fn crowdloan_ending_period_bid() { )); // Go to beginning of ending period - run_to_block(100); + run_to_block(ends_at); - assert_eq!(Auctions::auction_status(100), AuctionStatus::::EndingPeriod(0, 0)); + assert_eq!(Auctions::auction_status(ends_at), AuctionStatus::::EndingPeriod(0, 0)); let mut winning = [(); SlotRange::SLOT_RANGE_COUNT].map(|_| None); winning[SlotRange::ZeroOne as u8 as usize] = Some((account_id(2), ParaId::from(2001), 900)); @@ -1183,13 +1257,13 @@ fn crowdloan_ending_period_bid() { assert_eq!(Auctions::winning(0), Some(winning)); - run_to_block(101); + run_to_block(ends_at + 1); Balances::make_free_balance_be(&account_id(1234), 1_000_000_000); assert_ok!(Crowdloan::contribute(signed(1234), ParaId::from(2000), 900, None)); // Data propagates correctly - run_to_block(102); + run_to_block(ends_at + 2); let mut winning = [(); SlotRange::SLOT_RANGE_COUNT].map(|_| None); winning[SlotRange::ZeroOne as u8 as usize] = Some((account_id(2), ParaId::from(2001), 900)); winning[SlotRange::ZeroThree as u8 as usize] = @@ -1203,6 +1277,9 @@ fn auction_bid_requires_registered_para() { new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); /* So events are emitted */ + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // Start a new auction in the future let duration = 99u32; let lease_period_index_start = 4u32; @@ -1227,13 +1304,15 @@ fn auction_bid_requires_registered_para() { ); // Now we register the para + let validation_code = test_validation_code(10); assert_ok!(Registrar::reserve(signed(1))); assert_ok!(Registrar::register( signed(1), ParaId::from(2000), test_genesis_head(10), - test_validation_code(10), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Still can't bid until it is fully onboarded assert_noop!( @@ -1249,7 +1328,7 @@ fn auction_bid_requires_registered_para() { ); // Onboarded on Session 2 - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); // Success Balances::make_free_balance_be(&account_id(1), 1_000_000_000); @@ -1269,6 +1348,9 @@ fn gap_bids_work() { new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); /* So events are emitted */ + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // Start a new auction in the future let duration = 99u32; let lease_period_index_start = 4u32; @@ -1281,23 +1363,25 @@ fn gap_bids_work() { Balances::make_free_balance_be(&account_id(2), 1_000_000_000); // Now register 2 paras + let validation_code = test_validation_code(10); assert_ok!(Registrar::reserve(signed(1))); assert_ok!(Registrar::register( signed(1), ParaId::from(2000), test_genesis_head(10), - test_validation_code(10), + validation_code.clone(), )); assert_ok!(Registrar::reserve(signed(2))); assert_ok!(Registrar::register( signed(2), ParaId::from(2001), test_genesis_head(10), - test_validation_code(10), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Onboarded on Session 2 - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); // Make bids Balances::make_free_balance_be(&account_id(10), 1_000_000_000); @@ -1352,7 +1436,7 @@ fn gap_bids_work() { )); // Finish the auction - run_to_block(110 + LeaseOffset::get()); + run_to_block(130 + LeaseOffset::get()); // Should have won the lease periods assert_eq!( @@ -1450,15 +1534,21 @@ fn gap_bids_work() { fn cant_bid_on_existing_lease_periods() { new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); /* So events are emitted */ + + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + Balances::make_free_balance_be(&account_id(1), 1_000_000_000); // First register a parathread + let validation_code = test_validation_code(10); assert_ok!(Registrar::reserve(signed(1))); assert_ok!(Registrar::register( signed(1), ParaId::from(2000), test_genesis_head(10), - test_validation_code(10), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Start a new auction in the future let starting_block = System::block_number(); @@ -1471,7 +1561,7 @@ fn cant_bid_on_existing_lease_periods() { )); // 2 sessions later they are parathreads - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); // Open a crowdloan for Para 1 for slots 0-3 assert_ok!(Crowdloan::create( diff --git a/runtime/parachains/src/shared.rs b/runtime/parachains/src/shared.rs index ed094c953f45..686b955175b1 100644 --- a/runtime/parachains/src/shared.rs +++ b/runtime/parachains/src/shared.rs @@ -123,8 +123,8 @@ impl Pallet { CurrentSessionIndex::::set(index); } - #[cfg(any(feature = "runtime-benchmarks", test))] - pub(crate) fn set_active_validators_ascending(active: Vec) { + #[cfg(any(feature = "std", feature = "runtime-benchmarks", test))] + pub fn set_active_validators_ascending(active: Vec) { ActiveValidatorIndices::::set( (0..active.len()).map(|i| ValidatorIndex(i as _)).collect(), ); From 44c6326afc17e7decde64b9d29936fa10b590d29 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Wed, 26 Apr 2023 23:07:51 +0400 Subject: [PATCH 03/13] paras_registrar tests --- runtime/common/src/paras_registrar.rs | 137 +++++++++++++++++++------- 1 file changed, 100 insertions(+), 37 deletions(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 6ad37e63cc7e..7400eefb742a 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -662,10 +662,11 @@ mod tests { }; use frame_system::limits; use pallet_balances::Error as BalancesError; - use primitives::{Balance, BlockNumber, Header}; + use primitives::{Balance, BlockNumber, Header, PvfCheckStatement, SessionIndex}; use runtime_parachains::{configuration, origin, shared}; use sp_core::H256; use sp_io::TestExternalities; + use sp_keyring::Sr25519Keyring; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, transaction_validity::TransactionPriority, @@ -831,6 +832,14 @@ mod tests { const BLOCKS_PER_SESSION: u32 = 3; + const VALIDATORS: &[Sr25519Keyring] = &[ + Sr25519Keyring::Alice, + Sr25519Keyring::Bob, + Sr25519Keyring::Charlie, + Sr25519Keyring::Dave, + Sr25519Keyring::Ferdie, + ]; + fn run_to_block(n: BlockNumber) { // NOTE that this function only simulates modules of interest. Depending on new pallet may // require adding it here. @@ -843,9 +852,12 @@ mod tests { } // Session change every 3 blocks. if (b + 1) % BLOCKS_PER_SESSION == 0 { - shared::Pallet::::set_session_index( - shared::Pallet::::session_index() + 1, - ); + let session_index = shared::Pallet::::session_index() + 1; + let validators_pub_keys = VALIDATORS.iter().map(|v| v.public().into()).collect(); + + shared::Pallet::::set_session_index(session_index); + shared::Pallet::::set_active_validators_ascending(validators_pub_keys); + Parachains::test_on_new_session(); } System::set_block_number(b + 1); @@ -853,6 +865,21 @@ mod tests { } } + fn conclude_pvf_checking(validation_code: &ValidationCode, session_index: SessionIndex) { + VALIDATORS.iter().enumerate().take(4).for_each(|(idx, key)| { + let validator_index = idx as u32; + let statement = PvfCheckStatement { + accept: true, + subject: validation_code.hash(), + session_index, + validator_index: validator_index.into(), + }; + let signature = key.sign(&statement.signing_payload()); + Parachains::include_pvf_check_statement(None.into(), statement, signature.into()) + .unwrap(); + }) + } + fn run_to_session(n: BlockNumber) { let block_number = n * BLOCKS_PER_SESSION; run_to_block(block_number); @@ -891,35 +918,41 @@ mod tests { fn end_to_end_scenario_works() { new_test_ext().execute_with(|| { let para_id = LOWEST_PUBLIC_ID; - run_to_block(1); + + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // first para is not yet registered assert!(!Parachains::is_parathread(para_id)); // We register the Para ID + let validation_code = test_validation_code(32); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1))); assert_ok!(Registrar::register( RuntimeOrigin::signed(1), para_id, test_genesis_head(32), - test_validation_code(32), + validation_code.clone(), )); - run_to_session(2); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + run_to_session(START_SESSION_INDEX + 2); // It is now a parathread. assert!(Parachains::is_parathread(para_id)); assert!(!Parachains::is_parachain(para_id)); // Some other external process will elevate parathread to parachain assert_ok!(Registrar::make_parachain(para_id)); - run_to_session(4); + run_to_session(START_SESSION_INDEX + 4); // It is now a parachain. assert!(!Parachains::is_parathread(para_id)); assert!(Parachains::is_parachain(para_id)); // Turn it back into a parathread assert_ok!(Registrar::make_parathread(para_id)); - run_to_session(6); + run_to_session(START_SESSION_INDEX + 6); assert!(Parachains::is_parathread(para_id)); assert!(!Parachains::is_parachain(para_id)); // Deregister it assert_ok!(Registrar::deregister(RuntimeOrigin::root(), para_id,)); - run_to_session(8); + run_to_session(START_SESSION_INDEX + 8); // It is nothing assert!(!Parachains::is_parathread(para_id)); assert!(!Parachains::is_parachain(para_id)); @@ -929,18 +962,24 @@ mod tests { #[test] fn register_works() { new_test_ext().execute_with(|| { - run_to_block(1); + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + let para_id = LOWEST_PUBLIC_ID; assert!(!Parachains::is_parathread(para_id)); + + let validation_code = test_validation_code(32); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1))); assert_eq!(Balances::reserved_balance(&1), ::ParaDeposit::get()); assert_ok!(Registrar::register( RuntimeOrigin::signed(1), para_id, test_genesis_head(32), - test_validation_code(32), + validation_code.clone(), )); - run_to_session(2); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + run_to_session(START_SESSION_INDEX + 2); assert!(Parachains::is_parathread(para_id)); assert_eq!( Balances::reserved_balance(&1), @@ -984,7 +1023,7 @@ mod tests { test_genesis_head(max_head_size() as usize), test_validation_code(max_code_size() as usize), )); - + // Can skip pre-check and deregister para which's still onboarding. run_to_session(2); assert_ok!(Registrar::deregister(RuntimeOrigin::root(), para_id)); @@ -1034,20 +1073,26 @@ mod tests { #[test] fn deregister_works() { new_test_ext().execute_with(|| { - run_to_block(1); + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + let para_id = LOWEST_PUBLIC_ID; assert!(!Parachains::is_parathread(para_id)); + + let validation_code = test_validation_code(32); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1))); assert_ok!(Registrar::register( RuntimeOrigin::signed(1), para_id, test_genesis_head(32), - test_validation_code(32), + validation_code.clone(), )); - run_to_session(2); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + run_to_session(START_SESSION_INDEX + 2); assert!(Parachains::is_parathread(para_id)); assert_ok!(Registrar::deregister(RuntimeOrigin::root(), para_id,)); - run_to_session(4); + run_to_session(START_SESSION_INDEX + 4); assert!(paras::Pallet::::lifecycle(para_id).is_none()); assert_eq!(Balances::reserved_balance(&1), 0); }); @@ -1056,22 +1101,28 @@ mod tests { #[test] fn deregister_handles_basic_errors() { new_test_ext().execute_with(|| { - run_to_block(1); + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + let para_id = LOWEST_PUBLIC_ID; assert!(!Parachains::is_parathread(para_id)); + + let validation_code = test_validation_code(32); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1))); assert_ok!(Registrar::register( RuntimeOrigin::signed(1), para_id, test_genesis_head(32), - test_validation_code(32), + validation_code.clone(), )); - run_to_session(2); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + run_to_session(START_SESSION_INDEX + 2); assert!(Parachains::is_parathread(para_id)); // Owner check assert_noop!(Registrar::deregister(RuntimeOrigin::signed(2), para_id,), BadOrigin); assert_ok!(Registrar::make_parachain(para_id)); - run_to_session(4); + run_to_session(START_SESSION_INDEX + 4); // Cant directly deregister parachain assert_noop!( Registrar::deregister(RuntimeOrigin::root(), para_id,), @@ -1083,24 +1134,31 @@ mod tests { #[test] fn swap_works() { new_test_ext().execute_with(|| { + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + // Successfully register first two parachains let para_1 = LOWEST_PUBLIC_ID; let para_2 = LOWEST_PUBLIC_ID + 1; + + let validation_code = test_validation_code(max_code_size() as usize); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1))); assert_ok!(Registrar::register( RuntimeOrigin::signed(1), para_1, test_genesis_head(max_head_size() as usize), - test_validation_code(max_code_size() as usize), + validation_code.clone(), )); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(2))); assert_ok!(Registrar::register( RuntimeOrigin::signed(2), para_2, test_genesis_head(max_head_size() as usize), - test_validation_code(max_code_size() as usize), + validation_code.clone(), )); - run_to_session(2); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + + run_to_session(START_SESSION_INDEX + 2); // Upgrade para 1 into a parachain assert_ok!(Registrar::make_parachain(para_1)); @@ -1111,7 +1169,7 @@ mod tests { swap_data.insert(para_2, 1337); SwapData::set(swap_data); - run_to_session(4); + run_to_session(START_SESSION_INDEX + 4); // Roles are as we expect assert!(Parachains::is_parachain(para_1)); @@ -1123,7 +1181,7 @@ mod tests { assert_ok!(Registrar::swap(para_origin(para_1), para_1, para_2,)); assert_ok!(Registrar::swap(para_origin(para_2), para_2, para_1,)); - run_to_session(6); + run_to_session(START_SESSION_INDEX + 6); // Roles are swapped assert!(!Parachains::is_parachain(para_1)); @@ -1171,9 +1229,12 @@ mod tests { #[test] fn swap_handles_bad_states() { new_test_ext().execute_with(|| { + const START_SESSION_INDEX: SessionIndex = 1; + run_to_session(START_SESSION_INDEX); + let para_1 = LOWEST_PUBLIC_ID; let para_2 = LOWEST_PUBLIC_ID + 1; - run_to_block(1); + // paras are not yet registered assert!(!Parachains::is_parathread(para_1)); assert!(!Parachains::is_parathread(para_2)); @@ -1185,20 +1246,22 @@ mod tests { ); // We register Paras 1 and 2 + let validation_code = test_validation_code(32); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1))); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(2))); assert_ok!(Registrar::register( RuntimeOrigin::signed(1), para_1, test_genesis_head(32), - test_validation_code(32), + validation_code.clone(), )); assert_ok!(Registrar::register( RuntimeOrigin::signed(2), para_2, test_genesis_head(32), - test_validation_code(32), + validation_code.clone(), )); + conclude_pvf_checking(&validation_code, START_SESSION_INDEX); // Cannot swap assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2)); @@ -1207,7 +1270,7 @@ mod tests { Error::::CannotSwap ); - run_to_session(2); + run_to_session(START_SESSION_INDEX + 2); // They are now a parathread. assert!(Parachains::is_parathread(para_1)); @@ -1230,7 +1293,7 @@ mod tests { Error::::CannotSwap ); - run_to_session(3); + run_to_session(START_SESSION_INDEX + 3); // Cannot swap assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2)); @@ -1239,7 +1302,7 @@ mod tests { Error::::CannotSwap ); - run_to_session(4); + run_to_session(START_SESSION_INDEX + 4); // It is now a parachain. assert!(Parachains::is_parachain(para_1)); @@ -1249,7 +1312,7 @@ mod tests { assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2)); assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_2, para_1)); - run_to_session(5); + run_to_session(START_SESSION_INDEX + 5); // Cannot swap assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2)); @@ -1258,7 +1321,7 @@ mod tests { Error::::CannotSwap ); - run_to_session(6); + run_to_session(START_SESSION_INDEX + 6); // Swap worked! assert!(Parachains::is_parachain(para_2)); @@ -1267,7 +1330,7 @@ mod tests { // Something starts to downgrade a para assert_ok!(Registrar::make_parathread(para_2)); - run_to_session(7); + run_to_session(START_SESSION_INDEX + 7); // Cannot swap assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2)); @@ -1276,7 +1339,7 @@ mod tests { Error::::CannotSwap ); - run_to_session(8); + run_to_session(START_SESSION_INDEX + 8); assert!(Parachains::is_parathread(para_1)); assert!(Parachains::is_parathread(para_2)); From 2d2fbb0884e13acf5c6bd1a9cfd240569a6b8a29 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Thu, 27 Apr 2023 02:02:33 +0400 Subject: [PATCH 04/13] runtime benchmark tests --- runtime/common/src/auctions.rs | 29 +++++++++- runtime/common/src/crowdloan/mod.rs | 61 +++++++++++++++++++-- runtime/common/src/integration_tests.rs | 47 ++++++---------- runtime/common/src/mock.rs | 31 ++++++++++- runtime/common/src/paras_registrar.rs | 73 +++++++++++++++---------- runtime/common/src/slots/mod.rs | 22 +++++++- 6 files changed, 194 insertions(+), 69 deletions(-) diff --git a/runtime/common/src/auctions.rs b/runtime/common/src/auctions.rs index dea6f3fd4bb3..bbdbc0cd299c 100644 --- a/runtime/common/src/auctions.rs +++ b/runtime/common/src/auctions.rs @@ -1731,12 +1731,17 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Auctions, *}; + use crate::mock::{conclude_pvf_checking, validators_public_keys}; use frame_support::traits::{EnsureOrigin, OnInitialize}; use frame_system::RawOrigin; + use runtime_parachains::{paras, shared}; + use sp_keyring::Sr25519Keyring; use sp_runtime::{traits::Bounded, SaturatedConversion}; use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError}; + const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; + fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1745,9 +1750,12 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn fill_winners(lease_period_index: LeasePeriodOf) { + fn fill_winners( + lease_period_index: LeasePeriodOf, + ) { let auction_index = AuctionCounter::::get(); let minimum_balance = CurrencyOf::::minimum_balance(); + let session_index = shared::Pallet::::session_index(); for n in 1..=SlotRange::SLOT_RANGE_COUNT as u32 { let owner = account("owner", n, 0); @@ -1763,6 +1771,11 @@ mod benchmarking { ) .is_ok()); } + conclude_pvf_checking::( + &T::Registrar::worst_validation_code(), + VALIDATORS, + session_index, + ); T::Registrar::execute_pending_transitions(); @@ -1786,7 +1799,7 @@ mod benchmarking { } benchmarks! { - where_clause { where T: pallet_babe::Config } + where_clause { where T: pallet_babe::Config + paras::Config + shared::Config } new_auction { let duration = T::BlockNumber::max_value(); @@ -1804,6 +1817,8 @@ mod benchmarking { // Worst case scenario a new bid comes in which kicks out an existing bid for the same slot. bid { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (_, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); @@ -1824,7 +1839,11 @@ mod benchmarking { let worst_head_data = T::Registrar::worst_head_data(); let worst_validation_code = T::Registrar::worst_validation_code(); T::Registrar::register(owner.clone(), para, worst_head_data.clone(), worst_validation_code.clone())?; - T::Registrar::register(owner, new_para, worst_head_data, worst_validation_code)?; + T::Registrar::register(owner, new_para, worst_head_data, worst_validation_code.clone())?; + + let session_index = shared::Pallet::::session_index(); + conclude_pvf_checking::(&T::Registrar::worst_validation_code(), VALIDATORS, session_index); + T::Registrar::execute_pending_transitions(); // Make an existing bid @@ -1856,6 +1875,8 @@ mod benchmarking { // Worst case: 10 bidders taking all wining spots, and we need to calculate the winner for auction end. // Entire winner map should be full and removed at the end of the benchmark. on_initialize { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (lease_length, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); @@ -1901,6 +1922,8 @@ mod benchmarking { // Worst case: 10 bidders taking all wining spots, and winning data is full. cancel_auction { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (lease_length, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); diff --git a/runtime/common/src/crowdloan/mod.rs b/runtime/common/src/crowdloan/mod.rs index e4a8924df252..be92415da489 100644 --- a/runtime/common/src/crowdloan/mod.rs +++ b/runtime/common/src/crowdloan/mod.rs @@ -1951,14 +1951,19 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Crowdloan, *}; + use crate::mock::{conclude_pvf_checking, validators_public_keys}; use frame_support::{assert_ok, traits::OnInitialize}; use frame_system::RawOrigin; + use runtime_parachains::{paras, shared}; use sp_core::crypto::UncheckedFrom; + use sp_keyring::Sr25519Keyring; use sp_runtime::traits::{Bounded, CheckedSub}; use sp_std::prelude::*; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; + const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; + fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1967,7 +1972,10 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn create_fund(id: u32, end: T::BlockNumber) -> ParaId { + fn create_fund( + id: u32, + end: T::BlockNumber, + ) -> ParaId { let cap = BalanceOf::::max_value(); let (_, offset) = T::Auctioneer::lease_period_length(); // Set to the very beginning of lease period index 0. @@ -1985,9 +1993,17 @@ mod benchmarking { // Assume ed25519 is most complex signature format let pubkey = crypto::create_ed25519_pubkey(b"//verifier".to_vec()); + let session_index = shared::Pallet::::session_index(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); - assert_ok!(T::Registrar::register(caller.clone(), para_id, head_data, validation_code)); + assert_ok!(T::Registrar::register( + caller.clone(), + para_id, + head_data, + validation_code.clone() + )); + conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + T::Registrar::execute_pending_transitions(); assert_ok!(Crowdloan::::create( @@ -2020,7 +2036,12 @@ mod benchmarking { } benchmarks! { + where_clause { where T: paras::Config + shared::Config } + create { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let para_id = ParaId::from(1_u32); let cap = BalanceOf::::max_value(); let first_period = 0u32.into(); @@ -2029,13 +2050,15 @@ mod benchmarking { let end = lpl + offset; let caller: T::AccountId = whitelisted_caller(); + let session_index = shared::Pallet::::session_index(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0)); CurrencyOf::::make_free_balance_be(&caller, BalanceOf::::max_value()); - T::Registrar::register(caller.clone(), para_id, head_data, validation_code)?; + T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?; + conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); T::Registrar::execute_pending_transitions(); }: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier)) @@ -2045,6 +2068,9 @@ mod benchmarking { // Contribute has two arms: PreEnding and Ending, but both are equal complexity. contribute { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2065,6 +2091,9 @@ mod benchmarking { } withdraw { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2081,6 +2110,10 @@ mod benchmarking { #[skip_meta] refund { let k in 0 .. T::RemoveKeysLimit::get(); + + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2090,6 +2123,7 @@ mod benchmarking { contribute_fund::(&account("contributor", i, 0), fund_index); } + let caller: T::AccountId = whitelisted_caller(); frame_system::Pallet::::set_block_number(T::BlockNumber::max_value()); }: _(RawOrigin::Signed(caller), fund_index) @@ -2098,6 +2132,9 @@ mod benchmarking { } dissolve { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2109,6 +2146,9 @@ mod benchmarking { } edit { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let para_id = ParaId::from(1_u32); let cap = BalanceOf::::max_value(); let first_period = 0u32.into(); @@ -2119,11 +2159,14 @@ mod benchmarking { let caller: T::AccountId = whitelisted_caller(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); + let session_index = shared::Pallet::::session_index(); let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0)); CurrencyOf::::make_free_balance_be(&caller, BalanceOf::::max_value()); - T::Registrar::register(caller.clone(), para_id, head_data, validation_code)?; + T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?; + conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + T::Registrar::execute_pending_transitions(); Crowdloan::::create( @@ -2138,6 +2181,9 @@ mod benchmarking { } add_memo { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2154,6 +2200,9 @@ mod benchmarking { } poke { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2173,6 +2222,10 @@ mod benchmarking { on_initialize { // We test the complexity over different number of new raise let n in 2 .. 100; + + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let (lpl, offset) = T::Auctioneer::lease_period_length(); let end_block = lpl + offset - 1u32.into(); diff --git a/runtime/common/src/integration_tests.rs b/runtime/common/src/integration_tests.rs index eef77ea83222..407bd23b0890 100644 --- a/runtime/common/src/integration_tests.rs +++ b/runtime/common/src/integration_tests.rs @@ -17,7 +17,9 @@ //! Mocking utilities for testing with real pallets. use crate::{ - auctions, crowdloan, paras_registrar, + auctions, crowdloan, + mock::{conclude_pvf_checking, validators_public_keys}, + paras_registrar, slot_range::SlotRange, slots, traits::{AuctionStatus, Auctioneer, Leaser, Registrar as RegistrarT}, @@ -32,8 +34,7 @@ use frame_support_test::TestRandomness; use frame_system::EnsureRoot; use parity_scale_codec::Encode; use primitives::{ - BlockNumber, HeadData, Header, Id as ParaId, PvfCheckStatement, SessionIndex, ValidationCode, - LOWEST_PUBLIC_ID, + BlockNumber, HeadData, Header, Id as ParaId, SessionIndex, ValidationCode, LOWEST_PUBLIC_ID, }; use runtime_parachains::{ configuration, origin, paras, shared, Origin as ParaOrigin, ParaLifecycle, @@ -313,7 +314,7 @@ const VALIDATORS: &[Sr25519Keyring] = &[ fn maybe_new_session(n: u32) { if n % BLOCKS_PER_SESSION == 0 { let session_index = shared::Pallet::::session_index() + 1; - let validators_pub_keys = VALIDATORS.iter().map(|v| v.public().into()).collect(); + let validators_pub_keys = validators_public_keys(VALIDATORS); shared::Pallet::::set_session_index(session_index); shared::Pallet::::set_active_validators_ascending(validators_pub_keys); @@ -321,20 +322,6 @@ fn maybe_new_session(n: u32) { } } -fn conclude_pvf_checking(validation_code: &ValidationCode, session_index: SessionIndex) { - VALIDATORS.iter().enumerate().take(4).for_each(|(idx, key)| { - let validator_index = idx as u32; - let statement = PvfCheckStatement { - accept: true, - subject: validation_code.hash(), - session_index, - validator_index: validator_index.into(), - }; - let signature = key.sign(&statement.signing_payload()); - Paras::include_pvf_check_statement(None.into(), statement, signature.into()).unwrap(); - }) -} - fn test_genesis_head(size: usize) -> HeadData { HeadData(vec![0u8; size]) } @@ -404,7 +391,7 @@ fn basic_end_to_end_works() { genesis_head.clone(), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); assert_ok!(Registrar::reserve(signed(2))); assert_ok!(Registrar::register( signed(2), @@ -639,7 +626,7 @@ fn competing_slots() { )); } // The code undergoing the prechecking is the same for all paras. - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Start a new auction in the future let duration = 149u32; @@ -741,7 +728,7 @@ fn competing_bids() { )); } // The code undergoing the prechecking is the same for all paras. - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Finish registration of paras. run_to_session(START_SESSION_INDEX + 2); @@ -846,7 +833,7 @@ fn basic_swap_works() { test_genesis_head(10), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); let validation_code = test_validation_code(20); assert_ok!(Registrar::reserve(signed(2))); @@ -856,7 +843,7 @@ fn basic_swap_works() { test_genesis_head(20), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Paras should be onboarding assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding)); @@ -1008,7 +995,7 @@ fn parachain_swap_works() { test_genesis_head(10), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); let validation_code = test_validation_code(20); assert_ok!(Registrar::reserve(signed(2))); @@ -1018,7 +1005,7 @@ fn parachain_swap_works() { test_genesis_head(20), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Paras should be onboarding assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding)); @@ -1180,7 +1167,7 @@ fn crowdloan_ending_period_bid() { test_genesis_head(10), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); let validation_code = test_validation_code(20); assert_ok!(Registrar::reserve(signed(2))); @@ -1190,7 +1177,7 @@ fn crowdloan_ending_period_bid() { test_genesis_head(20), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Paras should be onboarding assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding)); @@ -1312,7 +1299,7 @@ fn auction_bid_requires_registered_para() { test_genesis_head(10), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Still can't bid until it is fully onboarded assert_noop!( @@ -1378,7 +1365,7 @@ fn gap_bids_work() { test_genesis_head(10), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Onboarded on Session 2 run_to_session(START_SESSION_INDEX + 2); @@ -1548,7 +1535,7 @@ fn cant_bid_on_existing_lease_periods() { test_genesis_head(10), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Start a new auction in the future let starting_block = System::block_number(); diff --git a/runtime/common/src/mock.rs b/runtime/common/src/mock.rs index 3e3f88169ab5..06cc7771dede 100644 --- a/runtime/common/src/mock.rs +++ b/runtime/common/src/mock.rs @@ -22,7 +22,9 @@ use frame_support::{ weights::Weight, }; use parity_scale_codec::{Decode, Encode}; -use primitives::{HeadData, Id as ParaId, ValidationCode}; +use primitives::{HeadData, Id as ParaId, PvfCheckStatement, SessionIndex, ValidationCode}; +use runtime_parachains::paras; +use sp_keyring::Sr25519Keyring; use sp_runtime::{traits::SaturatedConversion, Permill}; use std::{cell::RefCell, collections::HashMap}; @@ -231,3 +233,30 @@ impl frame_support::traits::EstimateNextSessionRotation for TestNextSession (None, Weight::zero()) } } + +pub fn validators_public_keys(validators: &[Sr25519Keyring]) -> Vec { + validators.iter().map(|v| v.public().into()).collect() +} + +pub fn conclude_pvf_checking( + validation_code: &ValidationCode, + validators: &[Sr25519Keyring], + session_index: SessionIndex, +) { + let num_required = primitives::supermajority_threshold(validators.len()); + validators.iter().enumerate().take(num_required).for_each(|(idx, key)| { + let validator_index = idx as u32; + let statement = PvfCheckStatement { + accept: true, + subject: validation_code.hash(), + session_index, + validator_index: validator_index.into(), + }; + let signature = key.sign(&statement.signing_payload()); + let _ = paras::Pallet::::include_pvf_check_statement( + frame_system::Origin::::None.into(), + statement, + signature.into(), + ); + }); +} diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 7400eefb742a..9ace5234bb4b 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -653,7 +653,9 @@ impl Pallet { #[cfg(test)] mod tests { use super::*; - use crate::{paras_registrar, traits::Registrar as RegistrarTrait}; + use crate::{ + mock::conclude_pvf_checking, paras_registrar, traits::Registrar as RegistrarTrait, + }; use frame_support::{ assert_noop, assert_ok, error::BadOrigin, @@ -662,7 +664,7 @@ mod tests { }; use frame_system::limits; use pallet_balances::Error as BalancesError; - use primitives::{Balance, BlockNumber, Header, PvfCheckStatement, SessionIndex}; + use primitives::{Balance, BlockNumber, Header, SessionIndex}; use runtime_parachains::{configuration, origin, shared}; use sp_core::H256; use sp_io::TestExternalities; @@ -865,21 +867,6 @@ mod tests { } } - fn conclude_pvf_checking(validation_code: &ValidationCode, session_index: SessionIndex) { - VALIDATORS.iter().enumerate().take(4).for_each(|(idx, key)| { - let validator_index = idx as u32; - let statement = PvfCheckStatement { - accept: true, - subject: validation_code.hash(), - session_index, - validator_index: validator_index.into(), - }; - let signature = key.sign(&statement.signing_payload()); - Parachains::include_pvf_check_statement(None.into(), statement, signature.into()) - .unwrap(); - }) - } - fn run_to_session(n: BlockNumber) { let block_number = n * BLOCKS_PER_SESSION; run_to_block(block_number); @@ -933,7 +920,7 @@ mod tests { test_genesis_head(32), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); run_to_session(START_SESSION_INDEX + 2); // It is now a parathread. @@ -977,7 +964,7 @@ mod tests { test_genesis_head(32), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); run_to_session(START_SESSION_INDEX + 2); assert!(Parachains::is_parathread(para_id)); @@ -1087,7 +1074,7 @@ mod tests { test_genesis_head(32), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); run_to_session(START_SESSION_INDEX + 2); assert!(Parachains::is_parathread(para_id)); @@ -1115,7 +1102,7 @@ mod tests { test_genesis_head(32), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); run_to_session(START_SESSION_INDEX + 2); assert!(Parachains::is_parathread(para_id)); @@ -1156,7 +1143,7 @@ mod tests { test_genesis_head(max_head_size() as usize), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); run_to_session(START_SESSION_INDEX + 2); @@ -1261,7 +1248,7 @@ mod tests { test_genesis_head(32), validation_code.clone(), )); - conclude_pvf_checking(&validation_code, START_SESSION_INDEX); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX); // Cannot swap assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2)); @@ -1350,15 +1337,21 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Registrar, *}; - use crate::traits::Registrar as RegistrarT; + use crate::{ + mock::{conclude_pvf_checking, validators_public_keys}, + traits::Registrar as RegistrarT, + }; use frame_support::assert_ok; use frame_system::RawOrigin; use primitives::{MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE}; use runtime_parachains::{paras, shared, Origin as ParaOrigin}; + use sp_keyring::Sr25519Keyring; use sp_runtime::traits::Bounded; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; + const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; + fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1367,8 +1360,9 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn register_para(id: u32) -> ParaId { + fn register_para(id: u32) -> ParaId { let para = ParaId::from(id); + let session_index = shared::Pallet::::session_index(); let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); let caller: T::AccountId = whitelisted_caller(); @@ -1378,8 +1372,9 @@ mod benchmarking { RawOrigin::Signed(caller).into(), para, genesis_head, - validation_code + validation_code.clone() )); + conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); return para } @@ -1394,7 +1389,11 @@ mod benchmarking { } benchmarks! { - where_clause { where ParaOrigin: Into<::RuntimeOrigin> } + where_clause { + where + ParaOrigin: Into<::RuntimeOrigin>, + T: paras::Config + shared::Config, + } reserve { let caller: T::AccountId = whitelisted_caller(); @@ -1407,35 +1406,48 @@ mod benchmarking { } register { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let para = LOWEST_PUBLIC_ID; let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); assert_ok!(Registrar::::reserve(RawOrigin::Signed(caller.clone()).into())); - }: _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code) + }: _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code.clone()) verify { assert_last_event::(Event::::Registered{ para_id: para, manager: caller }.into()); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); + let session_index = shared::Pallet::::session_index(); + conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); } force_register { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let manager: T::AccountId = account("manager", 0, 0); let deposit = 0u32.into(); let para = ParaId::from(69); let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); - }: _(RawOrigin::Root, manager.clone(), deposit, para, genesis_head, validation_code) + }: _(RawOrigin::Root, manager.clone(), deposit, para, genesis_head, validation_code.clone()) verify { assert_last_event::(Event::::Registered { para_id: para, manager }.into()); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); + let session_index = shared::Pallet::::session_index(); + conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); } deregister { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let para = register_para::(LOWEST_PUBLIC_ID.into()); next_scheduled_session::(); let caller: T::AccountId = whitelisted_caller(); @@ -1445,6 +1457,9 @@ mod benchmarking { } swap { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let parathread = register_para::(LOWEST_PUBLIC_ID.into()); let parachain = register_para::((LOWEST_PUBLIC_ID + 1).into()); diff --git a/runtime/common/src/slots/mod.rs b/runtime/common/src/slots/mod.rs index 4197257f9243..8d8b4f4f2e63 100644 --- a/runtime/common/src/slots/mod.rs +++ b/runtime/common/src/slots/mod.rs @@ -986,14 +986,19 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::*; + use crate::mock::{conclude_pvf_checking, validators_public_keys}; use frame_support::assert_ok; use frame_system::RawOrigin; + use runtime_parachains::{paras, shared}; + use sp_keyring::Sr25519Keyring; use sp_runtime::traits::{Bounded, One}; use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError}; use crate::slots::Pallet as Slots; + const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; + fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1002,7 +1007,10 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn register_a_parathread(i: u32) -> (ParaId, T::AccountId) { + fn register_a_parathread( + i: u32, + ) -> (ParaId, T::AccountId) { + let session_index = shared::Pallet::::session_index(); let para = ParaId::from(i); let leaser: T::AccountId = account("leaser", i, 0); T::Currency::make_free_balance_be(&leaser, BalanceOf::::max_value()); @@ -1013,14 +1021,18 @@ mod benchmarking { leaser.clone(), para, worst_head_data, - worst_validation_code + worst_validation_code.clone(), )); + conclude_pvf_checking::(&worst_validation_code, VALIDATORS, session_index); + T::Registrar::execute_pending_transitions(); (para, leaser) } benchmarks! { + where_clause { where T: paras::Config + shared::Config } + force_lease { // If there is an offset, we need to be on that block to be able to do lease things. frame_system::Pallet::::set_block_number(T::LeaseOffset::get() + One::one()); @@ -1049,6 +1061,9 @@ mod benchmarking { let c in 0 .. 100; let t in 0 .. 100; + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + let period_begin = 1u32.into(); let period_count = 4u32.into(); @@ -1138,6 +1153,9 @@ mod benchmarking { } trigger_onboard { + let public = validators_public_keys(VALIDATORS); + shared::Pallet::::set_active_validators_ascending(public); + // get a parachain into a bad state where they did not onboard let (para, _) = register_a_parathread::(1); Leases::::insert(para, vec![Some((account::("lease_insert", 0, 0), BalanceOf::::default()))]); From a50ca393df805c153e82675cba93e6096f9bb211 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Thu, 27 Apr 2023 03:17:38 +0400 Subject: [PATCH 05/13] fix bench --- runtime/common/src/auctions.rs | 40 +++++++---------- runtime/common/src/crowdloan/mod.rs | 63 +++++++-------------------- runtime/common/src/paras_registrar.rs | 46 +++++++------------ runtime/common/src/slots/mod.rs | 24 +++------- 4 files changed, 53 insertions(+), 120 deletions(-) diff --git a/runtime/common/src/auctions.rs b/runtime/common/src/auctions.rs index bbdbc0cd299c..3b1f941b5257 100644 --- a/runtime/common/src/auctions.rs +++ b/runtime/common/src/auctions.rs @@ -1731,17 +1731,16 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Auctions, *}; - use crate::mock::{conclude_pvf_checking, validators_public_keys}; - use frame_support::traits::{EnsureOrigin, OnInitialize}; + use frame_support::{ + assert_ok, + traits::{EnsureOrigin, OnInitialize}, + }; use frame_system::RawOrigin; - use runtime_parachains::{paras, shared}; - use sp_keyring::Sr25519Keyring; + use runtime_parachains::paras; use sp_runtime::{traits::Bounded, SaturatedConversion}; use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError}; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1750,12 +1749,9 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn fill_winners( - lease_period_index: LeasePeriodOf, - ) { + fn fill_winners(lease_period_index: LeasePeriodOf) { let auction_index = AuctionCounter::::get(); let minimum_balance = CurrencyOf::::minimum_balance(); - let session_index = shared::Pallet::::session_index(); for n in 1..=SlotRange::SLOT_RANGE_COUNT as u32 { let owner = account("owner", n, 0); @@ -1771,11 +1767,10 @@ mod benchmarking { ) .is_ok()); } - conclude_pvf_checking::( - &T::Registrar::worst_validation_code(), - VALIDATORS, - session_index, - ); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + T::Registrar::worst_validation_code(), + )); T::Registrar::execute_pending_transitions(); @@ -1799,7 +1794,7 @@ mod benchmarking { } benchmarks! { - where_clause { where T: pallet_babe::Config + paras::Config + shared::Config } + where_clause { where T: pallet_babe::Config + paras::Config } new_auction { let duration = T::BlockNumber::max_value(); @@ -1817,8 +1812,6 @@ mod benchmarking { // Worst case scenario a new bid comes in which kicks out an existing bid for the same slot. bid { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (_, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); @@ -1840,9 +1833,10 @@ mod benchmarking { let worst_validation_code = T::Registrar::worst_validation_code(); T::Registrar::register(owner.clone(), para, worst_head_data.clone(), worst_validation_code.clone())?; T::Registrar::register(owner, new_para, worst_head_data, worst_validation_code.clone())?; - - let session_index = shared::Pallet::::session_index(); - conclude_pvf_checking::(&T::Registrar::worst_validation_code(), VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + worst_validation_code, + )); T::Registrar::execute_pending_transitions(); @@ -1875,8 +1869,6 @@ mod benchmarking { // Worst case: 10 bidders taking all wining spots, and we need to calculate the winner for auction end. // Entire winner map should be full and removed at the end of the benchmark. on_initialize { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (lease_length, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); @@ -1922,8 +1914,6 @@ mod benchmarking { // Worst case: 10 bidders taking all wining spots, and winning data is full. cancel_auction { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); // If there is an offset, we need to be on that block to be able to do lease things. let (lease_length, offset) = T::Leaser::lease_period_length(); frame_system::Pallet::::set_block_number(offset + One::one()); diff --git a/runtime/common/src/crowdloan/mod.rs b/runtime/common/src/crowdloan/mod.rs index be92415da489..737a36989964 100644 --- a/runtime/common/src/crowdloan/mod.rs +++ b/runtime/common/src/crowdloan/mod.rs @@ -1951,19 +1951,15 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Crowdloan, *}; - use crate::mock::{conclude_pvf_checking, validators_public_keys}; use frame_support::{assert_ok, traits::OnInitialize}; use frame_system::RawOrigin; - use runtime_parachains::{paras, shared}; + use runtime_parachains::paras; use sp_core::crypto::UncheckedFrom; - use sp_keyring::Sr25519Keyring; use sp_runtime::traits::{Bounded, CheckedSub}; use sp_std::prelude::*; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1972,10 +1968,7 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn create_fund( - id: u32, - end: T::BlockNumber, - ) -> ParaId { + fn create_fund(id: u32, end: T::BlockNumber) -> ParaId { let cap = BalanceOf::::max_value(); let (_, offset) = T::Auctioneer::lease_period_length(); // Set to the very beginning of lease period index 0. @@ -1993,7 +1986,6 @@ mod benchmarking { // Assume ed25519 is most complex signature format let pubkey = crypto::create_ed25519_pubkey(b"//verifier".to_vec()); - let session_index = shared::Pallet::::session_index(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); assert_ok!(T::Registrar::register( @@ -2002,8 +1994,10 @@ mod benchmarking { head_data, validation_code.clone() )); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); - + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); T::Registrar::execute_pending_transitions(); assert_ok!(Crowdloan::::create( @@ -2036,12 +2030,9 @@ mod benchmarking { } benchmarks! { - where_clause { where T: paras::Config + shared::Config } + where_clause { where T: paras::Config } create { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para_id = ParaId::from(1_u32); let cap = BalanceOf::::max_value(); let first_period = 0u32.into(); @@ -2050,7 +2041,6 @@ mod benchmarking { let end = lpl + offset; let caller: T::AccountId = whitelisted_caller(); - let session_index = shared::Pallet::::session_index(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); @@ -2058,7 +2048,11 @@ mod benchmarking { CurrencyOf::::make_free_balance_be(&caller, BalanceOf::::max_value()); T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?; - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); + T::Registrar::execute_pending_transitions(); }: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier)) @@ -2068,9 +2062,6 @@ mod benchmarking { // Contribute has two arms: PreEnding and Ending, but both are equal complexity. contribute { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2091,9 +2082,6 @@ mod benchmarking { } withdraw { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2110,10 +2098,6 @@ mod benchmarking { #[skip_meta] refund { let k in 0 .. T::RemoveKeysLimit::get(); - - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2123,7 +2107,6 @@ mod benchmarking { contribute_fund::(&account("contributor", i, 0), fund_index); } - let caller: T::AccountId = whitelisted_caller(); frame_system::Pallet::::set_block_number(T::BlockNumber::max_value()); }: _(RawOrigin::Signed(caller), fund_index) @@ -2132,9 +2115,6 @@ mod benchmarking { } dissolve { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1337, end); @@ -2146,9 +2126,6 @@ mod benchmarking { } edit { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para_id = ParaId::from(1_u32); let cap = BalanceOf::::max_value(); let first_period = 0u32.into(); @@ -2159,13 +2136,15 @@ mod benchmarking { let caller: T::AccountId = whitelisted_caller(); let head_data = T::Registrar::worst_head_data(); let validation_code = T::Registrar::worst_validation_code(); - let session_index = shared::Pallet::::session_index(); let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0)); CurrencyOf::::make_free_balance_be(&caller, BalanceOf::::max_value()); T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?; - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); T::Registrar::execute_pending_transitions(); @@ -2181,9 +2160,6 @@ mod benchmarking { } add_memo { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2200,9 +2176,6 @@ mod benchmarking { } poke { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end = lpl + offset; let fund_index = create_fund::(1, end); @@ -2222,10 +2195,6 @@ mod benchmarking { on_initialize { // We test the complexity over different number of new raise let n in 2 .. 100; - - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let (lpl, offset) = T::Auctioneer::lease_period_length(); let end_block = lpl + offset - 1u32.into(); diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 9ace5234bb4b..f38dafa590b4 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -1337,21 +1337,15 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Registrar, *}; - use crate::{ - mock::{conclude_pvf_checking, validators_public_keys}, - traits::Registrar as RegistrarT, - }; + use crate::traits::Registrar as RegistrarT; use frame_support::assert_ok; use frame_system::RawOrigin; use primitives::{MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE}; use runtime_parachains::{paras, shared, Origin as ParaOrigin}; - use sp_keyring::Sr25519Keyring; use sp_runtime::traits::Bounded; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1360,9 +1354,8 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn register_para(id: u32) -> ParaId { + fn register_para(id: u32) -> ParaId { let para = ParaId::from(id); - let session_index = shared::Pallet::::session_index(); let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); let caller: T::AccountId = whitelisted_caller(); @@ -1374,7 +1367,10 @@ mod benchmarking { genesis_head, validation_code.clone() )); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); return para } @@ -1389,11 +1385,7 @@ mod benchmarking { } benchmarks! { - where_clause { - where - ParaOrigin: Into<::RuntimeOrigin>, - T: paras::Config + shared::Config, - } + where_clause { where ParaOrigin: Into<::RuntimeOrigin> } reserve { let caller: T::AccountId = whitelisted_caller(); @@ -1406,9 +1398,6 @@ mod benchmarking { } register { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para = LOWEST_PUBLIC_ID; let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); @@ -1419,16 +1408,15 @@ mod benchmarking { verify { assert_last_event::(Event::::Registered{ para_id: para, manager: caller }.into()); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - let session_index = shared::Pallet::::session_index(); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); } force_register { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let manager: T::AccountId = account("manager", 0, 0); let deposit = 0u32.into(); let para = ParaId::from(69); @@ -1438,16 +1426,15 @@ mod benchmarking { verify { assert_last_event::(Event::::Registered { para_id: para, manager }.into()); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - let session_index = shared::Pallet::::session_index(); - conclude_pvf_checking::(&validation_code, VALIDATORS, session_index); + assert_ok!(runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + )); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); } deregister { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let para = register_para::(LOWEST_PUBLIC_ID.into()); next_scheduled_session::(); let caller: T::AccountId = whitelisted_caller(); @@ -1457,9 +1444,6 @@ mod benchmarking { } swap { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let parathread = register_para::(LOWEST_PUBLIC_ID.into()); let parachain = register_para::((LOWEST_PUBLIC_ID + 1).into()); diff --git a/runtime/common/src/slots/mod.rs b/runtime/common/src/slots/mod.rs index 8d8b4f4f2e63..162d3031855a 100644 --- a/runtime/common/src/slots/mod.rs +++ b/runtime/common/src/slots/mod.rs @@ -986,19 +986,15 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::*; - use crate::mock::{conclude_pvf_checking, validators_public_keys}; use frame_support::assert_ok; use frame_system::RawOrigin; - use runtime_parachains::{paras, shared}; - use sp_keyring::Sr25519Keyring; + use runtime_parachains::paras; use sp_runtime::traits::{Bounded, One}; use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError}; use crate::slots::Pallet as Slots; - const VALIDATORS: &[Sr25519Keyring] = &[Sr25519Keyring::Alice]; - fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); let system_event: ::RuntimeEvent = generic_event.into(); @@ -1007,10 +1003,7 @@ mod benchmarking { assert_eq!(event, &system_event); } - fn register_a_parathread( - i: u32, - ) -> (ParaId, T::AccountId) { - let session_index = shared::Pallet::::session_index(); + fn register_a_parathread(i: u32) -> (ParaId, T::AccountId) { let para = ParaId::from(i); let leaser: T::AccountId = account("leaser", i, 0); T::Currency::make_free_balance_be(&leaser, BalanceOf::::max_value()); @@ -1023,7 +1016,10 @@ mod benchmarking { worst_head_data, worst_validation_code.clone(), )); - conclude_pvf_checking::(&worst_validation_code, VALIDATORS, session_index); + assert_ok!(paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + worst_validation_code, + )); T::Registrar::execute_pending_transitions(); @@ -1031,7 +1027,7 @@ mod benchmarking { } benchmarks! { - where_clause { where T: paras::Config + shared::Config } + where_clause { where T: paras::Config } force_lease { // If there is an offset, we need to be on that block to be able to do lease things. @@ -1061,9 +1057,6 @@ mod benchmarking { let c in 0 .. 100; let t in 0 .. 100; - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - let period_begin = 1u32.into(); let period_count = 4u32.into(); @@ -1153,9 +1146,6 @@ mod benchmarking { } trigger_onboard { - let public = validators_public_keys(VALIDATORS); - shared::Pallet::::set_active_validators_ascending(public); - // get a parachain into a bad state where they did not onboard let (para, _) = register_a_parathread::(1); Leases::::insert(para, vec![Some((account::("lease_insert", 0, 0), BalanceOf::::default()))]); From 09927f901a2d970ab95b06c5e0b89168d5502e88 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Thu, 27 Apr 2023 11:18:05 +0400 Subject: [PATCH 06/13] bypass prechecking in test node --- node/test/service/src/lib.rs | 28 ++++++++++++++++++++++------ runtime/parachains/src/paras/mod.rs | 3 ++- runtime/test-runtime/src/lib.rs | 1 + 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/node/test/service/src/lib.rs b/node/test/service/src/lib.rs index 4039f407ee39..7b3f5b60efac 100644 --- a/node/test/service/src/lib.rs +++ b/node/test/service/src/lib.rs @@ -32,8 +32,8 @@ use polkadot_service::{ ClientHandle, Error, ExecuteWithClient, FullClient, IsCollator, NewFull, PrometheusConfig, }; use polkadot_test_runtime::{ - ParasSudoWrapperCall, Runtime, SignedExtra, SignedPayload, SudoCall, UncheckedExtrinsic, - VERSION, + ParasCall, ParasSudoWrapperCall, Runtime, SignedExtra, SignedPayload, SudoCall, + UncheckedExtrinsic, VERSION, }; use sc_chain_spec::ChainSpec; use sc_client_api::execution_extensions::ExecutionStrategies; @@ -283,6 +283,19 @@ pub struct PolkadotTestNode { } impl PolkadotTestNode { + /// Send a sudo call to this node. + async fn send_sudo( + &self, + call: impl Into, + caller: Sr25519Keyring, + nonce: u32, + ) -> Result<(), RpcTransactionError> { + let sudo = SudoCall::sudo { call: Box::new(call.into()) }; + + let extrinsic = construct_extrinsic(&*self.client, sudo, caller, nonce); + self.rpc_handlers.send_transaction(extrinsic.into()).await.map(drop) + } + /// Send an extrinsic to this node. pub async fn send_extrinsic( &self, @@ -301,18 +314,21 @@ impl PolkadotTestNode { validation_code: impl Into, genesis_head: impl Into, ) -> Result<(), RpcTransactionError> { + let validation_code: ValidationCode = validation_code.into(); let call = ParasSudoWrapperCall::sudo_schedule_para_initialize { id, genesis: ParaGenesisArgs { genesis_head: genesis_head.into(), - validation_code: validation_code.into(), + validation_code: validation_code.clone(), para_kind: ParaKind::Parachain, }, }; - self.send_extrinsic(SudoCall::sudo { call: Box::new(call.into()) }, Sr25519Keyring::Alice) - .await - .map(drop) + self.send_sudo(call, Sr25519Keyring::Alice, 0).await?; + + // Bypass pvf-checking. + let call = ParasCall::add_trusted_validation_code { validation_code }; + self.send_sudo(call, Sr25519Keyring::Alice, 1).await } /// Wait for `count` blocks to be imported in the node and then exit. This function will not return if no blocks diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index d5731e6c605b..77cfbae5c8b9 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -501,7 +501,8 @@ impl WeightInfo for TestWeightInfo { Weight::MAX } fn add_trusted_validation_code(_c: u32) -> Weight { - Weight::MAX + // Called during integration tests for para initialization. + Weight::zero() } fn poke_unused_validation_code() -> Weight { Weight::MAX diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index fb114df2ee46..0bf776c019ad 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -79,6 +79,7 @@ pub use pallet_balances::Call as BalancesCall; pub use pallet_staking::StakerStatus; pub use pallet_sudo::Call as SudoCall; pub use pallet_timestamp::Call as TimestampCall; +pub use parachains_paras::Call as ParasCall; pub use paras_sudo_wrapper::Call as ParasSudoWrapperCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; From 44c414e6acd9b368c82fd94de7b02cff60df107b Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Tue, 2 May 2023 23:38:26 +0400 Subject: [PATCH 07/13] adjust bench --- runtime/parachains/src/paras/benchmarking.rs | 2 ++ .../src/paras/benchmarking/pvf_check.rs | 32 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/runtime/parachains/src/paras/benchmarking.rs b/runtime/parachains/src/paras/benchmarking.rs index b3dbb628965d..8faf8d67f7fd 100644 --- a/runtime/parachains/src/paras/benchmarking.rs +++ b/runtime/parachains/src/paras/benchmarking.rs @@ -137,6 +137,8 @@ benchmarks! { add_trusted_validation_code { let c in 1 .. MAX_CODE_SIZE; let new_code = ValidationCode(vec![0; c as usize]); + + pvf_check::prepare_bypassing_bench::(new_code.clone()); }: _(RawOrigin::Root, new_code) poke_unused_validation_code { diff --git a/runtime/parachains/src/paras/benchmarking/pvf_check.rs b/runtime/parachains/src/paras/benchmarking/pvf_check.rs index d13ce1a4ae2c..045e965f92e4 100644 --- a/runtime/parachains/src/paras/benchmarking/pvf_check.rs +++ b/runtime/parachains/src/paras/benchmarking/pvf_check.rs @@ -17,6 +17,7 @@ //! This module focuses on the benchmarking of the `include_pvf_check_statement` dispatchable. use crate::{configuration, paras::*, shared::Pallet as ParasShared}; +use frame_support::assert_ok; use frame_system::RawOrigin; use primitives::{HeadData, Id as ParaId, ValidationCode, ValidatorId, ValidatorIndex}; use sp_application_crypto::RuntimeAppPublic; @@ -43,7 +44,7 @@ where { initialize::(); // we do not plan to trigger finalization, thus the cause is inconsequential. - initialize_pvf_active_vote::(VoteCause::Onboarding); + initialize_pvf_active_vote::(VoteCause::Onboarding, CAUSES_NUM); // `unwrap` cannot panic here since the `initialize` function should initialize validators count // to be more than 0. @@ -68,7 +69,7 @@ where T: Config + shared::Config, { initialize::(); - initialize_pvf_active_vote::(cause); + initialize_pvf_active_vote::(cause, CAUSES_NUM); let mut stmts = generate_statements::(outcome).collect::>(); // this should be ensured by the `initialize` function. @@ -85,6 +86,29 @@ where stmt_n_sig } +/// Prepares storage for invoking `add_trusted_validation_code` with several paras initializing to +/// the same code. +pub fn prepare_bypassing_bench(validation_code: ValidationCode) +where + T: Config + shared::Config, +{ + // Suppose a sensible number of paras initialize to the same code. + const PARAS_NUM: usize = 10; + + initialize::(); + for i in 0..PARAS_NUM { + let id = ParaId::from(i as u32); + assert_ok!(Pallet::::schedule_para_initialize( + id, + ParaGenesisArgs { + para_kind: ParaKind::Parachain, + genesis_head: HeadData(vec![1, 2, 3, 4]), + validation_code: validation_code.clone(), + }, + )); + } +} + /// What caused the PVF pre-checking vote? #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub enum VoteCause { @@ -122,11 +146,11 @@ where /// /// The subject of the vote (i.e. validation code) and the cause (upgrade/onboarding) is specified /// by the test setup. -fn initialize_pvf_active_vote(vote_cause: VoteCause) +fn initialize_pvf_active_vote(vote_cause: VoteCause, causes_num: usize) where T: Config + shared::Config, { - for i in 0..CAUSES_NUM { + for i in 0..causes_num { let id = ParaId::from(i as u32); if vote_cause == VoteCause::Upgrade { From caaac2f450defe488c75f685ef955a9286055e93 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 2 May 2023 21:54:25 +0000 Subject: [PATCH 08/13] ".git/.scripts/commands/bench/bench.sh" runtime polkadot runtime_parachains::paras --- .../src/weights/runtime_parachains_paras.rs | 155 +++++++++--------- 1 file changed, 77 insertions(+), 78 deletions(-) diff --git a/runtime/polkadot/src/weights/runtime_parachains_paras.rs b/runtime/polkadot/src/weights/runtime_parachains_paras.rs index 1d1bd21185d3..7defb66a4af4 100644 --- a/runtime/polkadot/src/weights/runtime_parachains_paras.rs +++ b/runtime/polkadot/src/weights/runtime_parachains_paras.rs @@ -17,29 +17,30 @@ //! Autogenerated weights for `runtime_parachains::paras` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-05-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm5`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("polkadot-dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot +// target/production/polkadot // benchmark // pallet -// --chain=polkadot-dev // --steps=50 // --repeat=20 -// --pallet=runtime_parachains::paras // --extrinsic=* // --execution=wasm // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json +// --pallet=runtime_parachains::paras +// --chain=polkadot-dev // --header=./file_header.txt -// --output=./runtime/polkadot/src/weights/runtime_parachains_paras.rs +// --output=./runtime/polkadot/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(missing_docs)] use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; @@ -64,11 +65,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `8309` // Estimated: `11774` - // Minimum execution time: 32_553_000 picoseconds. - Weight::from_parts(32_756_000, 0) + // Minimum execution time: 32_694_000 picoseconds. + Weight::from_parts(32_922_000, 0) .saturating_add(Weight::from_parts(0, 11774)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_957, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(1_979, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -79,11 +80,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_606_000 picoseconds. - Weight::from_parts(8_843_000, 0) + // Minimum execution time: 8_539_000 picoseconds. + Weight::from_parts(8_748_000, 0) .saturating_add(Weight::from_parts(0, 0)) // Standard Error: 2 - .saturating_add(Weight::from_parts(864, 0).saturating_mul(s.into())) + .saturating_add(Weight::from_parts(882, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Configuration ActiveConfig (r:1 w:0) @@ -94,32 +95,30 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras CurrentCodeHash (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeCooldowns (r:1 w:1) /// Proof Skipped: Paras UpgradeCooldowns (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras CodeByHash (r:1 w:1) /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras UpcomingUpgrades (r:1 w:1) - /// Proof Skipped: Paras UpcomingUpgrades (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Digest (r:1 w:1) - /// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) + /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras CodeByHashRefs (r:1 w:1) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras FutureCodeUpgrades (r:0 w:1) - /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeRestrictionSignal (r:0 w:1) /// Proof Skipped: Paras UpgradeRestrictionSignal (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn force_schedule_code_upgrade(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16765` - // Estimated: `20230` - // Minimum execution time: 60_112_000 picoseconds. - Weight::from_parts(60_521_000, 0) - .saturating_add(Weight::from_parts(0, 20230)) - // Standard Error: 2 - .saturating_add(Weight::from_parts(1_987, 0).saturating_mul(c.into())) + // Measured: `8694` + // Estimated: `12159` + // Minimum execution time: 51_492_000 picoseconds. + Weight::from_parts(51_683_000, 0) + .saturating_add(Weight::from_parts(0, 12159)) + // Standard Error: 1 + .saturating_add(Weight::from_parts(2_009, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(9)) - .saturating_add(T::DbWeight::get().writes(8)) + .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: Paras FutureCodeUpgrades (r:1 w:0) /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) @@ -132,11 +131,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `95` // Estimated: `3560` - // Minimum execution time: 14_802_000 picoseconds. - Weight::from_parts(14_961_000, 0) + // Minimum execution time: 14_471_000 picoseconds. + Weight::from_parts(14_720_000, 0) .saturating_add(Weight::from_parts(0, 3560)) // Standard Error: 2 - .saturating_add(Weight::from_parts(868, 0).saturating_mul(s.into())) + .saturating_add(Weight::from_parts(887, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -148,28 +147,34 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `4251` // Estimated: `7716` - // Minimum execution time: 20_603_000 picoseconds. - Weight::from_parts(20_988_000, 0) + // Minimum execution time: 20_295_000 picoseconds. + Weight::from_parts(20_587_000, 0) .saturating_add(Weight::from_parts(0, 7716)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras CodeByHash (r:1 w:1) - /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Configuration ActiveConfig (r:1 w:0) + /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) + /// Proof Skipped: ParasShared CurrentSessionIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras ActionsQueue (r:1 w:1) + /// Proof Skipped: Paras ActionsQueue (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn add_trusted_validation_code(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `28` - // Estimated: `3493` - // Minimum execution time: 9_017_000 picoseconds. - Weight::from_parts(9_203_000, 0) - .saturating_add(Weight::from_parts(0, 3493)) + // Measured: `925` + // Estimated: `4390` + // Minimum execution time: 85_377_000 picoseconds. + Weight::from_parts(69_772_527, 0) + .saturating_add(Weight::from_parts(0, 4390)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_965, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(Weight::from_parts(1_441, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: Paras CodeByHashRefs (r:1 w:0) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) @@ -179,14 +184,12 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `28` // Estimated: `3493` - // Minimum execution time: 6_910_000 picoseconds. - Weight::from_parts(7_219_000, 0) + // Minimum execution time: 6_677_000 picoseconds. + Weight::from_parts(6_911_000, 0) .saturating_add(Weight::from_parts(0, 3493)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -195,16 +198,14 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement() -> Weight { // Proof Size summary in bytes: - // Measured: `26948` - // Estimated: `30413` - // Minimum execution time: 92_251_000 picoseconds. - Weight::from_parts(93_638_000, 0) - .saturating_add(Weight::from_parts(0, 30413)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `26645` + // Estimated: `30110` + // Minimum execution time: 92_860_000 picoseconds. + Weight::from_parts(93_926_000, 0) + .saturating_add(Weight::from_parts(0, 30110)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -213,6 +214,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras PvfActiveVoteList (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Configuration ActiveConfig (r:1 w:0) + /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras UpcomingUpgrades (r:1 w:1) /// Proof Skipped: Paras UpcomingUpgrades (max_values: Some(1), max_size: None, mode: Measured) /// Storage: System Digest (r:1 w:1) @@ -223,14 +226,12 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `27502` // Estimated: `30967` - // Minimum execution time: 792_755_000 picoseconds. - Weight::from_parts(799_668_000, 0) + // Minimum execution time: 792_233_000 picoseconds. + Weight::from_parts(800_363_000, 0) .saturating_add(Weight::from_parts(0, 30967)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(104)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -239,16 +240,14 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement_finalize_upgrade_reject() -> Weight { // Proof Size summary in bytes: - // Measured: `27480` - // Estimated: `30945` - // Minimum execution time: 92_117_000 picoseconds. - Weight::from_parts(93_358_000, 0) - .saturating_add(Weight::from_parts(0, 30945)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `27177` + // Estimated: `30642` + // Minimum execution time: 88_272_000 picoseconds. + Weight::from_parts(89_916_000, 0) + .saturating_add(Weight::from_parts(0, 30642)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -257,20 +256,20 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras PvfActiveVoteList (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Configuration ActiveConfig (r:1 w:0) + /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras ActionsQueue (r:1 w:1) /// Proof Skipped: Paras ActionsQueue (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement_finalize_onboarding_accept() -> Weight { // Proof Size summary in bytes: // Measured: `26970` // Estimated: `30435` - // Minimum execution time: 625_094_000 picoseconds. - Weight::from_parts(633_347_000, 0) + // Minimum execution time: 623_703_000 picoseconds. + Weight::from_parts(630_875_000, 0) .saturating_add(Weight::from_parts(0, 30435)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -279,12 +278,12 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement_finalize_onboarding_reject() -> Weight { // Proof Size summary in bytes: - // Measured: `26948` - // Estimated: `30413` - // Minimum execution time: 91_139_000 picoseconds. - Weight::from_parts(92_235_000, 0) - .saturating_add(Weight::from_parts(0, 30413)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `26645` + // Estimated: `30110` + // Minimum execution time: 87_411_000 picoseconds. + Weight::from_parts(89_432_000, 0) + .saturating_add(Weight::from_parts(0, 30110)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } } From 4b23f8a398b4e273b5f37ed773c7ac13b8293912 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 2 May 2023 23:16:26 +0000 Subject: [PATCH 09/13] ".git/.scripts/commands/bench/bench.sh" runtime kusama runtime_parachains::paras --- .../src/weights/runtime_parachains_paras.rs | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/runtime/kusama/src/weights/runtime_parachains_paras.rs b/runtime/kusama/src/weights/runtime_parachains_paras.rs index afc83c21dc41..af2e10a3e1dc 100644 --- a/runtime/kusama/src/weights/runtime_parachains_paras.rs +++ b/runtime/kusama/src/weights/runtime_parachains_paras.rs @@ -17,29 +17,30 @@ //! Autogenerated weights for `runtime_parachains::paras` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-05-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm6`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot +// target/production/polkadot // benchmark // pallet -// --chain=kusama-dev // --steps=50 // --repeat=20 -// --pallet=runtime_parachains::paras // --extrinsic=* // --execution=wasm // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json +// --pallet=runtime_parachains::paras +// --chain=kusama-dev // --header=./file_header.txt -// --output=./runtime/kusama/src/weights/runtime_parachains_paras.rs +// --output=./runtime/kusama/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(missing_docs)] use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; @@ -64,11 +65,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `8309` // Estimated: `11774` - // Minimum execution time: 31_454_000 picoseconds. - Weight::from_parts(31_826_000, 0) + // Minimum execution time: 31_199_000 picoseconds. + Weight::from_parts(31_493_000, 0) .saturating_add(Weight::from_parts(0, 11774)) - // Standard Error: 3 - .saturating_add(Weight::from_parts(1_953, 0).saturating_mul(c.into())) + // Standard Error: 1 + .saturating_add(Weight::from_parts(1_976, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -79,11 +80,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_749_000 picoseconds. - Weight::from_parts(8_953_000, 0) + // Minimum execution time: 8_460_000 picoseconds. + Weight::from_parts(8_645_000, 0) .saturating_add(Weight::from_parts(0, 0)) // Standard Error: 2 - .saturating_add(Weight::from_parts(857, 0).saturating_mul(s.into())) + .saturating_add(Weight::from_parts(890, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Paras FutureCodeHash (r:1 w:1) @@ -92,32 +93,30 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras CurrentCodeHash (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeCooldowns (r:1 w:1) /// Proof Skipped: Paras UpgradeCooldowns (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras CodeByHash (r:1 w:1) /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras UpcomingUpgrades (r:1 w:1) - /// Proof Skipped: Paras UpcomingUpgrades (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Digest (r:1 w:1) - /// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) + /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras CodeByHashRefs (r:1 w:1) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras FutureCodeUpgrades (r:0 w:1) - /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeRestrictionSignal (r:0 w:1) /// Proof Skipped: Paras UpgradeRestrictionSignal (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn force_schedule_code_upgrade(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16462` - // Estimated: `19927` - // Minimum execution time: 55_906_000 picoseconds. - Weight::from_parts(56_178_000, 0) - .saturating_add(Weight::from_parts(0, 19927)) + // Measured: `8391` + // Estimated: `11856` + // Minimum execution time: 47_009_000 picoseconds. + Weight::from_parts(47_428_000, 0) + .saturating_add(Weight::from_parts(0, 11856)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_967, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(1_999, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(8)) - .saturating_add(T::DbWeight::get().writes(8)) + .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: Paras FutureCodeUpgrades (r:1 w:0) /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) @@ -130,11 +129,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `95` // Estimated: `3560` - // Minimum execution time: 13_961_000 picoseconds. - Weight::from_parts(14_114_000, 0) + // Minimum execution time: 13_825_000 picoseconds. + Weight::from_parts(13_969_000, 0) .saturating_add(Weight::from_parts(0, 3560)) // Standard Error: 2 - .saturating_add(Weight::from_parts(858, 0).saturating_mul(s.into())) + .saturating_add(Weight::from_parts(888, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -146,28 +145,32 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `4251` // Estimated: `7716` - // Minimum execution time: 20_280_000 picoseconds. - Weight::from_parts(20_641_000, 0) + // Minimum execution time: 19_150_000 picoseconds. + Weight::from_parts(19_571_000, 0) .saturating_add(Weight::from_parts(0, 7716)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras CodeByHash (r:1 w:1) - /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) + /// Proof Skipped: ParasShared CurrentSessionIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras ActionsQueue (r:1 w:1) + /// Proof Skipped: Paras ActionsQueue (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn add_trusted_validation_code(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `28` - // Estimated: `3493` - // Minimum execution time: 8_193_000 picoseconds. - Weight::from_parts(8_317_000, 0) - .saturating_add(Weight::from_parts(0, 3493)) + // Measured: `622` + // Estimated: `4087` + // Minimum execution time: 80_323_000 picoseconds. + Weight::from_parts(57_788_688, 0) + .saturating_add(Weight::from_parts(0, 4087)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_948, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(Weight::from_parts(1_449, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: Paras CodeByHashRefs (r:1 w:0) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) @@ -177,8 +180,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `28` // Estimated: `3493` - // Minimum execution time: 6_072_000 picoseconds. - Weight::from_parts(6_224_000, 0) + // Minimum execution time: 5_737_000 picoseconds. + Weight::from_parts(5_935_000, 0) .saturating_add(Weight::from_parts(0, 3493)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -193,8 +196,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `26645` // Estimated: `30110` - // Minimum execution time: 89_474_000 picoseconds. - Weight::from_parts(90_579_000, 0) + // Minimum execution time: 91_237_000 picoseconds. + Weight::from_parts(92_747_000, 0) .saturating_add(Weight::from_parts(0, 30110)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -217,8 +220,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `27199` // Estimated: `30664` - // Minimum execution time: 783_434_000 picoseconds. - Weight::from_parts(789_541_000, 0) + // Minimum execution time: 780_738_000 picoseconds. + Weight::from_parts(791_043_000, 0) .saturating_add(Weight::from_parts(0, 30664)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(104)) @@ -233,8 +236,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `27177` // Estimated: `30642` - // Minimum execution time: 87_212_000 picoseconds. - Weight::from_parts(89_108_000, 0) + // Minimum execution time: 87_301_000 picoseconds. + Weight::from_parts(88_560_000, 0) .saturating_add(Weight::from_parts(0, 30642)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -253,8 +256,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `26667` // Estimated: `30132` - // Minimum execution time: 624_548_000 picoseconds. - Weight::from_parts(628_911_000, 0) + // Minimum execution time: 620_267_000 picoseconds. + Weight::from_parts(628_507_000, 0) .saturating_add(Weight::from_parts(0, 30132)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) @@ -269,8 +272,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `26645` // Estimated: `30110` - // Minimum execution time: 86_738_000 picoseconds. - Weight::from_parts(87_816_000, 0) + // Minimum execution time: 86_924_000 picoseconds. + Weight::from_parts(87_727_000, 0) .saturating_add(Weight::from_parts(0, 30110)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) From f22e03edf3e74fd3a6d8bd248a623a7f2ca994cb Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 3 May 2023 07:03:35 +0000 Subject: [PATCH 10/13] ".git/.scripts/commands/bench/bench.sh" runtime rococo runtime_parachains::paras --- .../src/weights/runtime_parachains_paras.rs | 155 +++++++++--------- 1 file changed, 77 insertions(+), 78 deletions(-) diff --git a/runtime/rococo/src/weights/runtime_parachains_paras.rs b/runtime/rococo/src/weights/runtime_parachains_paras.rs index a2eb315ac2dc..9e4be969a3d7 100644 --- a/runtime/rococo/src/weights/runtime_parachains_paras.rs +++ b/runtime/rococo/src/weights/runtime_parachains_paras.rs @@ -17,29 +17,30 @@ //! Autogenerated weights for `runtime_parachains::paras` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-05-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm4`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("rococo-dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot +// target/production/polkadot // benchmark // pallet -// --chain=rococo-dev // --steps=50 // --repeat=20 -// --pallet=runtime_parachains::paras // --extrinsic=* // --execution=wasm // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json +// --pallet=runtime_parachains::paras +// --chain=rococo-dev // --header=./file_header.txt -// --output=./runtime/rococo/src/weights/runtime_parachains_paras.rs +// --output=./runtime/rococo/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(missing_docs)] use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; @@ -64,11 +65,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `8309` // Estimated: `11774` - // Minimum execution time: 32_230_000 picoseconds. - Weight::from_parts(32_484_000, 0) + // Minimum execution time: 32_367_000 picoseconds. + Weight::from_parts(32_540_000, 0) .saturating_add(Weight::from_parts(0, 11774)) - // Standard Error: 3 - .saturating_add(Weight::from_parts(1_972, 0).saturating_mul(c.into())) + // Standard Error: 1 + .saturating_add(Weight::from_parts(1_977, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -79,11 +80,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_577_000 picoseconds. - Weight::from_parts(8_741_000, 0) + // Minimum execution time: 8_523_000 picoseconds. + Weight::from_parts(8_633_000, 0) .saturating_add(Weight::from_parts(0, 0)) // Standard Error: 2 - .saturating_add(Weight::from_parts(857, 0).saturating_mul(s.into())) + .saturating_add(Weight::from_parts(882, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Configuration ActiveConfig (r:1 w:0) @@ -94,32 +95,30 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras CurrentCodeHash (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeCooldowns (r:1 w:1) /// Proof Skipped: Paras UpgradeCooldowns (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras CodeByHash (r:1 w:1) /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras UpcomingUpgrades (r:1 w:1) - /// Proof Skipped: Paras UpcomingUpgrades (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Digest (r:1 w:1) - /// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) + /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras CodeByHashRefs (r:1 w:1) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras FutureCodeUpgrades (r:0 w:1) - /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeRestrictionSignal (r:0 w:1) /// Proof Skipped: Paras UpgradeRestrictionSignal (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn force_schedule_code_upgrade(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16769` - // Estimated: `20234` - // Minimum execution time: 59_725_000 picoseconds. - Weight::from_parts(60_345_000, 0) - .saturating_add(Weight::from_parts(0, 20234)) + // Measured: `8698` + // Estimated: `12163` + // Minimum execution time: 50_830_000 picoseconds. + Weight::from_parts(50_953_000, 0) + .saturating_add(Weight::from_parts(0, 12163)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_981, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(2_008, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(9)) - .saturating_add(T::DbWeight::get().writes(8)) + .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: Paras FutureCodeUpgrades (r:1 w:0) /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) @@ -132,11 +131,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `95` // Estimated: `3560` - // Minimum execution time: 14_733_000 picoseconds. - Weight::from_parts(14_854_000, 0) + // Minimum execution time: 14_524_000 picoseconds. + Weight::from_parts(14_595_000, 0) .saturating_add(Weight::from_parts(0, 3560)) // Standard Error: 2 - .saturating_add(Weight::from_parts(863, 0).saturating_mul(s.into())) + .saturating_add(Weight::from_parts(886, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -148,28 +147,34 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `4251` // Estimated: `7716` - // Minimum execution time: 21_286_000 picoseconds. - Weight::from_parts(21_593_000, 0) + // Minimum execution time: 20_191_000 picoseconds. + Weight::from_parts(20_738_000, 0) .saturating_add(Weight::from_parts(0, 7716)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras CodeByHash (r:1 w:1) - /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Configuration ActiveConfig (r:1 w:0) + /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) + /// Proof Skipped: ParasShared CurrentSessionIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras ActionsQueue (r:1 w:1) + /// Proof Skipped: Paras ActionsQueue (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn add_trusted_validation_code(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `28` - // Estimated: `3493` - // Minimum execution time: 8_945_000 picoseconds. - Weight::from_parts(9_207_000, 0) - .saturating_add(Weight::from_parts(0, 3493)) + // Measured: `929` + // Estimated: `4394` + // Minimum execution time: 84_027_000 picoseconds. + Weight::from_parts(66_112_336, 0) + .saturating_add(Weight::from_parts(0, 4394)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_961, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(Weight::from_parts(1_446, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: Paras CodeByHashRefs (r:1 w:0) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) @@ -179,14 +184,12 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `28` // Estimated: `3493` - // Minimum execution time: 6_494_000 picoseconds. - Weight::from_parts(6_828_000, 0) + // Minimum execution time: 6_672_000 picoseconds. + Weight::from_parts(6_990_000, 0) .saturating_add(Weight::from_parts(0, 3493)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -195,16 +198,14 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement() -> Weight { // Proof Size summary in bytes: - // Measured: `26952` - // Estimated: `30417` - // Minimum execution time: 92_204_000 picoseconds. - Weight::from_parts(92_879_000, 0) - .saturating_add(Weight::from_parts(0, 30417)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `26645` + // Estimated: `30110` + // Minimum execution time: 92_650_000 picoseconds. + Weight::from_parts(93_865_000, 0) + .saturating_add(Weight::from_parts(0, 30110)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -213,6 +214,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras PvfActiveVoteList (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Configuration ActiveConfig (r:1 w:0) + /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras UpcomingUpgrades (r:1 w:1) /// Proof Skipped: Paras UpcomingUpgrades (max_values: Some(1), max_size: None, mode: Measured) /// Storage: System Digest (r:1 w:1) @@ -223,14 +226,12 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `27506` // Estimated: `30971` - // Minimum execution time: 780_344_000 picoseconds. - Weight::from_parts(789_583_000, 0) + // Minimum execution time: 772_011_000 picoseconds. + Weight::from_parts(782_508_000, 0) .saturating_add(Weight::from_parts(0, 30971)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(104)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -239,16 +240,14 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement_finalize_upgrade_reject() -> Weight { // Proof Size summary in bytes: - // Measured: `27484` - // Estimated: `30949` - // Minimum execution time: 91_535_000 picoseconds. - Weight::from_parts(92_909_000, 0) - .saturating_add(Weight::from_parts(0, 30949)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `27177` + // Estimated: `30642` + // Minimum execution time: 88_339_000 picoseconds. + Weight::from_parts(90_069_000, 0) + .saturating_add(Weight::from_parts(0, 30642)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -257,20 +256,20 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras PvfActiveVoteList (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Configuration ActiveConfig (r:1 w:0) + /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras ActionsQueue (r:1 w:1) /// Proof Skipped: Paras ActionsQueue (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement_finalize_onboarding_accept() -> Weight { // Proof Size summary in bytes: // Measured: `26974` // Estimated: `30439` - // Minimum execution time: 627_464_000 picoseconds. - Weight::from_parts(631_072_000, 0) + // Minimum execution time: 613_406_000 picoseconds. + Weight::from_parts(621_925_000, 0) .saturating_add(Weight::from_parts(0, 30439)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } - /// Storage: Configuration ActiveConfig (r:1 w:0) - /// Proof Skipped: Configuration ActiveConfig (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) @@ -279,12 +278,12 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) fn include_pvf_check_statement_finalize_onboarding_reject() -> Weight { // Proof Size summary in bytes: - // Measured: `26952` - // Estimated: `30417` - // Minimum execution time: 91_119_000 picoseconds. - Weight::from_parts(91_722_000, 0) - .saturating_add(Weight::from_parts(0, 30417)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `26645` + // Estimated: `30110` + // Minimum execution time: 87_629_000 picoseconds. + Weight::from_parts(89_057_000, 0) + .saturating_add(Weight::from_parts(0, 30110)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } } From 26277a6af6d56aa29fb896ca40940a79a1256379 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 3 May 2023 10:59:43 +0000 Subject: [PATCH 11/13] ".git/.scripts/commands/bench/bench.sh" runtime westend runtime_parachains::paras --- .../src/weights/runtime_parachains_paras.rs | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/runtime/westend/src/weights/runtime_parachains_paras.rs b/runtime/westend/src/weights/runtime_parachains_paras.rs index 012412a1d660..7d5685c30d0e 100644 --- a/runtime/westend/src/weights/runtime_parachains_paras.rs +++ b/runtime/westend/src/weights/runtime_parachains_paras.rs @@ -17,29 +17,30 @@ //! Autogenerated weights for `runtime_parachains::paras` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-05-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm6`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot +// target/production/polkadot // benchmark // pallet -// --chain=westend-dev // --steps=50 // --repeat=20 -// --pallet=runtime_parachains::paras // --extrinsic=* // --execution=wasm // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json +// --pallet=runtime_parachains::paras +// --chain=westend-dev // --header=./file_header.txt -// --output=./runtime/westend/src/weights/runtime_parachains_paras.rs +// --output=./runtime/westend/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(missing_docs)] use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; @@ -64,11 +65,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `8309` // Estimated: `11774` - // Minimum execution time: 32_720_000 picoseconds. - Weight::from_parts(33_199_000, 0) + // Minimum execution time: 31_695_000 picoseconds. + Weight::from_parts(31_903_000, 0) .saturating_add(Weight::from_parts(0, 11774)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_947, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(1_979, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -79,11 +80,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_146_000 picoseconds. - Weight::from_parts(9_372_000, 0) + // Minimum execution time: 8_642_000 picoseconds. + Weight::from_parts(8_730_000, 0) .saturating_add(Weight::from_parts(0, 0)) // Standard Error: 2 - .saturating_add(Weight::from_parts(857, 0).saturating_mul(s.into())) + .saturating_add(Weight::from_parts(890, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Paras FutureCodeHash (r:1 w:1) @@ -92,32 +93,30 @@ impl runtime_parachains::paras::WeightInfo for WeightIn /// Proof Skipped: Paras CurrentCodeHash (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeCooldowns (r:1 w:1) /// Proof Skipped: Paras UpgradeCooldowns (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) /// Storage: Paras CodeByHash (r:1 w:1) /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras UpcomingUpgrades (r:1 w:1) - /// Proof Skipped: Paras UpcomingUpgrades (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Digest (r:1 w:1) - /// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared ActiveValidatorKeys (r:1 w:0) + /// Proof Skipped: ParasShared ActiveValidatorKeys (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Paras CodeByHashRefs (r:1 w:1) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras FutureCodeUpgrades (r:0 w:1) - /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) /// Storage: Paras UpgradeRestrictionSignal (r:0 w:1) /// Proof Skipped: Paras UpgradeRestrictionSignal (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn force_schedule_code_upgrade(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16462` - // Estimated: `19927` - // Minimum execution time: 57_014_000 picoseconds. - Weight::from_parts(57_397_000, 0) - .saturating_add(Weight::from_parts(0, 19927)) + // Measured: `8391` + // Estimated: `11856` + // Minimum execution time: 46_791_000 picoseconds. + Weight::from_parts(47_083_000, 0) + .saturating_add(Weight::from_parts(0, 11856)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_967, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(2_011, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(8)) - .saturating_add(T::DbWeight::get().writes(8)) + .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: Paras FutureCodeUpgrades (r:1 w:0) /// Proof Skipped: Paras FutureCodeUpgrades (max_values: None, max_size: None, mode: Measured) @@ -130,11 +129,11 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `95` // Estimated: `3560` - // Minimum execution time: 14_407_000 picoseconds. - Weight::from_parts(14_619_000, 0) + // Minimum execution time: 13_939_000 picoseconds. + Weight::from_parts(14_133_000, 0) .saturating_add(Weight::from_parts(0, 3560)) - // Standard Error: 1 - .saturating_add(Weight::from_parts(859, 0).saturating_mul(s.into())) + // Standard Error: 2 + .saturating_add(Weight::from_parts(901, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -146,28 +145,32 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `4251` // Estimated: `7716` - // Minimum execution time: 20_892_000 picoseconds. - Weight::from_parts(21_330_000, 0) + // Minimum execution time: 19_323_000 picoseconds. + Weight::from_parts(19_629_000, 0) .saturating_add(Weight::from_parts(0, 7716)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Paras PvfActiveVoteMap (r:1 w:0) + /// Storage: Paras PvfActiveVoteMap (r:1 w:1) /// Proof Skipped: Paras PvfActiveVoteMap (max_values: None, max_size: None, mode: Measured) - /// Storage: Paras CodeByHash (r:1 w:1) - /// Proof Skipped: Paras CodeByHash (max_values: None, max_size: None, mode: Measured) + /// Storage: Paras PvfActiveVoteList (r:1 w:1) + /// Proof Skipped: Paras PvfActiveVoteList (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParasShared CurrentSessionIndex (r:1 w:0) + /// Proof Skipped: ParasShared CurrentSessionIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Paras ActionsQueue (r:1 w:1) + /// Proof Skipped: Paras ActionsQueue (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 3145728]`. fn add_trusted_validation_code(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `28` - // Estimated: `3493` - // Minimum execution time: 8_643_000 picoseconds. - Weight::from_parts(8_743_000, 0) - .saturating_add(Weight::from_parts(0, 3493)) + // Measured: `622` + // Estimated: `4087` + // Minimum execution time: 81_851_000 picoseconds. + Weight::from_parts(65_672_617, 0) + .saturating_add(Weight::from_parts(0, 4087)) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_949, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(Weight::from_parts(1_442, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: Paras CodeByHashRefs (r:1 w:0) /// Proof Skipped: Paras CodeByHashRefs (max_values: None, max_size: None, mode: Measured) @@ -177,8 +180,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `28` // Estimated: `3493` - // Minimum execution time: 6_322_000 picoseconds. - Weight::from_parts(6_500_000, 0) + // Minimum execution time: 5_926_000 picoseconds. + Weight::from_parts(6_126_000, 0) .saturating_add(Weight::from_parts(0, 3493)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -193,8 +196,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `26645` // Estimated: `30110` - // Minimum execution time: 88_015_000 picoseconds. - Weight::from_parts(89_436_000, 0) + // Minimum execution time: 91_618_000 picoseconds. + Weight::from_parts(92_712_000, 0) .saturating_add(Weight::from_parts(0, 30110)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -217,8 +220,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `27199` // Estimated: `30664` - // Minimum execution time: 799_995_000 picoseconds. - Weight::from_parts(806_270_000, 0) + // Minimum execution time: 773_592_000 picoseconds. + Weight::from_parts(781_309_000, 0) .saturating_add(Weight::from_parts(0, 30664)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(104)) @@ -233,8 +236,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `27177` // Estimated: `30642` - // Minimum execution time: 87_373_000 picoseconds. - Weight::from_parts(88_419_000, 0) + // Minimum execution time: 86_554_000 picoseconds. + Weight::from_parts(88_691_000, 0) .saturating_add(Weight::from_parts(0, 30642)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -253,8 +256,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `26667` // Estimated: `30132` - // Minimum execution time: 632_844_000 picoseconds. - Weight::from_parts(641_036_000, 0) + // Minimum execution time: 617_351_000 picoseconds. + Weight::from_parts(621_906_000, 0) .saturating_add(Weight::from_parts(0, 30132)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) @@ -269,8 +272,8 @@ impl runtime_parachains::paras::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `26645` // Estimated: `30110` - // Minimum execution time: 86_854_000 picoseconds. - Weight::from_parts(88_145_000, 0) + // Minimum execution time: 85_943_000 picoseconds. + Weight::from_parts(87_442_000, 0) .saturating_add(Weight::from_parts(0, 30110)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) From 8bc1b33aa188f34a5563dbf5ebfba57c110322c2 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Wed, 3 May 2023 19:53:20 +0400 Subject: [PATCH 12/13] use test helper --- runtime/parachains/src/paras/tests.rs | 88 ++++++++------------------- 1 file changed, 24 insertions(+), 64 deletions(-) diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index c69c68d1f68e..1acd88094124 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -55,6 +55,22 @@ fn sign_and_include_pvf_check_statement(stmt: PvfCheckStatement) { Paras::include_pvf_check_statement(None.into(), stmt, signature.into()).unwrap(); } +fn submit_super_majority_pvf_votes( + validation_code: &ValidationCode, + session_index: SessionIndex, + accept: bool, +) { + [0, 1, 2, 3] + .into_iter() + .map(|i| PvfCheckStatement { + accept, + subject: validation_code.hash(), + session_index, + validator_index: i.into(), + }) + .for_each(sign_and_include_pvf_check_statement); +} + fn run_to_block(to: BlockNumber, new_session: Option>) { let keystore: KeystorePtr = Arc::new(LocalKeystore::in_memory()); for validator in VALIDATORS.iter() { @@ -431,14 +447,7 @@ fn code_upgrade_applied_after_delay() { let next_possible_upgrade_at = 1 + validation_upgrade_cooldown; Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); // Include votes for super-majority. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: new_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&new_code, EXPECTED_SESSION, true); Paras::note_new_head(para_id, Default::default(), 1); @@ -538,14 +547,7 @@ fn code_upgrade_applied_after_delay_even_when_late() { let next_possible_upgrade_at = 1 + validation_upgrade_cooldown; Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); // Include votes for super-majority. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: new_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&new_code, EXPECTED_SESSION, true); Paras::note_new_head(para_id, Default::default(), 1); @@ -625,14 +627,7 @@ fn submit_code_change_when_not_allowed_is_err() { Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); // Include votes for super-majority. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: new_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&new_code, EXPECTED_SESSION, true); assert_eq!(FutureCodeUpgrades::::get(¶_id), Some(1 + validation_upgrade_delay)); assert_eq!(FutureCodeHash::::get(¶_id), Some(new_code.hash())); @@ -703,14 +698,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { Paras::schedule_code_upgrade(para_id, new_code.clone(), 0, &Configuration::config()); // Include votes for super-majority. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: new_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&new_code, EXPECTED_SESSION, true); Paras::note_new_head(para_id, dummy_head_data(), 0); assert_eq!( @@ -784,14 +772,7 @@ fn full_parachain_cleanup_storage() { let expected_at = 1 + validation_upgrade_delay; Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config()); // Include votes for super-majority. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: new_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&new_code, EXPECTED_SESSION, true); Paras::note_new_head(para_id, Default::default(), 1); @@ -895,14 +876,7 @@ fn cannot_offboard_ongoing_pvf_check() { assert_err!(Paras::schedule_para_cleanup(para_id), Error::::CannotOffboard); // Include votes for super-majority. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: new_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&new_code, EXPECTED_SESSION, true); // Voting concluded, can offboard even though an upgrade is in progress. assert_ok!(Paras::schedule_para_cleanup(para_id)); @@ -1057,14 +1031,7 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { let new_code: ValidationCode = vec![4, 5, 6].into(); Paras::schedule_code_upgrade(para_id, new_code.clone(), 0, &Configuration::config()); // Include votes for super-majority. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: new_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&new_code, EXPECTED_SESSION, true); // The new validation code can be applied but a new parablock hasn't gotten in yet, // so the old code should still be current. @@ -1179,14 +1146,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { assert!(!Paras::pvfs_require_precheck().is_empty()); // Supermajority of validators vote for `validation_code`. It should be approved. - IntoIterator::into_iter([0, 1, 2, 3]) - .map(|i| PvfCheckStatement { - accept: true, - subject: validation_code.hash(), - session_index: EXPECTED_SESSION, - validator_index: i.into(), - }) - .for_each(sign_and_include_pvf_check_statement); + submit_super_majority_pvf_votes(&validation_code, EXPECTED_SESSION, true); // Check that `b` actually onboards. assert_eq!(ActionsQueue::::get(EXPECTED_SESSION + 2), vec![b]); From 733661240271bbd9e71d58e26926bb10309d2093 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Mon, 8 May 2023 21:30:24 +0400 Subject: [PATCH 13/13] fix new test --- runtime/common/src/paras_registrar.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 81e2dde7102a..6394a413f385 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -1204,15 +1204,17 @@ mod tests { // Parachain to parachain swap let para_3 = LOWEST_PUBLIC_ID + 2; + let validation_code = test_validation_code(max_code_size() as usize); assert_ok!(Registrar::reserve(RuntimeOrigin::signed(3))); assert_ok!(Registrar::register( RuntimeOrigin::signed(3), para_3, test_genesis_head(max_head_size() as usize), - test_validation_code(max_code_size() as usize), + validation_code.clone(), )); + conclude_pvf_checking::(&validation_code, VALIDATORS, START_SESSION_INDEX + 6); - run_to_session(8); + run_to_session(START_SESSION_INDEX + 8); // Upgrade para 3 into a parachain assert_ok!(Registrar::make_parachain(para_3)); @@ -1222,7 +1224,7 @@ mod tests { swap_data.insert(para_3, 777); SwapData::set(swap_data); - run_to_session(10); + run_to_session(START_SESSION_INDEX + 10); // Both are parachains assert!(Parachains::is_parachain(para_3));