Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow registering parathreads in pallet_registrar genesis #632

Merged
merged 11 commits into from
Jul 31, 2024
2 changes: 1 addition & 1 deletion node/src/chain_spec/dancebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn testnet_genesis(
.collect();
let para_ids: Vec<_> = para_ids
.into_iter()
.map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data))
.map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data, None))
.collect();

let accounts_with_ed = [
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec/flashbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn testnet_genesis(

let para_ids: Vec<_> = para_ids
.into_iter()
.map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data))
.map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data, None))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should find a way to pass them as parathreads. Maybe the cleanest is with a new command line argument dont you think? Or alternatively, something in the spec that indicates whether it is a parathread..

.collect();

let accounts_with_ed = [
Expand Down
12 changes: 10 additions & 2 deletions pallets/registrar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ pub mod pallet {
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
/// Para ids
pub para_ids: Vec<(ParaId, ContainerChainGenesisData<T::MaxLengthTokenSymbol>)>,
pub para_ids: Vec<(
ParaId,
ContainerChainGenesisData<T::MaxLengthTokenSymbol>,
Option<ParathreadParamsTy>,
)>,
}

#[pallet::genesis_build]
Expand All @@ -101,7 +105,7 @@ pub mod pallet {

let mut bounded_para_ids = BoundedVec::default();

for (para_id, genesis_data) in para_ids {
for (para_id, genesis_data, parathread_params) in para_ids {
bounded_para_ids
.try_push(*para_id)
.expect("too many para ids in genesis: bounded vec full");
Expand All @@ -116,6 +120,10 @@ pub mod pallet {
);
}
<ParaGenesisData<T>>::insert(para_id, genesis_data);

if let Some(parathread_params) = parathread_params {
<ParathreadParams<T>>::insert(para_id, parathread_params);
}
}

<RegisteredParaIds<T>>::put(bounded_para_ids);
Expand Down
8 changes: 6 additions & 2 deletions pallets/registrar/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::{self as pallet_registrar, RegistrarHooks},
crate::{self as pallet_registrar, ParathreadParamsTy, RegistrarHooks},
frame_support::{
traits::{ConstU16, ConstU64},
weights::Weight,
Expand Down Expand Up @@ -313,7 +313,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext_with_genesis(
para_ids: Vec<(ParaId, ContainerChainGenesisData<MaxLengthTokenSymbol>)>,
para_ids: Vec<(
ParaId,
ContainerChainGenesisData<MaxLengthTokenSymbol>,
Option<ParathreadParamsTy>,
)>,
) -> sp_io::TestExternalities {
RuntimeGenesisConfig {
system: Default::default(),
Expand Down
26 changes: 13 additions & 13 deletions pallets/registrar/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,10 @@ fn unpause_para_id_42_fails_not_registered() {
#[test]
fn genesis_loads_para_ids() {
new_test_ext_with_genesis(vec![
(1.into(), empty_genesis_data()),
(2.into(), empty_genesis_data()),
(3.into(), empty_genesis_data()),
(4.into(), empty_genesis_data()),
(1.into(), empty_genesis_data(), None),
(2.into(), empty_genesis_data(), None),
(3.into(), empty_genesis_data(), None),
(4.into(), empty_genesis_data(), None),
])
.execute_with(|| {
run_to_block(1);
Expand All @@ -556,10 +556,10 @@ fn genesis_loads_para_ids() {
#[test]
fn genesis_sorts_para_ids() {
new_test_ext_with_genesis(vec![
(4.into(), empty_genesis_data()),
(2.into(), empty_genesis_data()),
(3.into(), empty_genesis_data()),
(1.into(), empty_genesis_data()),
(4.into(), empty_genesis_data(), None),
(2.into(), empty_genesis_data(), None),
(3.into(), empty_genesis_data(), None),
(1.into(), empty_genesis_data(), None),
])
.execute_with(|| {
run_to_block(1);
Expand All @@ -574,10 +574,10 @@ fn genesis_sorts_para_ids() {
#[should_panic = "Duplicate para_id: 2"]
fn genesis_error_on_duplicate() {
new_test_ext_with_genesis(vec![
(2.into(), empty_genesis_data()),
(3.into(), empty_genesis_data()),
(4.into(), empty_genesis_data()),
(2.into(), empty_genesis_data()),
(2.into(), empty_genesis_data(), None),
(3.into(), empty_genesis_data(), None),
(4.into(), empty_genesis_data(), None),
(2.into(), empty_genesis_data(), None),
])
.execute_with(|| {
run_to_block(1);
Expand All @@ -595,7 +595,7 @@ fn genesis_error_genesis_data_size_too_big() {
extensions: Default::default(),
properties: Default::default(),
};
new_test_ext_with_genesis(vec![(2.into(), genesis_data)]).execute_with(|| {
new_test_ext_with_genesis(vec![(2.into(), genesis_data, None)]).execute_with(|| {
run_to_block(1);
});
}
Expand Down
56 changes: 26 additions & 30 deletions runtime/dancebox/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,35 +304,11 @@ pub fn set_parachain_inherent_data_random_seed(random_seed: [u8; 32]) {

#[derive(Default, Clone)]
pub struct ParaRegistrationParams {
para_id: u32,
genesis_data: ContainerChainGenesisData<MaxLengthTokenSymbol>,
block_production_credits: u32,
collator_assignment_credits: u32,
}

impl
From<(
u32,
ContainerChainGenesisData<MaxLengthTokenSymbol>,
u32,
u32,
)> for ParaRegistrationParams
{
fn from(
value: (
u32,
ContainerChainGenesisData<MaxLengthTokenSymbol>,
u32,
u32,
),
) -> Self {
Self {
para_id: value.0,
genesis_data: value.1,
block_production_credits: value.2,
collator_assignment_credits: value.3,
}
}
pub para_id: u32,
pub genesis_data: ContainerChainGenesisData<MaxLengthTokenSymbol>,
pub block_production_credits: u32,
pub collator_assignment_credits: u32,
pub parathread_params: Option<tp_traits::ParathreadParams>,
}

pub fn default_config() -> pallet_configuration::HostConfiguration {
Expand Down Expand Up @@ -403,6 +379,22 @@ impl ExtBuilder {
self
}

/// Helper function like `with_para_ids` but registering parachains with an empty genesis data,
/// and max amount of credits.
pub fn with_empty_parachains(mut self, para_ids: Vec<u32>) -> Self {
self.para_ids = para_ids
.into_iter()
.map(|para_id| ParaRegistrationParams {
para_id,
genesis_data: empty_genesis_data(),
block_production_credits: u32::MAX,
collator_assignment_credits: u32::MAX,
parathread_params: None,
})
.collect();
self
}

pub fn with_config(mut self, config: pallet_configuration::HostConfiguration) -> Self {
self.config = config;
self
Expand Down Expand Up @@ -438,7 +430,11 @@ impl ExtBuilder {
.iter()
.cloned()
.map(|registered_para| {
(registered_para.para_id.into(), registered_para.genesis_data)
(
registered_para.para_id.into(),
registered_para.genesis_data,
registered_para.parathread_params,
)
})
.collect(),
}
Expand Down
Loading
Loading