paras: dismiss pvf_checking_enabled configuration (#7138)

* paras: unconditionally precheck pvfs

* Update integration tests

* paras_registrar tests

* runtime benchmark tests

* fix bench

* bypass prechecking in test node

* adjust bench

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot runtime_parachains::paras

* ".git/.scripts/commands/bench/bench.sh" runtime kusama runtime_parachains::paras

* ".git/.scripts/commands/bench/bench.sh" runtime rococo runtime_parachains::paras

* ".git/.scripts/commands/bench/bench.sh" runtime westend runtime_parachains::paras

* use test helper

* fix new test

---------

Co-authored-by: command-bot <>
This commit is contained in:
Chris Sosnin
2023-05-08 21:58:55 +03:00
committed by GitHub
parent 580111dd98
commit 9c08536d5f
22 changed files with 716 additions and 464 deletions
+112 -35
View File
@@ -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},
@@ -31,12 +33,15 @@ 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, 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,9 +303,21 @@ 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::<Test>::set_session_index(shared::Pallet::<Test>::session_index() + 1);
let session_index = shared::Pallet::<Test>::session_index() + 1;
let validators_pub_keys = validators_public_keys(VALIDATORS);
shared::Pallet::<Test>::set_session_index(session_index);
shared::Pallet::<Test>::set_active_validators_ascending(validators_pub_keys);
Paras::test_on_new_session();
}
}
@@ -357,6 +374,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 +391,7 @@ fn basic_end_to_end_works() {
genesis_head.clone(),
validation_code.clone(),
));
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
assert_ok!(Registrar::reserve(signed(2)));
assert_ok!(Registrar::register(
signed(2),
@@ -392,7 +414,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 +433,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 +453,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::<Test>::HandleBidResult {
para_id: ParaId::from(para_2),
@@ -439,7 +461,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::<Test>::AuctionClosed { auction_index: 1 }.into()
@@ -473,7 +495,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 +609,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::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
// Start a new auction in the future
let duration = 149u32;
@@ -611,7 +638,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 +672,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 +710,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::<Test>(&validation_code, VALIDATORS, 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 +817,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::<Test>(&validation_code, VALIDATORS, 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::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
// Paras should be onboarding
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding));
@@ -818,7 +859,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 +979,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::<Test>(&validation_code, VALIDATORS, 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::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
// Paras should be onboarding
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding));
@@ -1107,24 +1157,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::<Test>(&validation_code, VALIDATORS, 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::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
// Paras should be onboarding
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding));
@@ -1132,6 +1192,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(),
@@ -1140,7 +1201,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));
@@ -1179,9 +1240,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::<u32>::EndingPeriod(0, 0));
assert_eq!(Auctions::auction_status(ends_at), AuctionStatus::<u32>::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));
@@ -1190,13 +1251,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] =
@@ -1210,6 +1271,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;
@@ -1234,13 +1298,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::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
// Still can't bid until it is fully onboarded
assert_noop!(
@@ -1256,7 +1322,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);
@@ -1276,6 +1342,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;
@@ -1288,23 +1357,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::<Test>(&validation_code, VALIDATORS, 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);
@@ -1359,7 +1430,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!(
@@ -1457,15 +1528,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::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
// Start a new auction in the future
let starting_block = System::block_number();
@@ -1478,7 +1555,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(