Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Replace parachain/parathread boolean by enum #6198

Merged
merged 17 commits into from
Nov 1, 2022
Prev Previous commit
Next Next commit
ParaType -> ParaKind
  • Loading branch information
alexgparity committed Oct 28, 2022
commit 06550bdd283bfb742e21f7169a2926966cd3eee7
4 changes: 2 additions & 2 deletions node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -305,7 +305,7 @@ impl PolkadotTestNode {
genesis: ParaGenesisArgs {
genesis_head: genesis_head.into(),
validation_code: validation_code.into(),
paratype: ParaType::Parachain,
paratype: ParaKind::Parachain,
},
};

Expand Down
6 changes: 3 additions & 3 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -571,7 +571,7 @@ impl<T: Config> Pallet<T> {
};
ensure!(paras::Pallet::<T>::lifecycle(id).is_none(), Error::<T>::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) {
Expand Down Expand Up @@ -614,7 +614,7 @@ impl<T: Config> Pallet<T> {
fn validate_onboarding_data(
genesis_head: HeadData,
validation_code: ValidationCode,
paratype: ParaType,
paratype: ParaKind,
This conversation was marked as resolved.
Show resolved Hide resolved
) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> {
let config = configuration::Pallet::<T>::config();
ensure!(validation_code.0.len() > 0, Error::<T>::EmptyCode);
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{
configuration, inclusion, initializer, paras,
paras::ParaType,
paras::ParaKind,
paras_inherent::{self},
scheduler, session_info, shared,
};
Expand Down Expand Up @@ -346,7 +346,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
paras::ParaGenesisArgs {
genesis_head: Self::mock_head_data(),
validation_code: mock_validation_code(),
paratype: ParaType::Parachain,
paratype: ParaKind::Parachain,
},
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/hrmp/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -31,7 +31,7 @@ fn register_parachain_with_balance<T: Config>(id: ParaId, balance: BalanceOf<T>)
&mut parachains,
id,
&crate::paras::ParaGenesisArgs {
paratype: ParaType::Parachain,
paratype: ParaKind::Parachain,
genesis_head: vec![1].into(),
validation_code: vec![1].into(),
},
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/hrmp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
},
Expand Down
42 changes: 21 additions & 21 deletions runtime/parachains/src/inclusion/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -51,7 +51,7 @@ fn default_config() -> HostConfiguration<BlockNumber> {
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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/initializer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(),
};
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/paras/benchmarking/pvf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -159,7 +159,7 @@ where
let r = Pallet::<T>::schedule_para_initialize(
id,
ParaGenesisArgs {
paratype: ParaType::Parachain,
paratype: ParaKind::Parachain,
genesis_head: HeadData(vec![1, 2, 3, 4]),
validation_code: validation_code(),
},
Expand Down
8 changes: 4 additions & 4 deletions runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -2030,11 +2030,11 @@ impl<T: Config> Pallet<T> {
genesis_data: &ParaGenesisArgs,
) {
match genesis_data.paratype {
ParaType::Parachain => {
ParaKind::Parachain => {
parachains.add(id);
ParaLifecycles::<T>::insert(&id, ParaLifecycle::Parachain);
},
ParaType::Parathread => ParaLifecycles::<T>::insert(&id, ParaLifecycle::Parathread),
ParaKind::Parathread => ParaLifecycles::<T>::insert(&id, ParaLifecycle::Parathread),
}

// HACK: see the notice in `schedule_para_initialize`.
Expand Down
Loading