Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Lockdown Mode pallet. #163

Merged
merged 15 commits into from
May 12, 2023
Merged

Lockdown Mode pallet. #163

merged 15 commits into from
May 12, 2023

Conversation

hbulgarini
Copy link
Contributor

@hbulgarini hbulgarini commented Apr 27, 2023

This PR implements a lockdown mode pallet inspired in the Moonbeam maintenance pallet implementation.

Specs can be found here: #144 (comment)

Closes #144

pallets/maintenance-mode/src/lib.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/lib.rs Outdated Show resolved Hide resolved
@hbulgarini hbulgarini marked this pull request as ready for review May 8, 2023 11:49
@hbulgarini
Copy link
Contributor Author

The PR is ready to be reviewed now. Still needs to be confirmed, but it seems the chess pallet is the responsable for the wasm exceed during execution.

pallets/maintenance-mode/src/lib.rs Outdated Show resolved Hide resolved
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
MaintenanceModeStatus::<T>::put(ACTIVATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the reason for having it activated at the start?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so we can have the chance to check that everything is fine before making the operations available.

Copy link
Contributor

@kalaninja kalaninja May 12, 2023

Choose a reason for hiding this comment

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

I got it, but it doesn't seem to be responsibility of the pallet. This decision (on or off at the start) should be taken on a composition root level. My suggestion here is to add activated into the genesis config

	#[pallet::genesis_config]
	/// Genesis config for lockdown mode pallet
	pub struct GenesisConfig<T: Config> {
		pub activated: bool,
		pub _phantom: PhantomData<T>,
	}

	impl<T: Config> Default for GenesisConfig<T> {
		fn default() -> Self {
			Self { activated: ACTIVATED, _phantom: PhantomData }
		}
	}

	#[pallet::genesis_build]
	impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
		fn build(&self) {
			LockdownModeStatus::<T>::put(&self.activated);
		}
	}

this will also let you to set initial state for you tests

pub fn new_test_ext(activated: bool) -> sp_io::TestExternalities {
	let mut storage = system::GenesisConfig::default().build_storage::<Test>().unwrap();
	pallet_lockdown_mode::GenesisConfig::<Test> { activated, _phantom: PhantomData }
		.assimilate_storage(&mut storage)
		.unwrap();

	storage.into()
}

So that you don't need to activate lockdown mode first to deactivate it in the next step.

You can also add a test to make sure that the storage is initialized properly

#[test]
fn initialized() {
	[true, false].into_iter().for_each(|expected| {
		new_test_ext(expected).execute_with(|| {
			let lockdown_mode = LockdownModeStatus::<Test>::get();
			assert_eq!(lockdown_mode, expected);
		});
	});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@hbulgarini I think @kalaninja makes sense. If you can apply those changes, we should be good then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pallets/maintenance-mode/src/lib.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/lib.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/lib.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/tests.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/tests.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/tests.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/weights.rs Outdated Show resolved Hide resolved
pallets/maintenance-mode/src/lib.rs Outdated Show resolved Hide resolved
@stiiifff
Copy link
Contributor

@hbulgarini I think calling this pallet lockdown-mode would better represent the intent (I just found out that Apple has such a mode in iOS).

@hbulgarini hbulgarini requested a review from kalaninja May 11, 2023 19:29
@hbulgarini hbulgarini changed the title Maintenance Mode pallet. Lockdown Mode pallet. May 11, 2023
@hbulgarini
Copy link
Contributor Author

@stiiifff @kalaninja @valentinfernandez1 , i have addressed all the comments.

pallets/lockdown-mode/src/lib.rs Outdated Show resolved Hide resolved
pallets/lockdown-mode/src/lib.rs Outdated Show resolved Hide resolved
@hbulgarini hbulgarini requested a review from kalaninja May 12, 2023 10:02
stiiifff
stiiifff previously approved these changes May 12, 2023
@hbulgarini hbulgarini requested a review from stiiifff May 12, 2023 10:17
@hbulgarini
Copy link
Contributor Author

@kalaninja , i have to solve some conflicts on this branch because of the merge of the PR #165, could you please make sure that something was not incorrectly solved during the sync? Then if everything looks fine, you can just approve and merge. @stiiifff already approved it but due to the re-sync the approval was missed.

@stiiifff
Copy link
Contributor

@hbulgarini approved but I think it'd be nice to implement @kalaninja 's suggestion (see above).

Copy link
Contributor

@stiiifff stiiifff left a comment

Choose a reason for hiding this comment

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

LGTM. Let's create a new issue with @kalaninja's improvement suggestion.

@stiiifff stiiifff merged commit ddf574f into main May 12, 2023
@stiiifff stiiifff deleted the hb-maintenance-mode-pallet branch May 12, 2023 12:58
@stiiifff stiiifff mentioned this pull request May 16, 2023
18 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Trappist on Rococo] Add pallet for maintenance mode
4 participants