Skip to content

Commit

Permalink
Allow registering parathreads in pallet_registrar genesis (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk authored Jul 31, 2024
1 parent 12eaef3 commit 7d2caa7
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 399 deletions.
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))
.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)>,
pub para_ids: Vec<(
ParaId,
ContainerChainGenesisData,
Option<ParathreadParamsTy>,
)>,
pub phantom: PhantomData<T>,
}

Expand All @@ -102,7 +106,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 @@ -117,6 +121,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},
dp_container_chain_genesis_data::ContainerChainGenesisData,
frame_support::{
traits::{ConstU16, ConstU64},
Expand Down Expand Up @@ -311,7 +311,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)>,
para_ids: Vec<(
ParaId,
ContainerChainGenesisData,
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
42 changes: 26 additions & 16 deletions runtime/dancebox/src/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,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,
block_production_credits: u32,
collator_assignment_credits: u32,
}

impl From<(u32, ContainerChainGenesisData, u32, u32)> for ParaRegistrationParams {
fn from(value: (u32, ContainerChainGenesisData, 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,
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 @@ -387,6 +377,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 @@ -422,7 +428,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(),
phantom: Default::default(),
Expand Down
Loading

0 comments on commit 7d2caa7

Please sign in to comment.