Skip to content

Commit 514579e

Browse files
committed
Remove legacy storage
Signed-off-by: Dengjianping <[email protected]>
1 parent 812db69 commit 514579e

File tree

3 files changed

+112
-1
lines changed

3 files changed

+112
-1
lines changed

runtime/manta/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, Si
10191019

10201020
/// Types for runtime upgrading.
10211021
/// Each type should implement trait `OnRuntimeUpgrade`.
1022-
pub type OnRuntimeUpgradeHooks = ();
1022+
pub type OnRuntimeUpgradeHooks = (migrations::manta_pay::RemoveMantaPay<Runtime>,);
10231023
/// Executive: handles dispatch to the various modules.
10241024
pub type Executive = frame_executive::Executive<
10251025
Runtime,
+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2020-2024 Manta Network.
2+
// This file is part of Manta.
3+
//
4+
// Manta is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Manta is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Manta. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#![allow(clippy::unnecessary_cast)]
18+
19+
use core::marker::PhantomData;
20+
use frame_support::migration::clear_storage_prefix;
21+
use frame_support::{
22+
migration::have_storage_value,
23+
pallet_prelude::Weight,
24+
traits::{Get, OnRuntimeUpgrade},
25+
};
26+
use sp_runtime::DispatchError;
27+
use sp_std::vec::Vec;
28+
29+
pub struct RemoveMantaPay<T>(PhantomData<T>);
30+
impl<T: frame_system::Config> OnRuntimeUpgrade for RemoveMantaPay<T> {
31+
fn on_runtime_upgrade() -> Weight {
32+
let mut reads = 0;
33+
let mut writes = 0;
34+
log::info!(target: "MantaPay", "✅ {:?} has been removed.", have_storage_value(b"MantaPay", b"", b""));
35+
// NullifierCommitmentSet
36+
if have_storage_value(b"MantaPay", b"NullifierCommitmentSet", b"") {
37+
clear_storage_prefix(b"MantaPay", b"Key", b"", None, None);
38+
clear_storage_prefix(b"MantaPay", b":__STORAGE_VERSION__:", b"", None, None);
39+
log::info!(target: "MantaPay", "✅ NullifierCommitmentSet has been removed.");
40+
log::info!(target: "MantaPay", "✅ The pallet version has been removed.");
41+
reads += 1;
42+
writes += 2;
43+
}
44+
// NullifierSetInsertionOrder
45+
if have_storage_value(b"MantaPay", b"NullifierSetInsertionOrder", b"") {
46+
clear_storage_prefix(b"MantaPay", b"NullifierSetInsertionOrder", b"", None, None);
47+
log::info!(target: "MantaPay", "✅ NullifierSetInsertionOrder has been removed.");
48+
reads += 1;
49+
writes += 1;
50+
}
51+
// NullifierSetSize
52+
if have_storage_value(b"MantaPay", b"NullifierSetSize", b"") {
53+
clear_storage_prefix(b"MantaPay", b"NullifierSetSize", b"", None, None);
54+
log::info!(target: "MantaPay", "✅ NullifierSetSize has been removed.");
55+
reads += 1;
56+
writes += 1;
57+
}
58+
// ShardTrees
59+
if have_storage_value(b"MantaPay", b"ShardTrees", b"") {
60+
clear_storage_prefix(b"MantaPay", b"ShardTrees", b"", None, None);
61+
log::info!(target: "MantaPay", "✅ ShardTrees has been removed.");
62+
reads += 1;
63+
writes += 1;
64+
}
65+
// Shards
66+
if have_storage_value(b"MantaPay", b"Shards", b"") {
67+
clear_storage_prefix(b"MantaPay", b"Shards", b"", None, None);
68+
log::info!(target: "MantaPay", "✅ Shards has been removed.");
69+
reads += 1;
70+
writes += 1;
71+
}
72+
// UtxoAccumulatorOutputs
73+
if have_storage_value(b"MantaPay", b"UtxoAccumulatorOutputs", b"") {
74+
clear_storage_prefix(b"MantaPay", b"UtxoAccumulatorOutputs", b"", None, None);
75+
log::info!(target: "MantaPay", "✅ UtxoAccumulatorOutputs has been removed.");
76+
reads += 1;
77+
writes += 1;
78+
}
79+
// UtxoSet
80+
if have_storage_value(b"MantaPay", b"UtxoSet", b"") {
81+
clear_storage_prefix(b"MantaPay", b"UtxoSet", b"", None, None);
82+
log::info!(target: "MantaPay", "✅ UtxoSet has been removed.");
83+
reads += 1;
84+
writes += 1;
85+
}
86+
log::info!(target: "MantaPay", "✅ {:?} has been removed.", have_storage_value(b"MantaPay", b"", b""));
87+
T::DbWeight::get()
88+
.reads(reads)
89+
.saturating_add(T::DbWeight::get().writes(writes))
90+
}
91+
92+
#[cfg(feature = "try-runtime")]
93+
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
94+
if have_storage_value(b"MantaPay", b"", b"") {
95+
log::info!(target: "MantaPay will be removed soon.");
96+
Ok(Vec::new())
97+
} else {
98+
Err(DispatchError::Other("Sudo doesn't exist."))
99+
}
100+
}
101+
102+
#[cfg(feature = "try-runtime")]
103+
fn post_upgrade(_state: Vec<u8>) -> Result<(), DispatchError> {
104+
if have_storage_value(b"MantaPay", b"", b"") {
105+
Err(DispatchError::Other("Failed to remove MantaPay module."))
106+
} else {
107+
Ok(())
108+
}
109+
}
110+
}

runtime/manta/src/migrations/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616

1717
pub mod asset_manager;
1818
pub mod assets_genesis;
19+
pub mod manta_pay;

0 commit comments

Comments
 (0)