Skip to content

Commit fe9f48e

Browse files
committed
clear corrupt unified mapping
1 parent f0b6f53 commit fe9f48e

File tree

3 files changed

+53
-40
lines changed

3 files changed

+53
-40
lines changed

pallets/unified-accounts/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use sp_std::marker::PhantomData;
8888

8989
pub use pallet::*;
9090

91+
pub mod migration;
9192
pub mod weights;
9293
pub use weights::WeightInfo;
9394

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use super::{Config, Pallet, Weight};
2+
use astar_primitives::evm::EvmAddress;
3+
use frame_support::{
4+
pallet_prelude::OptionQuery,
5+
storage_alias,
6+
traits::{Get, OnRuntimeUpgrade},
7+
Blake2_128Concat,
8+
};
9+
10+
#[storage_alias]
11+
type EvmToNative<T: Config> = StorageMap<
12+
Pallet<T>,
13+
Blake2_128Concat,
14+
<T as frame_system::Config>::AccountId,
15+
EvmAddress,
16+
OptionQuery,
17+
>;
18+
19+
#[storage_alias]
20+
type NativeToEvm<T: Config> = StorageMap<
21+
Pallet<T>,
22+
Blake2_128Concat,
23+
EvmAddress,
24+
<T as frame_system::Config>::AccountId,
25+
OptionQuery,
26+
>;
27+
28+
/// Remove all corrupted mappings.
29+
pub struct ClearCorruptedUnifiedMappings<T>(core::marker::PhantomData<T>);
30+
impl<T: Config> OnRuntimeUpgrade for ClearCorruptedUnifiedMappings<T> {
31+
fn on_runtime_upgrade() -> Weight {
32+
let healthy_count = crate::EvmToNative::<T>::iter().count() as u64 * 2;
33+
log::info!("Total healthy entries: {healthy_count}");
34+
35+
let mut count = 0;
36+
// translate will fail to decode valid entries and therefore will skip it,
37+
// so this will remove only corrupt entries
38+
EvmToNative::<T>::translate(|key, value: EvmAddress| {
39+
log::debug!("Remove corrupt key: {key:?} with value: {value:?}");
40+
count += 1;
41+
None
42+
});
43+
NativeToEvm::<T>::translate(|key, value: T::AccountId| {
44+
log::debug!("Remove corrupt key: {key:?} with value: {value:?}");
45+
count += 1;
46+
None
47+
});
48+
log::info!("Removed {count} corrupt entries");
49+
T::DbWeight::get().reads_writes(healthy_count + writes, count)
50+
}
51+
}

runtime/shibuya/src/lib.rs

+1-40
Original file line numberDiff line numberDiff line change
@@ -1625,53 +1625,14 @@ pub type Executive = frame_executive::Executive<
16251625
/// Once done, migrations should be removed from the tuple.
16261626
pub type Migrations = (
16271627
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
1628-
GovernancePalletsVersionSetting,
16291628
// permanent migration, do not remove
16301629
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
16311630
// XCM V3 -> V4
16321631
pallet_xc_asset_config::migrations::versioned::V2ToV3<Runtime>,
16331632
pallet_identity::migration::versioned::V0ToV1<Runtime, 250>,
1633+
pallet_unified_accounts::migration::ClearCorruptedUnifiedMappings<Runtime>,
16341634
);
16351635

1636-
use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade};
1637-
pub struct GovernancePalletsVersionSetting;
1638-
impl OnRuntimeUpgrade for GovernancePalletsVersionSetting {
1639-
fn on_runtime_upgrade() -> Weight {
1640-
// 1. Membership pallet instances
1641-
let membership_storage_version = pallet_membership::Pallet::<
1642-
Runtime,
1643-
MainCouncilMembershipInst,
1644-
>::in_code_storage_version();
1645-
1646-
membership_storage_version
1647-
.put::<pallet_membership::Pallet<Runtime, MainCouncilMembershipInst>>();
1648-
membership_storage_version
1649-
.put::<pallet_membership::Pallet<Runtime, TechnicalCommitteeCollectiveInst>>();
1650-
membership_storage_version
1651-
.put::<pallet_membership::Pallet<Runtime, CommunityCouncilMembershipInst>>();
1652-
1653-
// 2. Collective pallet instances
1654-
let collective_storage_version = pallet_collective::Pallet::<
1655-
Runtime,
1656-
MainCouncilCollectiveInst,
1657-
>::in_code_storage_version();
1658-
1659-
collective_storage_version
1660-
.put::<pallet_collective::Pallet<Runtime, MainCouncilCollectiveInst>>();
1661-
collective_storage_version
1662-
.put::<pallet_collective::Pallet<Runtime, TechnicalCommitteeCollectiveInst>>();
1663-
collective_storage_version
1664-
.put::<pallet_collective::Pallet<Runtime, CommunityCouncilCollectiveInst>>();
1665-
1666-
// 3. Democracy pallet
1667-
let democracy_storage_version =
1668-
pallet_democracy::Pallet::<Runtime>::in_code_storage_version();
1669-
democracy_storage_version.put::<pallet_democracy::Pallet<Runtime>>();
1670-
1671-
<Runtime as frame_system::Config>::DbWeight::get().writes(7)
1672-
}
1673-
}
1674-
16751636
type EventRecord = frame_system::EventRecord<
16761637
<Runtime as frame_system::Config>::RuntimeEvent,
16771638
<Runtime as frame_system::Config>::Hash,

0 commit comments

Comments
 (0)