-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sudo * change Root into Root +democracy * debug: recover chainspec rootkey * fix clippy * try to fix #900 * add debug log #900 * make CI tests pass after remove litmus `Sudo` * fmt * debug * debug * rococo/litentry align with litmus * remove useless test code Co-authored-by: Kai <[email protected]> Co-authored-by: BillyWooo <[email protected]> Co-authored-by: zhiming-zhong <[email protected]>
- Loading branch information
1 parent
b2be7f6
commit 3ddb119
Showing
11 changed files
with
161 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2020-2021 Litentry Technologies GmbH. | ||
// This file is part of Litentry. | ||
// | ||
// Litentry is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Litentry is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Litentry. If not, see <https://www.gnu.org/licenses/>. | ||
use frame_support::{ | ||
traits::{Get, OnRuntimeUpgrade}, | ||
StorageHasher, Twox128, | ||
}; | ||
use sp_std::marker::PhantomData; | ||
|
||
pub struct RemoveSudoAndStorage<T>(PhantomData<T>); | ||
impl<T> OnRuntimeUpgrade for RemoveSudoAndStorage<T> | ||
where | ||
T: frame_system::Config, | ||
{ | ||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<(), &'static str> { | ||
log::info!("Pre check pallet Sudo exists"); | ||
assert!( | ||
frame_support::storage::migration::have_storage_value(b"Sudo", b"Key", b"",), | ||
"Storage query fails: Sudo Key" | ||
); | ||
Ok(()) | ||
} | ||
|
||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
use sp_io::KillStorageResult; | ||
// Remove Sudo Storage | ||
// TODO: Very Weak safety | ||
let entries: u64 = 4 + 100; | ||
let _res: KillStorageResult = frame_support::storage::unhashed::clear_prefix( | ||
&Twox128::hash(b"Sudo"), | ||
Some(entries.try_into().unwrap()), | ||
None, | ||
) | ||
.into(); | ||
<T as frame_system::Config>::DbWeight::get().writes(entries) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade() -> Result<(), &'static str> { | ||
use sp_io::KillStorageResult; | ||
|
||
log::info!("Post check Sudo"); | ||
let res: KillStorageResult = | ||
frame_support::storage::unhashed::clear_prefix(&Twox128::hash(b"Sudo"), Some(0), None) | ||
.into(); | ||
|
||
match res { | ||
KillStorageResult::AllRemoved(0) | KillStorageResult::SomeRemaining(0) => {}, | ||
KillStorageResult::AllRemoved(n) | KillStorageResult::SomeRemaining(n) => { | ||
log::error!("Remaining entries: {:?}", n); | ||
return Err("Sudo not removed") | ||
}, | ||
}; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.