From c12568180e46bd0ebaeaf7e406c6d22b3e5de0f5 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Thu, 27 Oct 2022 12:35:46 +0200 Subject: [PATCH 01/16] Replace parachain/parathread boolean by enum --- runtime/common/src/paras_registrar.rs | 7 ++++--- runtime/parachains/src/paras/mod.rs | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 7245cd92d304..118c3c083581 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -35,6 +35,7 @@ use sp_std::{prelude::*, result}; use crate::traits::{OnSwap, Registrar}; pub use pallet::*; use parity_scale_codec::{Decode, Encode}; +use runtime_parachains::paras::ParaType; use scale_info::TypeInfo; use sp_runtime::{ traits::{CheckedSub, Saturating}, @@ -570,7 +571,7 @@ impl Pallet { }; ensure!(paras::Pallet::::lifecycle(id).is_none(), Error::::AlreadyRegistered); let (genesis, deposit) = - Self::validate_onboarding_data(genesis_head, validation_code, false)?; + Self::validate_onboarding_data(genesis_head, validation_code, ParaType::ParaThread)?; let deposit = deposit_override.unwrap_or(deposit); if let Some(additional) = deposit.checked_sub(&deposited) { @@ -613,7 +614,7 @@ impl Pallet { fn validate_onboarding_data( genesis_head: HeadData, validation_code: ValidationCode, - parachain: bool, + paratype: ParaType, ) -> Result<(ParaGenesisArgs, BalanceOf), sp_runtime::DispatchError> { let config = configuration::Pallet::::config(); ensure!(validation_code.0.len() > 0, Error::::EmptyCode); @@ -628,7 +629,7 @@ impl Pallet { .saturating_add(per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into())) .saturating_add(per_byte_fee.saturating_mul((validation_code.0.len() as u32).into())); - Ok((ParaGenesisArgs { genesis_head, validation_code, parachain }, deposit)) + Ok((ParaGenesisArgs { genesis_head, validation_code, paratype }, deposit)) } /// Swap a parachain and parathread, which involves scheduling an appropriate lifecycle update. diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index 273db30e2839..f53ee057f8e1 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -291,8 +291,15 @@ pub struct ParaGenesisArgs { pub genesis_head: HeadData, /// The initial validation code to use. pub validation_code: ValidationCode, - /// True if parachain, false if parathread. - pub parachain: bool, + /// Parachain or Parathread. + pub paratype: ParaType, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +pub enum ParaType { + ParaChain, + ParaThread, } /// This enum describes a reason why a particular PVF pre-checking vote was initiated. When the @@ -2021,11 +2028,12 @@ impl Pallet { id: ParaId, genesis_data: &ParaGenesisArgs, ) { - if genesis_data.parachain { - parachains.add(id); - ParaLifecycles::::insert(&id, ParaLifecycle::Parachain); - } else { - ParaLifecycles::::insert(&id, ParaLifecycle::Parathread); + match genesis_data.paratype { + ParaType::ParaChain => { + parachains.add(id); + ParaLifecycles::::insert(&id, ParaLifecycle::Parachain); + }, + ParaType::ParaThread => ParaLifecycles::::insert(&id, ParaLifecycle::Parathread), } // HACK: see the notice in `schedule_para_initialize`. From e8a8bb66700f38b7f44e47492d6926d4aad5a0a4 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Thu, 27 Oct 2022 18:57:55 +0200 Subject: [PATCH 02/16] Address PR comments --- runtime/parachains/src/paras/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index f53ee057f8e1..136926956501 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -295,11 +295,12 @@ pub struct ParaGenesisArgs { pub paratype: ParaType, } +/// Distinguishes between Parachain and Parathread #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum ParaType { - ParaChain, - ParaThread, + Parachain, + Parathread, } /// This enum describes a reason why a particular PVF pre-checking vote was initiated. When the @@ -2029,11 +2030,11 @@ impl Pallet { genesis_data: &ParaGenesisArgs, ) { match genesis_data.paratype { - ParaType::ParaChain => { + ParaType::Parachain => { parachains.add(id); ParaLifecycles::::insert(&id, ParaLifecycle::Parachain); }, - ParaType::ParaThread => ParaLifecycles::::insert(&id, ParaLifecycle::Parathread), + ParaType::Parathread => ParaLifecycles::::insert(&id, ParaLifecycle::Parathread), } // HACK: see the notice in `schedule_para_initialize`. From 58893344eed42ae69cb0775f396f6ecebec75a57 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Thu, 27 Oct 2022 18:59:01 +0200 Subject: [PATCH 03/16] Update dependencies --- node/test/service/src/lib.rs | 4 +- runtime/common/src/paras_registrar.rs | 2 +- runtime/parachains/src/builder.rs | 3 +- runtime/parachains/src/hrmp/benchmarking.rs | 4 +- runtime/parachains/src/hrmp/tests.rs | 11 ++- runtime/parachains/src/inclusion/tests.rs | 46 +++++++--- runtime/parachains/src/initializer/tests.rs | 3 +- .../src/paras/benchmarking/pvf_check.rs | 4 +- runtime/parachains/src/paras/tests.rs | 46 +++++----- runtime/parachains/src/scheduler/tests.rs | 88 +++++++++---------- 10 files changed, 120 insertions(+), 91 deletions(-) diff --git a/node/test/service/src/lib.rs b/node/test/service/src/lib.rs index 8fe31ce2b5b4..5525c5da2bf0 100644 --- a/node/test/service/src/lib.rs +++ b/node/test/service/src/lib.rs @@ -27,7 +27,7 @@ use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProt use polkadot_overseer::Handle; use polkadot_primitives::v2::{Balance, CollatorPair, HeadData, Id as ParaId, ValidationCode}; use polkadot_runtime_common::BlockHashCount; -use polkadot_runtime_parachains::paras::ParaGenesisArgs; +use polkadot_runtime_parachains::paras::{ParaGenesisArgs, ParaType}; use polkadot_service::{ ClientHandle, Error, ExecuteWithClient, FullClient, IsCollator, NewFull, PrometheusConfig, }; @@ -305,7 +305,7 @@ impl PolkadotTestNode { genesis: ParaGenesisArgs { genesis_head: genesis_head.into(), validation_code: validation_code.into(), - parachain: true, + paratype: ParaType::Parachain, }, }; diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 118c3c083581..9148f722eac5 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -571,7 +571,7 @@ impl Pallet { }; ensure!(paras::Pallet::::lifecycle(id).is_none(), Error::::AlreadyRegistered); let (genesis, deposit) = - Self::validate_onboarding_data(genesis_head, validation_code, ParaType::ParaThread)?; + Self::validate_onboarding_data(genesis_head, validation_code, ParaType::Parathread)?; let deposit = deposit_override.unwrap_or(deposit); if let Some(additional) = deposit.checked_sub(&deposited) { diff --git a/runtime/parachains/src/builder.rs b/runtime/parachains/src/builder.rs index f4bc58f2d4f2..be0face23b12 100644 --- a/runtime/parachains/src/builder.rs +++ b/runtime/parachains/src/builder.rs @@ -16,6 +16,7 @@ use crate::{ configuration, inclusion, initializer, paras, + paras::ParaType, paras_inherent::{self}, scheduler, session_info, shared, }; @@ -345,7 +346,7 @@ impl BenchBuilder { paras::ParaGenesisArgs { genesis_head: Self::mock_head_data(), validation_code: mock_validation_code(), - parachain: true, + paratype: ParaType::Parachain, }, ) .unwrap(); diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 7ea14b1dc922..5d83d79a44e7 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -17,7 +17,7 @@ use crate::{ configuration::Pallet as Configuration, hrmp::{Pallet as Hrmp, *}, - paras::{Pallet as Paras, ParachainsCache}, + paras::{Pallet as Paras, ParaType, ParachainsCache}, shared::Pallet as Shared, }; use frame_support::{assert_ok, traits::Currency}; @@ -31,7 +31,7 @@ fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) &mut parachains, id, &crate::paras::ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/hrmp/tests.rs b/runtime/parachains/src/hrmp/tests.rs index 9e0d0646d057..f960cd02455f 100644 --- a/runtime/parachains/src/hrmp/tests.rs +++ b/runtime/parachains/src/hrmp/tests.rs @@ -15,9 +15,12 @@ // along with Polkadot. If not, see . use super::*; -use crate::mock::{ - new_test_ext, Configuration, Hrmp, MockGenesisConfig, Paras, ParasShared, - RuntimeEvent as MockEvent, RuntimeOrigin, System, Test, +use crate::{ + mock::{ + new_test_ext, Configuration, Hrmp, MockGenesisConfig, Paras, ParasShared, + RuntimeEvent as MockEvent, RuntimeOrigin, System, Test, + }, + paras::ParaType, }; use frame_support::{assert_noop, assert_ok, traits::Currency as _}; use primitives::v2::BlockNumber; @@ -130,7 +133,7 @@ fn register_parachain_with_balance(id: ParaId, balance: Balance) { assert_ok!(Paras::schedule_para_initialize( id, crate::paras::ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/inclusion/tests.rs b/runtime/parachains/src/inclusion/tests.rs index de3199c366a7..ab7d6218c638 100644 --- a/runtime/parachains/src/inclusion/tests.rs +++ b/runtime/parachains/src/inclusion/tests.rs @@ -22,7 +22,7 @@ use crate::{ new_test_ext, Configuration, MockGenesisConfig, ParaInclusion, Paras, ParasShared, System, Test, }, - paras::ParaGenesisArgs, + paras::{ParaGenesisArgs, ParaType}, paras_inherent::DisputedBitfield, scheduler::AssignmentKind, }; @@ -51,18 +51,18 @@ fn default_config() -> HostConfiguration { config } -pub(crate) fn genesis_config(paras: Vec<(ParaId, bool)>) -> MockGenesisConfig { +pub(crate) fn genesis_config(paras: Vec<(ParaId, ParaType)>) -> MockGenesisConfig { MockGenesisConfig { paras: paras::GenesisConfig { paras: paras .into_iter() - .map(|(id, is_chain)| { + .map(|(id, paratype)| { ( id, ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: dummy_validation_code(), - parachain: is_chain, + paratype, }, ) }) @@ -310,7 +310,11 @@ fn collect_pending_cleans_up_pending() { let chain_b = ParaId::from(2_u32); let thread_a = ParaId::from(3_u32); - let paras = vec![(chain_a, true), (chain_b, true), (thread_a, false)]; + let paras = vec![ + (chain_a, ParaType::Parachain), + (chain_b, ParaType::Parachain), + (thread_a, ParaType::Parathread), + ]; new_test_ext(genesis_config(paras)).execute_with(|| { let default_candidate = TestCandidateBuilder::default().build(); >::insert( @@ -368,7 +372,11 @@ fn bitfield_checks() { let chain_b = ParaId::from(2_u32); let thread_a = ParaId::from(3_u32); - let paras = vec![(chain_a, true), (chain_b, true), (thread_a, false)]; + let paras = vec![ + (chain_a, ParaType::Parachain), + (chain_b, ParaType::Parachain), + (thread_a, ParaType::Parathread), + ]; let validators = vec![ Sr25519Keyring::Alice, Sr25519Keyring::Bob, @@ -711,7 +719,11 @@ fn supermajority_bitfields_trigger_availability() { let chain_b = ParaId::from(2_u32); let thread_a = ParaId::from(3_u32); - let paras = vec![(chain_a, true), (chain_b, true), (thread_a, false)]; + let paras = vec![ + (chain_a, ParaType::Parachain), + (chain_b, ParaType::Parachain), + (thread_a, ParaType::Parathread), + ]; let validators = vec![ Sr25519Keyring::Alice, Sr25519Keyring::Bob, @@ -899,7 +911,11 @@ fn candidate_checks() { // The block number of the relay-parent for testing. const RELAY_PARENT_NUM: BlockNumber = 4; - let paras = vec![(chain_a, true), (chain_b, true), (thread_a, false)]; + let paras = vec![ + (chain_a, ParaType::Parachain), + (chain_b, ParaType::Parachain), + (thread_a, ParaType::Parathread), + ]; let validators = vec![ Sr25519Keyring::Alice, Sr25519Keyring::Bob, @@ -1442,7 +1458,11 @@ fn backing_works() { // The block number of the relay-parent for testing. const RELAY_PARENT_NUM: BlockNumber = 4; - let paras = vec![(chain_a, true), (chain_b, true), (thread_a, false)]; + let paras = vec![ + (chain_a, ParaType::Parachain), + (chain_b, ParaType::Parachain), + (thread_a, ParaType::Parathread), + ]; let validators = vec![ Sr25519Keyring::Alice, Sr25519Keyring::Bob, @@ -1722,7 +1742,7 @@ fn can_include_candidate_with_ok_code_upgrade() { // The block number of the relay-parent for testing. const RELAY_PARENT_NUM: BlockNumber = 4; - let paras = vec![(chain_a, true)]; + let paras = vec![(chain_a, ParaType::Parachain)]; let validators = vec![ Sr25519Keyring::Alice, Sr25519Keyring::Bob, @@ -1827,7 +1847,11 @@ fn session_change_wipes() { let chain_b = ParaId::from(2_u32); let thread_a = ParaId::from(3_u32); - let paras = vec![(chain_a, true), (chain_b, true), (thread_a, false)]; + let paras = vec![ + (chain_a, ParaType::Parachain), + (chain_b, ParaType::Parachain), + (thread_a, ParaType::Parathread), + ]; let validators = vec![ Sr25519Keyring::Alice, Sr25519Keyring::Bob, diff --git a/runtime/parachains/src/initializer/tests.rs b/runtime/parachains/src/initializer/tests.rs index 7fdf8b6b4a57..67fcd6218396 100644 --- a/runtime/parachains/src/initializer/tests.rs +++ b/runtime/parachains/src/initializer/tests.rs @@ -21,6 +21,7 @@ use crate::mock::{ use primitives::v2::{HeadData, Id as ParaId}; use test_helpers::dummy_validation_code; +use crate::paras::ParaType; use frame_support::{ assert_ok, traits::{OnFinalize, OnInitialize}, @@ -90,7 +91,7 @@ fn scheduled_cleanup_performed() { let c = ParaId::from(123); let mock_genesis = crate::paras::ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: HeadData(vec![4, 5, 6]), validation_code: dummy_validation_code(), }; diff --git a/runtime/parachains/src/paras/benchmarking/pvf_check.rs b/runtime/parachains/src/paras/benchmarking/pvf_check.rs index a89315c2857b..48902bc39978 100644 --- a/runtime/parachains/src/paras/benchmarking/pvf_check.rs +++ b/runtime/parachains/src/paras/benchmarking/pvf_check.rs @@ -140,7 +140,7 @@ where &mut parachains, id, &ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: old_validation_code, }, @@ -159,7 +159,7 @@ where let r = Pallet::::schedule_para_initialize( id, ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: validation_code(), }, diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index 766fa00d01b3..9e0e615aa977 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -222,7 +222,7 @@ fn schedule_para_init_rejects_empty_code() { Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![]), } @@ -233,7 +233,7 @@ fn schedule_para_init_rejects_empty_code() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![1]), } @@ -248,7 +248,7 @@ fn para_past_code_pruning_in_initialize() { ( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -256,7 +256,7 @@ fn para_past_code_pruning_in_initialize() { ( 1u32.into(), ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -316,7 +316,7 @@ fn note_new_head_sets_head() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -349,7 +349,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -357,7 +357,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 1u32.into(), ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -402,7 +402,7 @@ fn code_upgrade_applied_after_delay() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -505,7 +505,7 @@ fn code_upgrade_applied_after_delay_even_when_late() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -590,7 +590,7 @@ fn submit_code_change_when_not_allowed_is_err() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -658,7 +658,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -721,7 +721,7 @@ fn full_parachain_cleanup_storage() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -827,7 +827,7 @@ fn cannot_offboard_ongoing_pvf_check() { let paras = vec![( para_id, ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -900,7 +900,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: vec![1].into(), validation_code: code_b.clone(), }, @@ -909,7 +909,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -918,7 +918,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( c, ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: vec![3].into(), validation_code: code_c.clone(), }, @@ -994,7 +994,7 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -1084,7 +1084,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { let paras = vec![( a, ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -1117,7 +1117,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - parachain: true, + paratype: ParaType::Parachain, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1185,7 +1185,7 @@ fn pvf_check_onboarding_reject_on_expiry() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1224,7 +1224,7 @@ fn pvf_check_upgrade_reject() { let paras = vec![( a, ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: Default::default(), validation_code: old_code, }, @@ -1359,7 +1359,7 @@ fn pvf_check_submit_vote() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -1446,7 +1446,7 @@ fn include_pvf_check_statement_refunds_weight() { let paras = vec![( a, ParaGenesisArgs { - parachain: false, + paratype: ParaType::Parathread, genesis_head: Default::default(), validation_code: old_code, }, diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index b2b5e4236dd5..93a7596d4a3d 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -26,16 +26,16 @@ use crate::{ mock::{ new_test_ext, Configuration, MockGenesisConfig, Paras, ParasShared, Scheduler, System, Test, }, - paras::ParaGenesisArgs, + paras::{ParaGenesisArgs, ParaType}, }; -fn schedule_blank_para(id: ParaId, is_chain: bool) { +fn schedule_blank_para(id: ParaId, paratype: ParaType) { assert_ok!(Paras::schedule_para_initialize( id, ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: vec![1, 2, 3].into(), - parachain: is_chain, + paratype, } )); } @@ -122,7 +122,7 @@ fn add_parathread_claim_works() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_id, false); + schedule_blank_para(thread_id, ParaType::Parathread); assert!(!Paras::is_parathread(thread_id)); @@ -203,7 +203,7 @@ fn cannot_add_claim_when_no_parathread_cores() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_id, false); + schedule_blank_para(thread_id, ParaType::Parathread); assert!(!Paras::is_parathread(thread_id)); @@ -239,9 +239,9 @@ fn session_change_prunes_cores_beyond_retries_and_those_from_non_live_parathread // threads a, b, and c will be live in next session, but not d. { - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); - schedule_blank_para(thread_c, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_c, ParaType::Parathread); } // set up a queue as if `n_cores` was 4 and with some with many retries. @@ -334,8 +334,8 @@ fn session_change_shuffles_validators() { let chain_b = ParaId::from(2_u32); // ensure that we have 5 groups by registering 2 parachains. - schedule_blank_para(chain_a, true); - schedule_blank_para(chain_b, true); + schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_b, ParaType::Parachain); run_to_block(1, |number| match number { 1 => Some(SessionChangeNotification { @@ -392,9 +392,9 @@ fn session_change_takes_only_max_per_core() { let chain_c = ParaId::from(3_u32); // ensure that we have 5 groups by registering 2 parachains. - schedule_blank_para(chain_a, true); - schedule_blank_para(chain_b, true); - schedule_blank_para(chain_c, false); + schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_b, ParaType::Parachain); + schedule_blank_para(chain_c, ParaType::Parathread); run_to_block(1, |number| match number { 1 => Some(SessionChangeNotification { @@ -447,13 +447,13 @@ fn schedule_schedules() { assert_eq!(default_config().parathread_cores, 3); // register 2 parachains - schedule_blank_para(chain_a, true); - schedule_blank_para(chain_b, true); + schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_b, ParaType::Parachain); // and 3 parathreads - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); - schedule_blank_para(thread_c, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_c, ParaType::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -574,15 +574,15 @@ fn schedule_schedules_including_just_freed() { assert_eq!(default_config().parathread_cores, 3); // register 2 parachains - schedule_blank_para(chain_a, true); - schedule_blank_para(chain_b, true); + schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_b, ParaType::Parachain); // and 5 parathreads - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); - schedule_blank_para(thread_c, false); - schedule_blank_para(thread_d, false); - schedule_blank_para(thread_e, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_c, ParaType::Parathread); + schedule_blank_para(thread_d, ParaType::Parathread); + schedule_blank_para(thread_e, ParaType::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -743,9 +743,9 @@ fn schedule_clears_availability_cores() { assert_eq!(default_config().parathread_cores, 3); // register 3 parachains - schedule_blank_para(chain_a, true); - schedule_blank_para(chain_b, true); - schedule_blank_para(chain_c, true); + schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_b, ParaType::Parachain); + schedule_blank_para(chain_c, ParaType::Parachain); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -849,8 +849,8 @@ fn schedule_rotates_groups() { new_test_ext(genesis_config).execute_with(|| { assert_eq!(default_config().parathread_cores, 3); - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -921,8 +921,8 @@ fn parathread_claims_are_pruned_after_retries() { new_test_ext(genesis_config).execute_with(|| { assert_eq!(default_config().parathread_cores, 3); - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -978,8 +978,8 @@ fn availability_predicate_works() { let thread_a = ParaId::from(2_u32); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(chain_a, true); - schedule_blank_para(thread_a, false); + schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(thread_a, ParaType::Parathread); // start a new session with our chain & thread registered. run_to_block(1, |number| match number { @@ -1075,8 +1075,8 @@ fn next_up_on_available_uses_next_scheduled_or_none_for_thread() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1147,8 +1147,8 @@ fn next_up_on_time_out_reuses_claim_if_nothing_queued() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1222,7 +1222,7 @@ fn next_up_on_available_is_parachain_always() { let chain_a = ParaId::from(1_u32); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(chain_a, true); + schedule_blank_para(chain_a, ParaType::Parachain); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1276,7 +1276,7 @@ fn next_up_on_time_out_is_parachain_always() { let chain_a = ParaId::from(1_u32); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(chain_a, true); + schedule_blank_para(chain_a, ParaType::Parachain); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1330,8 +1330,8 @@ fn session_change_requires_reschedule_dropping_removed_paras() { let chain_b = ParaId::from(2_u32); // ensure that we have 5 groups by registering 2 parachains. - schedule_blank_para(chain_a, true); - schedule_blank_para(chain_b, true); + schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_b, ParaType::Parachain); run_to_block(1, |number| match number { 1 => Some(SessionChangeNotification { @@ -1409,8 +1409,8 @@ fn parathread_claims_are_pruned_after_deregistration() { new_test_ext(genesis_config).execute_with(|| { assert_eq!(default_config().parathread_cores, 3); - schedule_blank_para(thread_a, false); - schedule_blank_para(thread_b, false); + schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(thread_b, ParaType::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { From 06550bdd283bfb742e21f7169a2926966cd3eee7 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Fri, 28 Oct 2022 10:08:24 +0200 Subject: [PATCH 04/16] ParaType -> ParaKind --- node/test/service/src/lib.rs | 4 +- runtime/common/src/paras_registrar.rs | 6 +- runtime/parachains/src/builder.rs | 4 +- runtime/parachains/src/hrmp/benchmarking.rs | 4 +- runtime/parachains/src/hrmp/tests.rs | 4 +- runtime/parachains/src/inclusion/tests.rs | 42 ++++----- runtime/parachains/src/initializer/tests.rs | 4 +- .../src/paras/benchmarking/pvf_check.rs | 4 +- runtime/parachains/src/paras/mod.rs | 8 +- runtime/parachains/src/paras/tests.rs | 46 +++++----- runtime/parachains/src/scheduler/tests.rs | 86 +++++++++---------- 11 files changed, 106 insertions(+), 106 deletions(-) diff --git a/node/test/service/src/lib.rs b/node/test/service/src/lib.rs index 5525c5da2bf0..f08519e3d9ee 100644 --- a/node/test/service/src/lib.rs +++ b/node/test/service/src/lib.rs @@ -27,7 +27,7 @@ use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProt use polkadot_overseer::Handle; use polkadot_primitives::v2::{Balance, CollatorPair, HeadData, Id as ParaId, ValidationCode}; use polkadot_runtime_common::BlockHashCount; -use polkadot_runtime_parachains::paras::{ParaGenesisArgs, ParaType}; +use polkadot_runtime_parachains::paras::{ParaGenesisArgs, ParaKind}; use polkadot_service::{ ClientHandle, Error, ExecuteWithClient, FullClient, IsCollator, NewFull, PrometheusConfig, }; @@ -305,7 +305,7 @@ impl PolkadotTestNode { genesis: ParaGenesisArgs { genesis_head: genesis_head.into(), validation_code: validation_code.into(), - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, }, }; diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 9148f722eac5..ab7f5d027831 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -35,7 +35,7 @@ use sp_std::{prelude::*, result}; use crate::traits::{OnSwap, Registrar}; pub use pallet::*; use parity_scale_codec::{Decode, Encode}; -use runtime_parachains::paras::ParaType; +use runtime_parachains::paras::ParaKind; use scale_info::TypeInfo; use sp_runtime::{ traits::{CheckedSub, Saturating}, @@ -571,7 +571,7 @@ impl Pallet { }; ensure!(paras::Pallet::::lifecycle(id).is_none(), Error::::AlreadyRegistered); let (genesis, deposit) = - Self::validate_onboarding_data(genesis_head, validation_code, ParaType::Parathread)?; + Self::validate_onboarding_data(genesis_head, validation_code, ParaKind::Parathread)?; let deposit = deposit_override.unwrap_or(deposit); if let Some(additional) = deposit.checked_sub(&deposited) { @@ -614,7 +614,7 @@ impl Pallet { fn validate_onboarding_data( genesis_head: HeadData, validation_code: ValidationCode, - paratype: ParaType, + paratype: ParaKind, ) -> Result<(ParaGenesisArgs, BalanceOf), sp_runtime::DispatchError> { let config = configuration::Pallet::::config(); ensure!(validation_code.0.len() > 0, Error::::EmptyCode); diff --git a/runtime/parachains/src/builder.rs b/runtime/parachains/src/builder.rs index be0face23b12..32447e074d43 100644 --- a/runtime/parachains/src/builder.rs +++ b/runtime/parachains/src/builder.rs @@ -16,7 +16,7 @@ use crate::{ configuration, inclusion, initializer, paras, - paras::ParaType, + paras::ParaKind, paras_inherent::{self}, scheduler, session_info, shared, }; @@ -346,7 +346,7 @@ impl BenchBuilder { paras::ParaGenesisArgs { genesis_head: Self::mock_head_data(), validation_code: mock_validation_code(), - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, }, ) .unwrap(); diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 5d83d79a44e7..3e870e35389b 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -17,7 +17,7 @@ use crate::{ configuration::Pallet as Configuration, hrmp::{Pallet as Hrmp, *}, - paras::{Pallet as Paras, ParaType, ParachainsCache}, + paras::{Pallet as Paras, ParaKind, ParachainsCache}, shared::Pallet as Shared, }; use frame_support::{assert_ok, traits::Currency}; @@ -31,7 +31,7 @@ fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) &mut parachains, id, &crate::paras::ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/hrmp/tests.rs b/runtime/parachains/src/hrmp/tests.rs index f960cd02455f..c7c7431ce005 100644 --- a/runtime/parachains/src/hrmp/tests.rs +++ b/runtime/parachains/src/hrmp/tests.rs @@ -20,7 +20,7 @@ use crate::{ new_test_ext, Configuration, Hrmp, MockGenesisConfig, Paras, ParasShared, RuntimeEvent as MockEvent, RuntimeOrigin, System, Test, }, - paras::ParaType, + paras::ParaKind, }; use frame_support::{assert_noop, assert_ok, traits::Currency as _}; use primitives::v2::BlockNumber; @@ -133,7 +133,7 @@ fn register_parachain_with_balance(id: ParaId, balance: Balance) { assert_ok!(Paras::schedule_para_initialize( id, crate::paras::ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/inclusion/tests.rs b/runtime/parachains/src/inclusion/tests.rs index ab7d6218c638..4220c8e20d1a 100644 --- a/runtime/parachains/src/inclusion/tests.rs +++ b/runtime/parachains/src/inclusion/tests.rs @@ -22,7 +22,7 @@ use crate::{ new_test_ext, Configuration, MockGenesisConfig, ParaInclusion, Paras, ParasShared, System, Test, }, - paras::{ParaGenesisArgs, ParaType}, + paras::{ParaGenesisArgs, ParaKind}, paras_inherent::DisputedBitfield, scheduler::AssignmentKind, }; @@ -51,7 +51,7 @@ fn default_config() -> HostConfiguration { config } -pub(crate) fn genesis_config(paras: Vec<(ParaId, ParaType)>) -> MockGenesisConfig { +pub(crate) fn genesis_config(paras: Vec<(ParaId, ParaKind)>) -> MockGenesisConfig { MockGenesisConfig { paras: paras::GenesisConfig { paras: paras @@ -311,9 +311,9 @@ fn collect_pending_cleans_up_pending() { let thread_a = ParaId::from(3_u32); let paras = vec![ - (chain_a, ParaType::Parachain), - (chain_b, ParaType::Parachain), - (thread_a, ParaType::Parathread), + (chain_a, ParaKind::Parachain), + (chain_b, ParaKind::Parachain), + (thread_a, ParaKind::Parathread), ]; new_test_ext(genesis_config(paras)).execute_with(|| { let default_candidate = TestCandidateBuilder::default().build(); @@ -373,9 +373,9 @@ fn bitfield_checks() { let thread_a = ParaId::from(3_u32); let paras = vec![ - (chain_a, ParaType::Parachain), - (chain_b, ParaType::Parachain), - (thread_a, ParaType::Parathread), + (chain_a, ParaKind::Parachain), + (chain_b, ParaKind::Parachain), + (thread_a, ParaKind::Parathread), ]; let validators = vec![ Sr25519Keyring::Alice, @@ -720,9 +720,9 @@ fn supermajority_bitfields_trigger_availability() { let thread_a = ParaId::from(3_u32); let paras = vec![ - (chain_a, ParaType::Parachain), - (chain_b, ParaType::Parachain), - (thread_a, ParaType::Parathread), + (chain_a, ParaKind::Parachain), + (chain_b, ParaKind::Parachain), + (thread_a, ParaKind::Parathread), ]; let validators = vec![ Sr25519Keyring::Alice, @@ -912,9 +912,9 @@ fn candidate_checks() { const RELAY_PARENT_NUM: BlockNumber = 4; let paras = vec![ - (chain_a, ParaType::Parachain), - (chain_b, ParaType::Parachain), - (thread_a, ParaType::Parathread), + (chain_a, ParaKind::Parachain), + (chain_b, ParaKind::Parachain), + (thread_a, ParaKind::Parathread), ]; let validators = vec![ Sr25519Keyring::Alice, @@ -1459,9 +1459,9 @@ fn backing_works() { const RELAY_PARENT_NUM: BlockNumber = 4; let paras = vec![ - (chain_a, ParaType::Parachain), - (chain_b, ParaType::Parachain), - (thread_a, ParaType::Parathread), + (chain_a, ParaKind::Parachain), + (chain_b, ParaKind::Parachain), + (thread_a, ParaKind::Parathread), ]; let validators = vec![ Sr25519Keyring::Alice, @@ -1742,7 +1742,7 @@ fn can_include_candidate_with_ok_code_upgrade() { // The block number of the relay-parent for testing. const RELAY_PARENT_NUM: BlockNumber = 4; - let paras = vec![(chain_a, ParaType::Parachain)]; + let paras = vec![(chain_a, ParaKind::Parachain)]; let validators = vec![ Sr25519Keyring::Alice, Sr25519Keyring::Bob, @@ -1848,9 +1848,9 @@ fn session_change_wipes() { let thread_a = ParaId::from(3_u32); let paras = vec![ - (chain_a, ParaType::Parachain), - (chain_b, ParaType::Parachain), - (thread_a, ParaType::Parathread), + (chain_a, ParaKind::Parachain), + (chain_b, ParaKind::Parachain), + (thread_a, ParaKind::Parathread), ]; let validators = vec![ Sr25519Keyring::Alice, diff --git a/runtime/parachains/src/initializer/tests.rs b/runtime/parachains/src/initializer/tests.rs index 67fcd6218396..970365db5a11 100644 --- a/runtime/parachains/src/initializer/tests.rs +++ b/runtime/parachains/src/initializer/tests.rs @@ -21,7 +21,7 @@ use crate::mock::{ use primitives::v2::{HeadData, Id as ParaId}; use test_helpers::dummy_validation_code; -use crate::paras::ParaType; +use crate::paras::ParaKind; use frame_support::{ assert_ok, traits::{OnFinalize, OnInitialize}, @@ -91,7 +91,7 @@ fn scheduled_cleanup_performed() { let c = ParaId::from(123); let mock_genesis = crate::paras::ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: HeadData(vec![4, 5, 6]), validation_code: dummy_validation_code(), }; diff --git a/runtime/parachains/src/paras/benchmarking/pvf_check.rs b/runtime/parachains/src/paras/benchmarking/pvf_check.rs index 48902bc39978..8ded700f23e1 100644 --- a/runtime/parachains/src/paras/benchmarking/pvf_check.rs +++ b/runtime/parachains/src/paras/benchmarking/pvf_check.rs @@ -140,7 +140,7 @@ where &mut parachains, id, &ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: old_validation_code, }, @@ -159,7 +159,7 @@ where let r = Pallet::::schedule_para_initialize( id, ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: validation_code(), }, diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index 136926956501..3cee07639ca3 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -292,13 +292,13 @@ pub struct ParaGenesisArgs { /// The initial validation code to use. pub validation_code: ValidationCode, /// Parachain or Parathread. - pub paratype: ParaType, + pub paratype: ParaKind, } /// Distinguishes between Parachain and Parathread #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub enum ParaType { +pub enum ParaKind { Parachain, Parathread, } @@ -2030,11 +2030,11 @@ impl Pallet { genesis_data: &ParaGenesisArgs, ) { match genesis_data.paratype { - ParaType::Parachain => { + ParaKind::Parachain => { parachains.add(id); ParaLifecycles::::insert(&id, ParaLifecycle::Parachain); }, - ParaType::Parathread => ParaLifecycles::::insert(&id, ParaLifecycle::Parathread), + ParaKind::Parathread => ParaLifecycles::::insert(&id, ParaLifecycle::Parathread), } // HACK: see the notice in `schedule_para_initialize`. diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index 9e0e615aa977..67b3f566981e 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -222,7 +222,7 @@ fn schedule_para_init_rejects_empty_code() { Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![]), } @@ -233,7 +233,7 @@ fn schedule_para_init_rejects_empty_code() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![1]), } @@ -248,7 +248,7 @@ fn para_past_code_pruning_in_initialize() { ( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -256,7 +256,7 @@ fn para_past_code_pruning_in_initialize() { ( 1u32.into(), ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -316,7 +316,7 @@ fn note_new_head_sets_head() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -349,7 +349,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -357,7 +357,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 1u32.into(), ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -402,7 +402,7 @@ fn code_upgrade_applied_after_delay() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -505,7 +505,7 @@ fn code_upgrade_applied_after_delay_even_when_late() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -590,7 +590,7 @@ fn submit_code_change_when_not_allowed_is_err() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -658,7 +658,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -721,7 +721,7 @@ fn full_parachain_cleanup_storage() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -827,7 +827,7 @@ fn cannot_offboard_ongoing_pvf_check() { let paras = vec![( para_id, ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -900,7 +900,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: code_b.clone(), }, @@ -909,7 +909,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -918,7 +918,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( c, ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: vec![3].into(), validation_code: code_c.clone(), }, @@ -994,7 +994,7 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -1084,7 +1084,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { let paras = vec![( a, ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -1117,7 +1117,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - paratype: ParaType::Parachain, + paratype: ParaKind::Parachain, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1185,7 +1185,7 @@ fn pvf_check_onboarding_reject_on_expiry() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1224,7 +1224,7 @@ fn pvf_check_upgrade_reject() { let paras = vec![( a, ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, @@ -1359,7 +1359,7 @@ fn pvf_check_submit_vote() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -1446,7 +1446,7 @@ fn include_pvf_check_statement_refunds_weight() { let paras = vec![( a, ParaGenesisArgs { - paratype: ParaType::Parathread, + paratype: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index 93a7596d4a3d..0ec20fa6363c 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -26,10 +26,10 @@ use crate::{ mock::{ new_test_ext, Configuration, MockGenesisConfig, Paras, ParasShared, Scheduler, System, Test, }, - paras::{ParaGenesisArgs, ParaType}, + paras::{ParaGenesisArgs, ParaKind}, }; -fn schedule_blank_para(id: ParaId, paratype: ParaType) { +fn schedule_blank_para(id: ParaId, paratype: ParaKind) { assert_ok!(Paras::schedule_para_initialize( id, ParaGenesisArgs { @@ -122,7 +122,7 @@ fn add_parathread_claim_works() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_id, ParaType::Parathread); + schedule_blank_para(thread_id, ParaKind::Parathread); assert!(!Paras::is_parathread(thread_id)); @@ -203,7 +203,7 @@ fn cannot_add_claim_when_no_parathread_cores() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_id, ParaType::Parathread); + schedule_blank_para(thread_id, ParaKind::Parathread); assert!(!Paras::is_parathread(thread_id)); @@ -239,9 +239,9 @@ fn session_change_prunes_cores_beyond_retries_and_those_from_non_live_parathread // threads a, b, and c will be live in next session, but not d. { - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); - schedule_blank_para(thread_c, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); + schedule_blank_para(thread_c, ParaKind::Parathread); } // set up a queue as if `n_cores` was 4 and with some with many retries. @@ -334,8 +334,8 @@ fn session_change_shuffles_validators() { let chain_b = ParaId::from(2_u32); // ensure that we have 5 groups by registering 2 parachains. - schedule_blank_para(chain_a, ParaType::Parachain); - schedule_blank_para(chain_b, ParaType::Parachain); + schedule_blank_para(chain_a, ParaKind::Parachain); + schedule_blank_para(chain_b, ParaKind::Parachain); run_to_block(1, |number| match number { 1 => Some(SessionChangeNotification { @@ -392,9 +392,9 @@ fn session_change_takes_only_max_per_core() { let chain_c = ParaId::from(3_u32); // ensure that we have 5 groups by registering 2 parachains. - schedule_blank_para(chain_a, ParaType::Parachain); - schedule_blank_para(chain_b, ParaType::Parachain); - schedule_blank_para(chain_c, ParaType::Parathread); + schedule_blank_para(chain_a, ParaKind::Parachain); + schedule_blank_para(chain_b, ParaKind::Parachain); + schedule_blank_para(chain_c, ParaKind::Parathread); run_to_block(1, |number| match number { 1 => Some(SessionChangeNotification { @@ -447,13 +447,13 @@ fn schedule_schedules() { assert_eq!(default_config().parathread_cores, 3); // register 2 parachains - schedule_blank_para(chain_a, ParaType::Parachain); - schedule_blank_para(chain_b, ParaType::Parachain); + schedule_blank_para(chain_a, ParaKind::Parachain); + schedule_blank_para(chain_b, ParaKind::Parachain); // and 3 parathreads - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); - schedule_blank_para(thread_c, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); + schedule_blank_para(thread_c, ParaKind::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -574,15 +574,15 @@ fn schedule_schedules_including_just_freed() { assert_eq!(default_config().parathread_cores, 3); // register 2 parachains - schedule_blank_para(chain_a, ParaType::Parachain); - schedule_blank_para(chain_b, ParaType::Parachain); + schedule_blank_para(chain_a, ParaKind::Parachain); + schedule_blank_para(chain_b, ParaKind::Parachain); // and 5 parathreads - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); - schedule_blank_para(thread_c, ParaType::Parathread); - schedule_blank_para(thread_d, ParaType::Parathread); - schedule_blank_para(thread_e, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); + schedule_blank_para(thread_c, ParaKind::Parathread); + schedule_blank_para(thread_d, ParaKind::Parathread); + schedule_blank_para(thread_e, ParaKind::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -743,9 +743,9 @@ fn schedule_clears_availability_cores() { assert_eq!(default_config().parathread_cores, 3); // register 3 parachains - schedule_blank_para(chain_a, ParaType::Parachain); - schedule_blank_para(chain_b, ParaType::Parachain); - schedule_blank_para(chain_c, ParaType::Parachain); + schedule_blank_para(chain_a, ParaKind::Parachain); + schedule_blank_para(chain_b, ParaKind::Parachain); + schedule_blank_para(chain_c, ParaKind::Parachain); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -849,8 +849,8 @@ fn schedule_rotates_groups() { new_test_ext(genesis_config).execute_with(|| { assert_eq!(default_config().parathread_cores, 3); - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -921,8 +921,8 @@ fn parathread_claims_are_pruned_after_retries() { new_test_ext(genesis_config).execute_with(|| { assert_eq!(default_config().parathread_cores, 3); - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -978,8 +978,8 @@ fn availability_predicate_works() { let thread_a = ParaId::from(2_u32); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(chain_a, ParaType::Parachain); - schedule_blank_para(thread_a, ParaType::Parathread); + schedule_blank_para(chain_a, ParaKind::Parachain); + schedule_blank_para(thread_a, ParaKind::Parathread); // start a new session with our chain & thread registered. run_to_block(1, |number| match number { @@ -1075,8 +1075,8 @@ fn next_up_on_available_uses_next_scheduled_or_none_for_thread() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1147,8 +1147,8 @@ fn next_up_on_time_out_reuses_claim_if_nothing_queued() { let collator = CollatorId::from(Sr25519Keyring::Alice.public()); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1222,7 +1222,7 @@ fn next_up_on_available_is_parachain_always() { let chain_a = ParaId::from(1_u32); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_a, ParaKind::Parachain); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1276,7 +1276,7 @@ fn next_up_on_time_out_is_parachain_always() { let chain_a = ParaId::from(1_u32); new_test_ext(genesis_config).execute_with(|| { - schedule_blank_para(chain_a, ParaType::Parachain); + schedule_blank_para(chain_a, ParaKind::Parachain); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { @@ -1330,8 +1330,8 @@ fn session_change_requires_reschedule_dropping_removed_paras() { let chain_b = ParaId::from(2_u32); // ensure that we have 5 groups by registering 2 parachains. - schedule_blank_para(chain_a, ParaType::Parachain); - schedule_blank_para(chain_b, ParaType::Parachain); + schedule_blank_para(chain_a, ParaKind::Parachain); + schedule_blank_para(chain_b, ParaKind::Parachain); run_to_block(1, |number| match number { 1 => Some(SessionChangeNotification { @@ -1409,8 +1409,8 @@ fn parathread_claims_are_pruned_after_deregistration() { new_test_ext(genesis_config).execute_with(|| { assert_eq!(default_config().parathread_cores, 3); - schedule_blank_para(thread_a, ParaType::Parathread); - schedule_blank_para(thread_b, ParaType::Parathread); + schedule_blank_para(thread_a, ParaKind::Parathread); + schedule_blank_para(thread_b, ParaKind::Parathread); // start a new session to activate, 5 validators for 5 cores. run_to_block(1, |number| match number { From c088e27dea611f3a4d165cb8c61ab03efef3d08b Mon Sep 17 00:00:00 2001 From: alexgparity Date: Fri, 28 Oct 2022 10:10:50 +0200 Subject: [PATCH 05/16] Swap enum field order to avoid migration --- runtime/parachains/src/paras/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index 3cee07639ca3..a57378c429cd 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -299,8 +299,8 @@ pub struct ParaGenesisArgs { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum ParaKind { - Parachain, Parathread, + Parachain, } /// This enum describes a reason why a particular PVF pre-checking vote was initiated. When the From 04610bebbfe6f4211a8d4ff59fd237931acf4697 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Fri, 28 Oct 2022 15:03:51 +0200 Subject: [PATCH 06/16] Rename paratype field to parakind --- node/test/service/src/lib.rs | 2 +- runtime/common/src/paras_registrar.rs | 2 +- runtime/parachains/src/builder.rs | 2 +- runtime/parachains/src/hrmp/benchmarking.rs | 2 +- runtime/parachains/src/hrmp/tests.rs | 2 +- runtime/parachains/src/inclusion/tests.rs | 2 +- runtime/parachains/src/initializer/tests.rs | 2 +- .../src/paras/benchmarking/pvf_check.rs | 4 +- runtime/parachains/src/paras/mod.rs | 4 +- runtime/parachains/src/paras/tests.rs | 46 +++++++++---------- runtime/parachains/src/scheduler/tests.rs | 2 +- 11 files changed, 35 insertions(+), 35 deletions(-) diff --git a/node/test/service/src/lib.rs b/node/test/service/src/lib.rs index f08519e3d9ee..eaf2381977c3 100644 --- a/node/test/service/src/lib.rs +++ b/node/test/service/src/lib.rs @@ -305,7 +305,7 @@ impl PolkadotTestNode { genesis: ParaGenesisArgs { genesis_head: genesis_head.into(), validation_code: validation_code.into(), - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, }, }; diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index ab7f5d027831..710baebd9abb 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -629,7 +629,7 @@ impl Pallet { .saturating_add(per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into())) .saturating_add(per_byte_fee.saturating_mul((validation_code.0.len() as u32).into())); - Ok((ParaGenesisArgs { genesis_head, validation_code, paratype }, deposit)) + Ok((ParaGenesisArgs { genesis_head, validation_code, parakind: paratype }, deposit)) } /// Swap a parachain and parathread, which involves scheduling an appropriate lifecycle update. diff --git a/runtime/parachains/src/builder.rs b/runtime/parachains/src/builder.rs index 32447e074d43..e42cc2bf478b 100644 --- a/runtime/parachains/src/builder.rs +++ b/runtime/parachains/src/builder.rs @@ -346,7 +346,7 @@ impl BenchBuilder { paras::ParaGenesisArgs { genesis_head: Self::mock_head_data(), validation_code: mock_validation_code(), - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, }, ) .unwrap(); diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 3e870e35389b..8c538110af72 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -31,7 +31,7 @@ fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) &mut parachains, id, &crate::paras::ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/hrmp/tests.rs b/runtime/parachains/src/hrmp/tests.rs index c7c7431ce005..8fa260977590 100644 --- a/runtime/parachains/src/hrmp/tests.rs +++ b/runtime/parachains/src/hrmp/tests.rs @@ -133,7 +133,7 @@ fn register_parachain_with_balance(id: ParaId, balance: Balance) { assert_ok!(Paras::schedule_para_initialize( id, crate::paras::ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/inclusion/tests.rs b/runtime/parachains/src/inclusion/tests.rs index 4220c8e20d1a..d8faeb489bed 100644 --- a/runtime/parachains/src/inclusion/tests.rs +++ b/runtime/parachains/src/inclusion/tests.rs @@ -62,7 +62,7 @@ pub(crate) fn genesis_config(paras: Vec<(ParaId, ParaKind)>) -> MockGenesisConfi ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: dummy_validation_code(), - paratype, + parakind: paratype, }, ) }) diff --git a/runtime/parachains/src/initializer/tests.rs b/runtime/parachains/src/initializer/tests.rs index 970365db5a11..f74c345bb157 100644 --- a/runtime/parachains/src/initializer/tests.rs +++ b/runtime/parachains/src/initializer/tests.rs @@ -91,7 +91,7 @@ fn scheduled_cleanup_performed() { let c = ParaId::from(123); let mock_genesis = crate::paras::ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: HeadData(vec![4, 5, 6]), validation_code: dummy_validation_code(), }; diff --git a/runtime/parachains/src/paras/benchmarking/pvf_check.rs b/runtime/parachains/src/paras/benchmarking/pvf_check.rs index 8ded700f23e1..5e1b50557c2d 100644 --- a/runtime/parachains/src/paras/benchmarking/pvf_check.rs +++ b/runtime/parachains/src/paras/benchmarking/pvf_check.rs @@ -140,7 +140,7 @@ where &mut parachains, id, &ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: old_validation_code, }, @@ -159,7 +159,7 @@ where let r = Pallet::::schedule_para_initialize( id, ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: validation_code(), }, diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index a57378c429cd..5d2f622269b9 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -292,7 +292,7 @@ pub struct ParaGenesisArgs { /// The initial validation code to use. pub validation_code: ValidationCode, /// Parachain or Parathread. - pub paratype: ParaKind, + pub parakind: ParaKind, } /// Distinguishes between Parachain and Parathread @@ -2029,7 +2029,7 @@ impl Pallet { id: ParaId, genesis_data: &ParaGenesisArgs, ) { - match genesis_data.paratype { + match genesis_data.parakind { ParaKind::Parachain => { parachains.add(id); ParaLifecycles::::insert(&id, ParaLifecycle::Parachain); diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index 67b3f566981e..dc767b0520d1 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -222,7 +222,7 @@ fn schedule_para_init_rejects_empty_code() { Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![]), } @@ -233,7 +233,7 @@ fn schedule_para_init_rejects_empty_code() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![1]), } @@ -248,7 +248,7 @@ fn para_past_code_pruning_in_initialize() { ( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -256,7 +256,7 @@ fn para_past_code_pruning_in_initialize() { ( 1u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -316,7 +316,7 @@ fn note_new_head_sets_head() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -349,7 +349,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -357,7 +357,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 1u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -402,7 +402,7 @@ fn code_upgrade_applied_after_delay() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -505,7 +505,7 @@ fn code_upgrade_applied_after_delay_even_when_late() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -590,7 +590,7 @@ fn submit_code_change_when_not_allowed_is_err() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -658,7 +658,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -721,7 +721,7 @@ fn full_parachain_cleanup_storage() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -827,7 +827,7 @@ fn cannot_offboard_ongoing_pvf_check() { let paras = vec![( para_id, ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -900,7 +900,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: code_b.clone(), }, @@ -909,7 +909,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -918,7 +918,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( c, ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: vec![3].into(), validation_code: code_c.clone(), }, @@ -994,7 +994,7 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -1084,7 +1084,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { let paras = vec![( a, ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -1117,7 +1117,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - paratype: ParaKind::Parachain, + parakind: ParaKind::Parachain, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1185,7 +1185,7 @@ fn pvf_check_onboarding_reject_on_expiry() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1224,7 +1224,7 @@ fn pvf_check_upgrade_reject() { let paras = vec![( a, ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, @@ -1359,7 +1359,7 @@ fn pvf_check_submit_vote() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -1446,7 +1446,7 @@ fn include_pvf_check_statement_refunds_weight() { let paras = vec![( a, ParaGenesisArgs { - paratype: ParaKind::Parathread, + parakind: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index 0ec20fa6363c..380e7841d83c 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -35,7 +35,7 @@ fn schedule_blank_para(id: ParaId, paratype: ParaKind) { ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: vec![1, 2, 3].into(), - paratype, + parakind, } )); } From 739e6e3e2ea0a4d575ff824ce13ff25daa93efd8 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Fri, 28 Oct 2022 17:15:23 +0200 Subject: [PATCH 07/16] Manual en-/decocing of Parakind --- runtime/parachains/src/paras/mod.rs | 28 ++++++++++++++++++++++- runtime/parachains/src/paras/tests.rs | 17 ++++++++++++++ runtime/parachains/src/scheduler/tests.rs | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index 5d2f622269b9..6daea4badc48 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -296,13 +296,39 @@ pub struct ParaGenesisArgs { } /// Distinguishes between Parachain and Parathread -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum ParaKind { Parathread, Parachain, } +// manual encoding and decoding as the parakind field in ParaGenesisArgs used to be a bool +impl Encode for ParaKind { + fn size_hint(&self) -> usize { + true.size_hint() + } + + fn using_encoded R>(&self, f: F) -> R { + match self { + ParaKind::Parachain => true.using_encoded(f), + ParaKind::Parathread => false.using_encoded(f), + } + } +} + +impl Decode for ParaKind { + fn decode( + input: &mut I, + ) -> Result { + match bool::decode(input) { + Ok(true) => Ok(ParaKind::Parachain), + Ok(false) => Ok(ParaKind::Parathread), + _ => Err("Invalid ParaKind representation".into()), + } + } +} + /// This enum describes a reason why a particular PVF pre-checking vote was initiated. When the /// PVF vote in question is concluded, this enum indicates what changes should be performed. #[derive(Encode, Decode, TypeInfo)] diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index dc767b0520d1..0f67bf9c45af 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -1723,3 +1723,20 @@ fn verify_upgrade_restriction_signal_is_externally_accessible() { ); }); } + +#[test] +fn parakind_encodes_decodes_to_bool() { + let chain_kind = ParaKind::Parachain.encode(); + let chain_bool = true.encode(); + assert_eq!(chain_kind, chain_bool); + + let chain_dec = ParaKind::decode(&mut chain_kind.as_slice()); + assert_eq!(chain_dec, Ok(ParaKind::Parachain)); + + let thread_kind = ParaKind::Parathread.encode(); + let thread_bool = false.encode(); + assert_eq!(thread_kind, thread_bool); + + let thread_dec = ParaKind::decode(&mut thread_kind.as_slice()); + assert_eq!(thread_dec, Ok(ParaKind::Parathread)); +} diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index 380e7841d83c..63262e1ba22a 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -29,7 +29,7 @@ use crate::{ paras::{ParaGenesisArgs, ParaKind}, }; -fn schedule_blank_para(id: ParaId, paratype: ParaKind) { +fn schedule_blank_para(id: ParaId, parakind: ParaKind) { assert_ok!(Paras::schedule_para_initialize( id, ParaGenesisArgs { From dcb044d1e386c877900fd056821a9ebdfb2d3e9c Mon Sep 17 00:00:00 2001 From: alexgparity Date: Sat, 29 Oct 2022 17:27:30 +0200 Subject: [PATCH 08/16] Manual TypeInfo for ParaKind --- runtime/parachains/src/paras/mod.rs | 13 ++++++++++--- runtime/parachains/src/paras/tests.rs | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index 6daea4badc48..a9a7de0a6195 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -115,7 +115,7 @@ use primitives::v2::{ ConsensusLog, HeadData, Id as ParaId, PvfCheckStatement, SessionIndex, UpgradeGoAhead, UpgradeRestriction, ValidationCode, ValidationCodeHash, ValidatorSignature, }; -use scale_info::TypeInfo; +use scale_info::{Type, TypeInfo}; use sp_core::RuntimeDebug; use sp_runtime::{ traits::{AppVerify, One, Saturating}, @@ -296,14 +296,14 @@ pub struct ParaGenesisArgs { } /// Distinguishes between Parachain and Parathread -#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)] +#[derive(PartialEq, Eq, Clone, RuntimeDebug)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum ParaKind { Parathread, Parachain, } -// manual encoding and decoding as the parakind field in ParaGenesisArgs used to be a bool +// manual encoding, decoding, adn TypeInfo as the parakind field in ParaGenesisArgs used to be a bool impl Encode for ParaKind { fn size_hint(&self) -> usize { true.size_hint() @@ -329,6 +329,13 @@ impl Decode for ParaKind { } } +impl TypeInfo for ParaKind { + type Identity = bool; + fn type_info() -> Type { + bool::type_info() + } +} + /// This enum describes a reason why a particular PVF pre-checking vote was initiated. When the /// PVF vote in question is concluded, this enum indicates what changes should be performed. #[derive(Encode, Decode, TypeInfo)] diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index 0f67bf9c45af..e5610b7ae681 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -1739,4 +1739,6 @@ fn parakind_encodes_decodes_to_bool() { let thread_dec = ParaKind::decode(&mut thread_kind.as_slice()); assert_eq!(thread_dec, Ok(ParaKind::Parathread)); + + assert_eq!(bool::type_info(), ParaKind::type_info()); } From 6ca0760d86aa535b5b867b23e0a1c706f416fe1f Mon Sep 17 00:00:00 2001 From: alexgparity Date: Sun, 30 Oct 2022 10:28:23 +0100 Subject: [PATCH 09/16] rename field back to parachain --- node/test/service/src/lib.rs | 2 +- runtime/common/src/paras_registrar.rs | 2 +- runtime/parachains/src/builder.rs | 2 +- runtime/parachains/src/hrmp/benchmarking.rs | 2 +- runtime/parachains/src/hrmp/tests.rs | 2 +- runtime/parachains/src/inclusion/tests.rs | 2 +- runtime/parachains/src/initializer/tests.rs | 2 +- .../src/paras/benchmarking/pvf_check.rs | 4 +- runtime/parachains/src/paras/mod.rs | 4 +- runtime/parachains/src/paras/tests.rs | 46 +++++++++---------- runtime/parachains/src/scheduler/tests.rs | 2 +- 11 files changed, 35 insertions(+), 35 deletions(-) diff --git a/node/test/service/src/lib.rs b/node/test/service/src/lib.rs index eaf2381977c3..446dea311b94 100644 --- a/node/test/service/src/lib.rs +++ b/node/test/service/src/lib.rs @@ -305,7 +305,7 @@ impl PolkadotTestNode { genesis: ParaGenesisArgs { genesis_head: genesis_head.into(), validation_code: validation_code.into(), - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, }, }; diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 710baebd9abb..1f8bc888df8e 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -629,7 +629,7 @@ impl Pallet { .saturating_add(per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into())) .saturating_add(per_byte_fee.saturating_mul((validation_code.0.len() as u32).into())); - Ok((ParaGenesisArgs { genesis_head, validation_code, parakind: paratype }, deposit)) + Ok((ParaGenesisArgs { genesis_head, validation_code, parachain: paratype }, deposit)) } /// Swap a parachain and parathread, which involves scheduling an appropriate lifecycle update. diff --git a/runtime/parachains/src/builder.rs b/runtime/parachains/src/builder.rs index e42cc2bf478b..714cba431731 100644 --- a/runtime/parachains/src/builder.rs +++ b/runtime/parachains/src/builder.rs @@ -346,7 +346,7 @@ impl BenchBuilder { paras::ParaGenesisArgs { genesis_head: Self::mock_head_data(), validation_code: mock_validation_code(), - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, }, ) .unwrap(); diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 8c538110af72..ffe12d9133f7 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -31,7 +31,7 @@ fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) &mut parachains, id, &crate::paras::ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/hrmp/tests.rs b/runtime/parachains/src/hrmp/tests.rs index 8fa260977590..e6062d34ee4d 100644 --- a/runtime/parachains/src/hrmp/tests.rs +++ b/runtime/parachains/src/hrmp/tests.rs @@ -133,7 +133,7 @@ fn register_parachain_with_balance(id: ParaId, balance: Balance) { assert_ok!(Paras::schedule_para_initialize( id, crate::paras::ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/inclusion/tests.rs b/runtime/parachains/src/inclusion/tests.rs index d8faeb489bed..12eab1d4264d 100644 --- a/runtime/parachains/src/inclusion/tests.rs +++ b/runtime/parachains/src/inclusion/tests.rs @@ -62,7 +62,7 @@ pub(crate) fn genesis_config(paras: Vec<(ParaId, ParaKind)>) -> MockGenesisConfi ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: dummy_validation_code(), - parakind: paratype, + parachain: paratype, }, ) }) diff --git a/runtime/parachains/src/initializer/tests.rs b/runtime/parachains/src/initializer/tests.rs index f74c345bb157..1a904ca7dbe4 100644 --- a/runtime/parachains/src/initializer/tests.rs +++ b/runtime/parachains/src/initializer/tests.rs @@ -91,7 +91,7 @@ fn scheduled_cleanup_performed() { let c = ParaId::from(123); let mock_genesis = crate::paras::ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: HeadData(vec![4, 5, 6]), validation_code: dummy_validation_code(), }; diff --git a/runtime/parachains/src/paras/benchmarking/pvf_check.rs b/runtime/parachains/src/paras/benchmarking/pvf_check.rs index 5e1b50557c2d..d9a46a12e449 100644 --- a/runtime/parachains/src/paras/benchmarking/pvf_check.rs +++ b/runtime/parachains/src/paras/benchmarking/pvf_check.rs @@ -140,7 +140,7 @@ where &mut parachains, id, &ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: old_validation_code, }, @@ -159,7 +159,7 @@ where let r = Pallet::::schedule_para_initialize( id, ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: validation_code(), }, diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index a9a7de0a6195..73f23ad172d6 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -292,7 +292,7 @@ pub struct ParaGenesisArgs { /// The initial validation code to use. pub validation_code: ValidationCode, /// Parachain or Parathread. - pub parakind: ParaKind, + pub parachain: ParaKind, } /// Distinguishes between Parachain and Parathread @@ -2062,7 +2062,7 @@ impl Pallet { id: ParaId, genesis_data: &ParaGenesisArgs, ) { - match genesis_data.parakind { + match genesis_data.parachain { ParaKind::Parachain => { parachains.add(id); ParaLifecycles::::insert(&id, ParaLifecycle::Parachain); diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index e5610b7ae681..4e042de45e11 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -222,7 +222,7 @@ fn schedule_para_init_rejects_empty_code() { Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![]), } @@ -233,7 +233,7 @@ fn schedule_para_init_rejects_empty_code() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![1]), } @@ -248,7 +248,7 @@ fn para_past_code_pruning_in_initialize() { ( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -256,7 +256,7 @@ fn para_past_code_pruning_in_initialize() { ( 1u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -316,7 +316,7 @@ fn note_new_head_sets_head() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -349,7 +349,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -357,7 +357,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 1u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -402,7 +402,7 @@ fn code_upgrade_applied_after_delay() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -505,7 +505,7 @@ fn code_upgrade_applied_after_delay_even_when_late() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -590,7 +590,7 @@ fn submit_code_change_when_not_allowed_is_err() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -658,7 +658,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -721,7 +721,7 @@ fn full_parachain_cleanup_storage() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -827,7 +827,7 @@ fn cannot_offboard_ongoing_pvf_check() { let paras = vec![( para_id, ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -900,7 +900,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: code_b.clone(), }, @@ -909,7 +909,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -918,7 +918,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( c, ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: vec![3].into(), validation_code: code_c.clone(), }, @@ -994,7 +994,7 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -1084,7 +1084,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { let paras = vec![( a, ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -1117,7 +1117,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - parakind: ParaKind::Parachain, + parachain: ParaKind::Parachain, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1185,7 +1185,7 @@ fn pvf_check_onboarding_reject_on_expiry() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1224,7 +1224,7 @@ fn pvf_check_upgrade_reject() { let paras = vec![( a, ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, @@ -1359,7 +1359,7 @@ fn pvf_check_submit_vote() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -1446,7 +1446,7 @@ fn include_pvf_check_statement_refunds_weight() { let paras = vec![( a, ParaGenesisArgs { - parakind: ParaKind::Parathread, + parachain: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index 63262e1ba22a..c6d22d0c7b0a 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -35,7 +35,7 @@ fn schedule_blank_para(id: ParaId, parakind: ParaKind) { ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: vec![1, 2, 3].into(), - parakind, + parachain, } )); } From 06825c3784cae0ccedbbe52909f225e886c980bd Mon Sep 17 00:00:00 2001 From: alexgparity Date: Sun, 30 Oct 2022 10:58:30 +0100 Subject: [PATCH 10/16] minor --- runtime/parachains/src/scheduler/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index c6d22d0c7b0a..4f87079c502f 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -35,7 +35,7 @@ fn schedule_blank_para(id: ParaId, parakind: ParaKind) { ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: vec![1, 2, 3].into(), - parachain, + parachain: parakind, } )); } From a9769b4911767b3e28f4137ec2ab79688e5fe10b Mon Sep 17 00:00:00 2001 From: alexgparity <115470171+alexgparity@users.noreply.github.com> Date: Sun, 30 Oct 2022 11:05:14 +0100 Subject: [PATCH 11/16] Update runtime/parachains/src/paras/mod.rs Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com> --- runtime/parachains/src/paras/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index 73f23ad172d6..de30c5a6801c 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -303,7 +303,7 @@ pub enum ParaKind { Parachain, } -// manual encoding, decoding, adn TypeInfo as the parakind field in ParaGenesisArgs used to be a bool +// Manual encoding, decoding, and TypeInfo as the parakind field in ParaGenesisArgs used to be a bool impl Encode for ParaKind { fn size_hint(&self) -> usize { true.size_hint() From 485ae0d458d664d8d438e263ebf96dc81b93ad41 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Sun, 30 Oct 2022 13:12:47 +0100 Subject: [PATCH 12/16] Manual serde Serialize and Deserialize for ParaKind --- node/test/service/src/lib.rs | 2 +- runtime/common/src/paras_registrar.rs | 4 +- runtime/parachains/src/builder.rs | 2 +- runtime/parachains/src/hrmp/benchmarking.rs | 2 +- runtime/parachains/src/hrmp/tests.rs | 2 +- runtime/parachains/src/inclusion/tests.rs | 4 +- runtime/parachains/src/initializer/tests.rs | 2 +- .../src/paras/benchmarking/pvf_check.rs | 4 +- runtime/parachains/src/paras/mod.rs | 33 +++++++++++-- runtime/parachains/src/paras/tests.rs | 46 +++++++++---------- runtime/parachains/src/scheduler/tests.rs | 2 +- 11 files changed, 65 insertions(+), 38 deletions(-) diff --git a/node/test/service/src/lib.rs b/node/test/service/src/lib.rs index 446dea311b94..831f0c85aaaa 100644 --- a/node/test/service/src/lib.rs +++ b/node/test/service/src/lib.rs @@ -305,7 +305,7 @@ impl PolkadotTestNode { genesis: ParaGenesisArgs { genesis_head: genesis_head.into(), validation_code: validation_code.into(), - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, }, }; diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 1f8bc888df8e..e86ed0b3baa4 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -614,7 +614,7 @@ impl Pallet { fn validate_onboarding_data( genesis_head: HeadData, validation_code: ValidationCode, - paratype: ParaKind, + para_kind: ParaKind, ) -> Result<(ParaGenesisArgs, BalanceOf), sp_runtime::DispatchError> { let config = configuration::Pallet::::config(); ensure!(validation_code.0.len() > 0, Error::::EmptyCode); @@ -629,7 +629,7 @@ impl Pallet { .saturating_add(per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into())) .saturating_add(per_byte_fee.saturating_mul((validation_code.0.len() as u32).into())); - Ok((ParaGenesisArgs { genesis_head, validation_code, parachain: paratype }, deposit)) + Ok((ParaGenesisArgs { genesis_head, validation_code, para_kind: para_kind}, deposit)) } /// Swap a parachain and parathread, which involves scheduling an appropriate lifecycle update. diff --git a/runtime/parachains/src/builder.rs b/runtime/parachains/src/builder.rs index 714cba431731..9a1c16e6aa1d 100644 --- a/runtime/parachains/src/builder.rs +++ b/runtime/parachains/src/builder.rs @@ -346,7 +346,7 @@ impl BenchBuilder { paras::ParaGenesisArgs { genesis_head: Self::mock_head_data(), validation_code: mock_validation_code(), - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, }, ) .unwrap(); diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index ffe12d9133f7..562e735e6a50 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -31,7 +31,7 @@ fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) &mut parachains, id, &crate::paras::ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/hrmp/tests.rs b/runtime/parachains/src/hrmp/tests.rs index e6062d34ee4d..85cdc459ffb9 100644 --- a/runtime/parachains/src/hrmp/tests.rs +++ b/runtime/parachains/src/hrmp/tests.rs @@ -133,7 +133,7 @@ fn register_parachain_with_balance(id: ParaId, balance: Balance) { assert_ok!(Paras::schedule_para_initialize( id, crate::paras::ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: vec![1].into(), }, diff --git a/runtime/parachains/src/inclusion/tests.rs b/runtime/parachains/src/inclusion/tests.rs index 12eab1d4264d..00369fb67e75 100644 --- a/runtime/parachains/src/inclusion/tests.rs +++ b/runtime/parachains/src/inclusion/tests.rs @@ -56,13 +56,13 @@ pub(crate) fn genesis_config(paras: Vec<(ParaId, ParaKind)>) -> MockGenesisConfi paras: paras::GenesisConfig { paras: paras .into_iter() - .map(|(id, paratype)| { + .map(|(id, para_kind)| { ( id, ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: dummy_validation_code(), - parachain: paratype, + para_kind, }, ) }) diff --git a/runtime/parachains/src/initializer/tests.rs b/runtime/parachains/src/initializer/tests.rs index 1a904ca7dbe4..d1d884200527 100644 --- a/runtime/parachains/src/initializer/tests.rs +++ b/runtime/parachains/src/initializer/tests.rs @@ -91,7 +91,7 @@ fn scheduled_cleanup_performed() { let c = ParaId::from(123); let mock_genesis = crate::paras::ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: HeadData(vec![4, 5, 6]), validation_code: dummy_validation_code(), }; diff --git a/runtime/parachains/src/paras/benchmarking/pvf_check.rs b/runtime/parachains/src/paras/benchmarking/pvf_check.rs index d9a46a12e449..e1400ac4297d 100644 --- a/runtime/parachains/src/paras/benchmarking/pvf_check.rs +++ b/runtime/parachains/src/paras/benchmarking/pvf_check.rs @@ -140,7 +140,7 @@ where &mut parachains, id, &ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: old_validation_code, }, @@ -159,7 +159,7 @@ where let r = Pallet::::schedule_para_initialize( id, ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: HeadData(vec![1, 2, 3, 4]), validation_code: validation_code(), }, diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index de30c5a6801c..f4769c9e2dcf 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -292,17 +292,44 @@ pub struct ParaGenesisArgs { /// The initial validation code to use. pub validation_code: ValidationCode, /// Parachain or Parathread. - pub parachain: ParaKind, + #[cfg_attr(feature = "std", serde(rename(serialize = "parachain", deserialize = "parachain")))] + pub para_kind: ParaKind, } /// Distinguishes between Parachain and Parathread #[derive(PartialEq, Eq, Clone, RuntimeDebug)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum ParaKind { Parathread, Parachain, } +#[cfg(feature = "std")] +impl Serialize for ParaKind { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match self { + ParaKind::Parachain => serializer.serialize_bool(true), + ParaKind::Parathread => serializer.serialize_bool(false), + } + } +} + +#[cfg(feature = "std")] +impl<'de> Deserialize<'de> for ParaKind { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + match serde::de::Deserialize::deserialize(deserializer) { + Ok(true) => Ok(ParaKind::Parachain), + Ok(false) => Ok(ParaKind::Parathread), + _ => Err(serde::de::Error::custom("invalid ParaKind serde representation")), + } + } +} + // Manual encoding, decoding, and TypeInfo as the parakind field in ParaGenesisArgs used to be a bool impl Encode for ParaKind { fn size_hint(&self) -> usize { @@ -2062,7 +2089,7 @@ impl Pallet { id: ParaId, genesis_data: &ParaGenesisArgs, ) { - match genesis_data.parachain { + match genesis_data.para_kind { ParaKind::Parachain => { parachains.add(id); ParaLifecycles::::insert(&id, ParaLifecycle::Parachain); diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index 4e042de45e11..5023f6fe683a 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -222,7 +222,7 @@ fn schedule_para_init_rejects_empty_code() { Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![]), } @@ -233,7 +233,7 @@ fn schedule_para_init_rejects_empty_code() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: ValidationCode(vec![1]), } @@ -248,7 +248,7 @@ fn para_past_code_pruning_in_initialize() { ( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -256,7 +256,7 @@ fn para_past_code_pruning_in_initialize() { ( 1u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -316,7 +316,7 @@ fn note_new_head_sets_head() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -349,7 +349,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -357,7 +357,7 @@ fn note_past_code_sets_up_pruning_correctly() { ( 1u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: dummy_head_data(), validation_code: dummy_validation_code(), }, @@ -402,7 +402,7 @@ fn code_upgrade_applied_after_delay() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -505,7 +505,7 @@ fn code_upgrade_applied_after_delay_even_when_late() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -590,7 +590,7 @@ fn submit_code_change_when_not_allowed_is_err() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -658,7 +658,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -721,7 +721,7 @@ fn full_parachain_cleanup_storage() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: original_code.clone(), }, @@ -827,7 +827,7 @@ fn cannot_offboard_ongoing_pvf_check() { let paras = vec![( para_id, ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -900,7 +900,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: vec![1].into(), validation_code: code_b.clone(), }, @@ -909,7 +909,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -918,7 +918,7 @@ fn para_incoming_at_session() { assert_ok!(Paras::schedule_para_initialize( c, ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: vec![3].into(), validation_code: code_c.clone(), }, @@ -994,7 +994,7 @@ fn code_hash_at_returns_up_to_end_of_code_retention_period() { let paras = vec![( 0u32.into(), ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: dummy_head_data(), validation_code: vec![1, 2, 3].into(), }, @@ -1084,7 +1084,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { let paras = vec![( a, ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: Default::default(), validation_code: existing_code, }, @@ -1117,7 +1117,7 @@ fn pvf_check_coalescing_onboarding_and_upgrade() { assert_ok!(Paras::schedule_para_initialize( b, ParaGenesisArgs { - parachain: ParaKind::Parachain, + para_kind: ParaKind::Parachain, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1185,7 +1185,7 @@ fn pvf_check_onboarding_reject_on_expiry() { assert_ok!(Paras::schedule_para_initialize( a, ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: validation_code.clone(), }, @@ -1224,7 +1224,7 @@ fn pvf_check_upgrade_reject() { let paras = vec![( a, ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, @@ -1359,7 +1359,7 @@ fn pvf_check_submit_vote() { assert_ok!(Paras::schedule_para_initialize( 1000.into(), ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: vec![2].into(), validation_code: code_a.clone(), }, @@ -1446,7 +1446,7 @@ fn include_pvf_check_statement_refunds_weight() { let paras = vec![( a, ParaGenesisArgs { - parachain: ParaKind::Parathread, + para_kind: ParaKind::Parathread, genesis_head: Default::default(), validation_code: old_code, }, diff --git a/runtime/parachains/src/scheduler/tests.rs b/runtime/parachains/src/scheduler/tests.rs index 4f87079c502f..40ff9db82871 100644 --- a/runtime/parachains/src/scheduler/tests.rs +++ b/runtime/parachains/src/scheduler/tests.rs @@ -35,7 +35,7 @@ fn schedule_blank_para(id: ParaId, parakind: ParaKind) { ParaGenesisArgs { genesis_head: Vec::new().into(), validation_code: vec![1, 2, 3].into(), - parachain: parakind, + para_kind: parakind, } )); } From 450c06c055e885f86dde56ed78f8b9ee657f1680 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Sun, 30 Oct 2022 13:15:17 +0100 Subject: [PATCH 13/16] cargo fmt --- runtime/common/src/paras_registrar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index e86ed0b3baa4..bfcc91e3ba71 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -629,7 +629,7 @@ impl Pallet { .saturating_add(per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into())) .saturating_add(per_byte_fee.saturating_mul((validation_code.0.len() as u32).into())); - Ok((ParaGenesisArgs { genesis_head, validation_code, para_kind: para_kind}, deposit)) + Ok((ParaGenesisArgs { genesis_head, validation_code, para_kind }, deposit)) } /// Swap a parachain and parathread, which involves scheduling an appropriate lifecycle update. From 9676fee58b59c4c986d4b8e879a9579b5c5cfa93 Mon Sep 17 00:00:00 2001 From: alexgparity <115470171+alexgparity@users.noreply.github.com> Date: Sun, 30 Oct 2022 13:16:55 +0100 Subject: [PATCH 14/16] Update runtime/parachains/src/paras/mod.rs Co-authored-by: Andronik --- runtime/parachains/src/paras/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index f4769c9e2dcf..3c5744b96546 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -292,7 +292,7 @@ pub struct ParaGenesisArgs { /// The initial validation code to use. pub validation_code: ValidationCode, /// Parachain or Parathread. - #[cfg_attr(feature = "std", serde(rename(serialize = "parachain", deserialize = "parachain")))] + #[cfg_attr(feature = "std", serde(rename = "parachain"))] pub para_kind: ParaKind, } From 1f496cf4669a27d5f35c6a48c3cc29e3af5d3aa6 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Sun, 30 Oct 2022 16:00:36 +0100 Subject: [PATCH 15/16] Add test for serde_json encoding/decoding --- Cargo.lock | 1 + runtime/parachains/Cargo.toml | 1 + runtime/parachains/src/paras/tests.rs | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ede6cb7363dd..f4ec558ca3d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7050,6 +7050,7 @@ dependencies = [ "sc-keystore", "scale-info", "serde", + "serde_json", "sp-api", "sp-application-crypto", "sp-core", diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 4361f443d9a9..a3412013dee6 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -11,6 +11,7 @@ log = { version = "0.4.17", default-features = false } rustc-hex = { version = "2.1.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.137", features = [ "derive" ], optional = true } +serde_json = "1.0.85" derive_more = "0.99.17" bitflags = "1.3.2" diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index 5023f6fe683a..f110e2a0d38a 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -1725,7 +1725,7 @@ fn verify_upgrade_restriction_signal_is_externally_accessible() { } #[test] -fn parakind_encodes_decodes_to_bool() { +fn parakind_encodes_decodes_to_bool_scale() { let chain_kind = ParaKind::Parachain.encode(); let chain_bool = true.encode(); assert_eq!(chain_kind, chain_bool); @@ -1742,3 +1742,22 @@ fn parakind_encodes_decodes_to_bool() { assert_eq!(bool::type_info(), ParaKind::type_info()); } + +#[test] +fn parakind_encodes_decodes_to_bool_serde() { + let chain = ParaKind::Parachain; + let ser_chain = serde_json::to_string(&ParaKind::Parachain).unwrap(); + let de_chain: ParaKind = serde_json::from_str(&ser_chain).unwrap(); + assert_eq!(chain, de_chain); + + let ser_true = serde_json::to_string(&true).unwrap(); + assert_eq!(ser_true, ser_chain); + + let thread = ParaKind::Parathread; + let ser_thread = serde_json::to_string(&thread).unwrap(); + let de_thread: ParaKind = serde_json::from_str(&ser_thread).unwrap(); + assert_eq!(thread, de_thread); + + let ser_false = serde_json::to_string(&false).unwrap(); + assert_eq!(ser_false, ser_thread); +} From 55ab444d99ceb4ac5fa1d0a25a81561935cffdc4 Mon Sep 17 00:00:00 2001 From: alexgparity Date: Tue, 1 Nov 2022 08:10:51 +0100 Subject: [PATCH 16/16] Move serde_json dep to dev-deps --- runtime/parachains/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index a3412013dee6..cb8b989ccdda 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -11,7 +11,6 @@ log = { version = "0.4.17", default-features = false } rustc-hex = { version = "2.1.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.137", features = [ "derive" ], optional = true } -serde_json = "1.0.85" derive_more = "0.99.17" bitflags = "1.3.2" @@ -58,6 +57,7 @@ test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../pri sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } thousands = "0.2.0" assert_matches = "1" +serde_json = "1.0.85" [features] default = ["std"]