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

Starlight: Wire ContainerRegistrar and Registrar pallets #653

Merged
merged 59 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6b2f98d
first steps
Agusrodri Aug 7, 2024
a07c3ef
refactor and test
Agusrodri Aug 14, 2024
ecfaaed
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Aug 14, 2024
1345124
add tuple conversion for ParaRegistrationParams in tests
Agusrodri Aug 14, 2024
14e0250
add changes for mark_valid_for_collating and deregister
Agusrodri Aug 15, 2024
35d34b2
modify RegistrarHandler trait and add more tests
Agusrodri Aug 15, 2024
4eb4a71
add TS test
Agusrodri Aug 20, 2024
80eedbc
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Aug 20, 2024
86afe09
add more TS tests
Agusrodri Aug 21, 2024
9e93f72
fix syntax
Agusrodri Aug 21, 2024
138f6db
remove clone
Agusrodri Aug 21, 2024
b645892
modify MaxEncodedGenesisDataSize
Agusrodri Aug 22, 2024
9975471
add BufferedParasToDeregister
Agusrodri Aug 22, 2024
dca620e
fix deregistration rust test
Agusrodri Aug 22, 2024
749b44f
TS tests now working
Agusrodri Aug 22, 2024
b9c069a
fmt
Agusrodri Aug 22, 2024
f0d0dec
TS lint
Agusrodri Aug 22, 2024
8541763
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Aug 22, 2024
7a92da1
use run_block() instead
Agusrodri Aug 23, 2024
88c54c9
at the end run_block is not needed in test
Agusrodri Aug 23, 2024
2f0a142
PR suggestions in pallet_registrar
Agusrodri Aug 23, 2024
ea7e018
add comment
Agusrodri Aug 23, 2024
427d048
account for proper weight inside on_initialize()
Agusrodri Aug 23, 2024
c0b4efe
add test for deregistering two paras
Agusrodri Aug 24, 2024
146ec2d
fmt
Agusrodri Aug 24, 2024
4edc2ff
make all trait functions to behave as hooks
Agusrodri Aug 27, 2024
4f0a4a5
set MaxGenesisDataSize to 5MB again
Agusrodri Aug 27, 2024
2299e61
add head_data param to register functions
Agusrodri Aug 28, 2024
de0933f
fix tests
Agusrodri Aug 28, 2024
8060b00
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Aug 28, 2024
be84061
fmt
Agusrodri Aug 28, 2024
7ebedb7
fix build
Agusrodri Aug 28, 2024
5cc9f78
fmt
Agusrodri Aug 28, 2024
8ad6dc3
make trait functions fallible again
Agusrodri Aug 28, 2024
59cef34
fix rust tests
Agusrodri Aug 29, 2024
cc6e792
fix dancebox and flashbox TS tests
Agusrodri Aug 29, 2024
150dd7b
fix dev_tanssi_relay TS tests
Agusrodri Aug 29, 2024
3775849
fix zombie tests
Agusrodri Aug 29, 2024
3823f2d
clippy
Agusrodri Aug 30, 2024
d952d1e
fmt
Agusrodri Aug 30, 2024
67b8a88
generate new api-augment interfaces
Agusrodri Aug 30, 2024
48a4a7e
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Aug 30, 2024
b762692
api-augment again
Agusrodri Aug 30, 2024
9a76e31
add more docs
Agusrodri Aug 30, 2024
ecb457d
fix core scheduling test
Agusrodri Aug 30, 2024
cf97156
add test for invalid wasm
Agusrodri Aug 30, 2024
1da1601
add registrar errors to ContainerRegistrar
Agusrodri Aug 30, 2024
368163e
fmt
Agusrodri Aug 30, 2024
293d3bf
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Aug 30, 2024
694f2f1
cargo fmt
Agusrodri Aug 30, 2024
31b4455
api-augment
Agusrodri Aug 30, 2024
29bf2d8
add a way to test InnerRegistrar calls in pallet registrar
Agusrodri Sep 2, 2024
e51b495
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Sep 2, 2024
1d7a9ca
adapt previous tests
Agusrodri Sep 3, 2024
433dfea
comment
Agusrodri Sep 3, 2024
5992697
Merge remote-tracking branch 'origin/master' into agustin-wire-regist…
Agusrodri Sep 3, 2024
73daab1
pr comments
Agusrodri Sep 3, 2024
b5517b4
Avoid clone of genesis storage in dancebox
tmpolaczyk Sep 4, 2024
e83f4a4
fix mock
Agusrodri Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions pallets/registrar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ use {
sp_std::{collections::btree_set::BTreeSet, prelude::*},
tp_traits::{
GetCurrentContainerChains, GetSessionContainerChains, GetSessionIndex, ParaId,
ParathreadParams as ParathreadParamsTy, RelayStorageRootProvider, SessionContainerChains,
SlotFrequency,
ParathreadParams as ParathreadParamsTy, RegistrarHandler, RelayStorageRootProvider,
SessionContainerChains, SlotFrequency,
},
};

Expand Down Expand Up @@ -176,6 +176,8 @@ pub mod pallet {

type RegistrarHooks: RegistrarHooks;

type InnerRegistrar: RegistrarHandler<Self::AccountId>;
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved

type WeightInfo: WeightInfo;
}

Expand Down Expand Up @@ -798,6 +800,8 @@ pub mod pallet {
// Hold the deposit, we verified we can do this
T::Currency::hold(&HoldReason::RegistrarDeposit.into(), &account, deposit)?;

T::InnerRegistrar::register(account.clone(), para_id, genesis_data.clone().storage)?;

// Update DepositInfo
RegistrarDeposit::<T>::insert(
para_id,
Expand Down Expand Up @@ -846,6 +850,7 @@ pub mod pallet {
})?;
// Mark this para id for cleanup later
Self::schedule_parachain_cleanup(para_id)?;
T::InnerRegistrar::schedule_para_downgrade(para_id)?;
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
Self::deposit_event(Event::ParaIdDeregistered { para_id });
}

Expand Down Expand Up @@ -882,6 +887,8 @@ pub mod pallet {

T::RegistrarHooks::para_marked_valid_for_collating(para_id);

T::InnerRegistrar::schedule_para_upgrade(para_id)?;

Ok(())
}

Expand Down Expand Up @@ -1203,6 +1210,7 @@ pub mod pallet {
ParaManager::<T>::remove(para_id);

T::RegistrarHooks::para_deregistered(para_id);
T::InnerRegistrar::deregister(para_id);
}

fn schedule_parachain_cleanup(para_id: ParaId) -> DispatchResult {
Expand Down
1 change: 1 addition & 0 deletions pallets/registrar/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl pallet_registrar::Config for Test {
type DepositAmount = DepositAmount;
type RuntimeHoldReason = RuntimeHoldReason;
type RegistrarHooks = Mock;
type InnerRegistrar = ();
girazoki marked this conversation as resolved.
Show resolved Hide resolved
type WeightInfo = ();
}

Expand Down
2 changes: 2 additions & 0 deletions primitives/traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ workspace = true

[dependencies]
dp-chain-state-snapshot = { workspace = true }
dp-container-chain-genesis-data = { workspace = true }
frame-support = { workspace = true }
impl-trait-for-tuples = { workspace = true }
macro_rules_attribute = { workspace = true }
Expand All @@ -29,6 +30,7 @@ default = [ "std" ]
std = [
"cumulus-primitives-core/std",
"dp-chain-state-snapshot/std",
"dp-container-chain-genesis-data/std",
"frame-support/std",
"parity-scale-codec/std",
"scale-info/std",
Expand Down
41 changes: 39 additions & 2 deletions primitives/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ pub mod alias;
pub use {
alias::*,
cumulus_primitives_core::{
relay_chain::{BlockNumber, Slot},
relay_chain::{BlockNumber, HeadData, Slot, ValidationCode},
ParaId,
},
dp_chain_state_snapshot::{GenericStateProof, ReadEntryErr},
dp_container_chain_genesis_data::ContainerChainGenesisDataItem,
};
use {
core::marker::PhantomData,
frame_support::{
dispatch::DispatchErrorWithPostInfo,
pallet_prelude::{Decode, DispatchResultWithPostInfo, Encode, Get, MaxEncodedLen, Weight},
pallet_prelude::{
Decode, DispatchResult, DispatchResultWithPostInfo, Encode, Get, MaxEncodedLen, Weight,
},
BoundedVec,
},
serde::{Deserialize, Serialize},
Expand Down Expand Up @@ -366,3 +369,37 @@ impl GenericStorageReader for NativeStorageReader {
}
}
}

pub trait RegistrarHandler<AccountId> {
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
fn register(
who: AccountId,
id: ParaId,
genesis_storage: Vec<ContainerChainGenesisDataItem>,
) -> DispatchResult;

fn schedule_para_upgrade(id: ParaId) -> DispatchResult;
fn schedule_para_downgrade(id: ParaId) -> DispatchResult;
fn deregister(id: ParaId) -> Weight;
}

impl<AccountId> RegistrarHandler<AccountId> for () {
fn register(
_who: AccountId,
_id: ParaId,
_genesis_storage: Vec<ContainerChainGenesisDataItem>,
) -> DispatchResult {
Ok(())
}

fn schedule_para_upgrade(_id: ParaId) -> DispatchResult {
Ok(())
}

fn schedule_para_downgrade(_id: ParaId) -> DispatchResult {
Ok(())
}

fn deregister(_id: ParaId) -> Weight {
Weight::default()
}
}
1 change: 1 addition & 0 deletions runtime/dancebox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,7 @@ impl pallet_registrar::Config for Runtime {
type DepositAmount = DepositAmount;
type RegistrarHooks = DanceboxRegistrarHooks;
type RuntimeHoldReason = RuntimeHoldReason;
type InnerRegistrar = ();
type WeightInfo = weights::pallet_registrar::SubstrateWeight<Runtime>;
}

Expand Down
1 change: 1 addition & 0 deletions runtime/flashbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ impl pallet_registrar::Config for Runtime {
type DepositAmount = DepositAmount;
type RegistrarHooks = FlashboxRegistrarHooks;
type RuntimeHoldReason = RuntimeHoldReason;
type InnerRegistrar = ();
type WeightInfo = weights::pallet_registrar::SubstrateWeight<Runtime>;
}

Expand Down
71 changes: 67 additions & 4 deletions solo-chains/runtime/starlight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use {
ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature},
mmr::{BeefyDataProvider, MmrLeafVersion},
},
cumulus_primitives_core::relay_chain::{HeadData, ValidationCode},
dp_container_chain_genesis_data::ContainerChainGenesisDataItem,
frame_support::{
dispatch::DispatchResult,
dynamic_params::{dynamic_pallet_params, dynamic_params},
Expand All @@ -47,7 +49,7 @@ use {
CommittedCandidateReceipt, CoreIndex, CoreState, DisputeState, ExecutorParams,
GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, Moment,
NodeFeatures, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes,
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
SessionInfo, Signature, ValidationCodeHash, ValidatorId, ValidatorIndex,
PARACHAIN_KEY_TYPE_ID,
},
runtime_common::{
Expand All @@ -56,7 +58,9 @@ use {
ContainsParts, LocatableAssetConverter, ToAuthor, VersionedLocatableAsset,
VersionedLocationConverter,
},
paras_registrar, paras_sudo_wrapper, BlockHashCount, BlockLength, SlowAdjustingFeeUpdate,
paras_registrar, paras_sudo_wrapper,
traits::Registrar as RegistrarInterface,
BlockHashCount, BlockLength, SlowAdjustingFeeUpdate,
},
runtime_parachains::{
assigner_on_demand as parachains_assigner_on_demand,
Expand All @@ -73,15 +77,19 @@ use {
shared as parachains_shared,
},
scale_info::TypeInfo,
sp_core::storage::well_known_keys as StorageWellKnownKeys,
sp_genesis_builder::PresetId,
sp_runtime::traits::BlockNumberProvider,
sp_runtime::{traits::BlockNumberProvider, DispatchError},
sp_std::{
cmp::Ordering,
collections::{btree_map::BTreeMap, btree_set::BTreeSet, vec_deque::VecDeque},
marker::PhantomData,
prelude::*,
},
tp_traits::{GetSessionContainerChains, RemoveParaIdsWithNoCredits, Slot, SlotFrequency},
tp_traits::{
GetSessionContainerChains, RegistrarHandler, RemoveParaIdsWithNoCredits, Slot,
SlotFrequency,
},
};

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -1484,6 +1492,60 @@ parameter_types! {
pub const MaxLengthParaIds: u32 = 100u32;
pub const MaxEncodedGenesisDataSize: u32 = 5_000_000u32; // 5MB
}

pub struct InnerStarlightRegistrar<AccountId, RegistrarManager>(
PhantomData<(AccountId, RegistrarManager)>,
);
impl<AccountId, RegistrarManager> RegistrarHandler<AccountId>
for InnerStarlightRegistrar<AccountId, RegistrarManager>
where
RegistrarManager: RegistrarInterface<AccountId = AccountId>,
{
fn register(
who: AccountId,
id: ParaId,
genesis_storage: Vec<ContainerChainGenesisDataItem>,
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
) -> DispatchResult {
// Build HeadData
let key_values: Vec<(Vec<u8>, Vec<u8>)> =
genesis_storage.into_iter().map(|x| x.into()).collect();
let genesis_head = HeadData(key_values.clone().encode());
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved

// Check if the wasm code is present in storage
let kv_code = key_values
.into_iter()
.find(|kv| kv.0 == StorageWellKnownKeys::CODE.to_vec());

if let None = kv_code {
return Err(DispatchError::Other("Code not found"));
}

// Build ValidationCode
let validation_code = ValidationCode(kv_code.unwrap().1);
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
RegistrarManager::register(who, id, genesis_head, validation_code)
}

fn schedule_para_upgrade(id: ParaId) -> DispatchResult {
RegistrarManager::make_parachain(id)
}

fn schedule_para_downgrade(id: ParaId) -> DispatchResult {
RegistrarManager::make_parathread(id)
}

fn deregister(id: ParaId) -> Weight {
if let Err(e) = RegistrarManager::deregister(id) {
log::warn!(
"Failed to deregister para id {} in relay chain: {:?}",
u32::from(id),
e,
);
}

Weight::default()
}
}

impl pallet_registrar::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RegistrarOrigin = EnsureRoot<AccountId>;
Expand All @@ -1499,6 +1561,7 @@ impl pallet_registrar::Config for Runtime {
type DepositAmount = DepositAmount;
type RegistrarHooks = StarlightRegistrarHooks;
type RuntimeHoldReason = RuntimeHoldReason;
type InnerRegistrar = InnerStarlightRegistrar<AccountId, Registrar>;
type WeightInfo = pallet_registrar::weights::SubstrateWeight<Runtime>;
}

Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
12 changes: 12 additions & 0 deletions solo-chains/runtime/starlight/src/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ pub struct ParaRegistrationParams {
pub parathread_params: Option<tp_traits::ParathreadParams>,
}

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,
parathread_params: None,
}
}
}

pub fn default_config() -> pallet_configuration::HostConfiguration {
pallet_configuration::HostConfiguration {
max_collators: 100,
Expand Down
Loading
Loading