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
Manual serde Serialize and Deserialize for ParaKind
alexgparity committed Oct 30, 2022

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
commit 485ae0d458d664d8d438e263ebf96dc81b93ad41
2 changes: 1 addition & 1 deletion node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
},
};

4 changes: 2 additions & 2 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
@@ -614,7 +614,7 @@ impl<T: Config> Pallet<T> {
fn validate_onboarding_data(
genesis_head: HeadData,
validation_code: ValidationCode,
paratype: ParaKind,
para_kind: ParaKind,
) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> {
let config = configuration::Pallet::<T>::config();
ensure!(validation_code.0.len() > 0, Error::<T>::EmptyCode);
@@ -629,7 +629,7 @@ impl<T: Config> Pallet<T> {
.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.
2 changes: 1 addition & 1 deletion runtime/parachains/src/builder.rs
Original file line number Diff line number Diff line change
@@ -346,7 +346,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
paras::ParaGenesisArgs {
genesis_head: Self::mock_head_data(),
validation_code: mock_validation_code(),
parachain: ParaKind::Parachain,
para_kind: ParaKind::Parachain,
},
)
.unwrap();
2 changes: 1 addition & 1 deletion runtime/parachains/src/hrmp/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ fn register_parachain_with_balance<T: Config>(id: ParaId, balance: BalanceOf<T>)
&mut parachains,
id,
&crate::paras::ParaGenesisArgs {
parachain: ParaKind::Parachain,
para_kind: ParaKind::Parachain,
genesis_head: vec![1].into(),
validation_code: vec![1].into(),
},
2 changes: 1 addition & 1 deletion runtime/parachains/src/hrmp/tests.rs
Original file line number Diff line number Diff line change
@@ -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(),
},
4 changes: 2 additions & 2 deletions runtime/parachains/src/inclusion/tests.rs
Original file line number Diff line number Diff line change
@@ -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,
},
)
})
2 changes: 1 addition & 1 deletion runtime/parachains/src/initializer/tests.rs
Original file line number Diff line number Diff line change
@@ -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(),
};
4 changes: 2 additions & 2 deletions runtime/parachains/src/paras/benchmarking/pvf_check.rs
Original file line number Diff line number Diff line change
@@ -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::<T>::schedule_para_initialize(
id,
ParaGenesisArgs {
parachain: ParaKind::Parachain,
para_kind: ParaKind::Parachain,
genesis_head: HeadData(vec![1, 2, 3, 4]),
validation_code: validation_code(),
},
33 changes: 30 additions & 3 deletions runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
@@ -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")))]
This conversation was marked as resolved.
Show resolved Hide resolved
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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<D>(deserializer: D) -> Result<Self, D::Error>
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<T: Config> Pallet<T> {
id: ParaId,
genesis_data: &ParaGenesisArgs,
) {
match genesis_data.parachain {
match genesis_data.para_kind {
ParaKind::Parachain => {
parachains.add(id);
ParaLifecycles::<T>::insert(&id, ParaLifecycle::Parachain);
46 changes: 23 additions & 23 deletions runtime/parachains/src/paras/tests.rs
Original file line number Diff line number Diff line change
@@ -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,15 +248,15 @@ 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(),
},
),
(
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,15 +349,15 @@ 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(),
},
),
(
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,
},
2 changes: 1 addition & 1 deletion runtime/parachains/src/scheduler/tests.rs
Original file line number Diff line number Diff line change
@@ -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,
}
));
}