Skip to content

Commit b064f1a

Browse files
authored
remove localAssets lazy migration (#2797)
* remove localAssets lazy migration * remove unused type
1 parent 4f9193a commit b064f1a

File tree

8 files changed

+3
-330
lines changed

8 files changed

+3
-330
lines changed

pallets/moonbeam-lazy-migrations/src/lib.rs

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,16 @@ pub use pallet::*;
3737
pub mod pallet {
3838
use super::*;
3939
use frame_support::pallet_prelude::*;
40-
use frame_support::traits::ReservableCurrency;
4140
use frame_system::pallet_prelude::*;
4241
use sp_core::H160;
4342

4443
pub const ARRAY_LIMIT: u32 = 1000;
4544
pub type GetArrayLimit = ConstU32<ARRAY_LIMIT>;
4645

47-
const INTERMEDIATES_NODES_SIZE: u64 = 4096;
48-
const MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE: u64 =
49-
(/* biggest key on moonbeam */136) + (/* biggest value on moonbeam */142);
50-
5146
/// Pallet for multi block migrations
5247
#[pallet::pallet]
5348
pub struct Pallet<T>(PhantomData<T>);
5449

55-
#[pallet::storage]
56-
/// If true, it means that LocalAssets storage has been removed.
57-
pub(crate) type LocalAssetsMigrationCompleted<T: Config> = StorageValue<_, bool, ValueQuery>;
58-
5950
#[pallet::storage]
6051
/// The total number of suicided contracts that were removed
6152
pub(crate) type SuicidedContractsRemoved<T: Config> = StorageValue<_, u32, ValueQuery>;
@@ -68,16 +59,8 @@ pub mod pallet {
6859

6960
#[pallet::error]
7061
pub enum Error<T> {
71-
/// There are no more storage entries to be removed
72-
AllStorageEntriesHaveBeenRemoved,
7362
/// The limit cannot be zero
7463
LimitCannotBeZero,
75-
/// The maximum number of assets cannot be zero
76-
MaxAssetsCannotBeZero,
77-
/// The limit for unlocking funds is too high
78-
UnlockLimitTooHigh,
79-
/// There are no more VotingOf entries to be removed and democracy funds to be unlocked
80-
AllDemocracyFundsUnlocked,
8164
/// There must be at least one address
8265
AddressesLengthCannotBeZero,
8366
/// The contract is not corrupted (Still exist or properly suicided)
@@ -86,126 +69,6 @@ pub mod pallet {
8669

8770
#[pallet::call]
8871
impl<T: Config> Pallet<T> {
89-
// TODO(rodrigo): This extrinsic should be removed once LocalAssets pallet storage is removed
90-
#[pallet::call_index(0)]
91-
#[pallet::weight({
92-
// "*limit" is used twice to account to the possibility that we may need to unreserve
93-
// deposits for every approval
94-
let possible_iterations = max_assets.saturating_add(*limit).saturating_add(*limit);
95-
let proof_size = INTERMEDIATES_NODES_SIZE + (MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE
96-
.saturating_mul(<u64>::from(possible_iterations)));
97-
98-
Weight::from_parts(0, proof_size)
99-
.saturating_add(<T as frame_system::Config>::DbWeight::get()
100-
.reads_writes((*max_assets + *limit + 1).into(), (*limit + 1).into()))
101-
})]
102-
pub fn clear_local_assets_storage(
103-
origin: OriginFor<T>,
104-
max_assets: u32,
105-
limit: u32,
106-
) -> DispatchResultWithPostInfo {
107-
ensure_signed(origin)?;
108-
ensure!(limit != 0, Error::<T>::LimitCannotBeZero);
109-
ensure!(max_assets != 0, Error::<T>::MaxAssetsCannotBeZero);
110-
111-
ensure!(
112-
!LocalAssetsMigrationCompleted::<T>::get(),
113-
Error::<T>::AllStorageEntriesHaveBeenRemoved
114-
);
115-
116-
let mut allowed_removals = limit;
117-
118-
const PALLET_PREFIX: &'static str = "LocalAssets";
119-
120-
struct LocalAssetsStorageAsset;
121-
impl frame_support::traits::StorageInstance for LocalAssetsStorageAsset {
122-
const STORAGE_PREFIX: &'static str = "Asset";
123-
fn pallet_prefix() -> &'static str {
124-
PALLET_PREFIX
125-
}
126-
}
127-
struct LocalAssetsStorageApprovals;
128-
impl frame_support::traits::StorageInstance for LocalAssetsStorageApprovals {
129-
const STORAGE_PREFIX: &'static str = "Approvals";
130-
fn pallet_prefix() -> &'static str {
131-
PALLET_PREFIX
132-
}
133-
}
134-
135-
/// Data concerning an approval.
136-
/// Duplicated the type from pallet_assets (The original type is private)
137-
#[derive(
138-
Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, MaxEncodedLen, TypeInfo,
139-
)]
140-
pub struct Approval<Balance, DepositBalance> {
141-
/// The amount of funds approved for the balance transfer from the owner to some delegated
142-
/// target.
143-
pub(super) amount: Balance,
144-
/// The amount reserved on the owner's account to hold this item in storage.
145-
pub(super) deposit: DepositBalance,
146-
}
147-
148-
type AssetMap = frame_support::storage::types::StorageMap<
149-
LocalAssetsStorageAsset,
150-
Blake2_128Concat,
151-
u128,
152-
// It is fine to add a dummy `Value` type
153-
// The value is not going to be decoded, since we only care about the keys)
154-
(),
155-
>;
156-
157-
for asset_id in AssetMap::iter_keys().take(max_assets as usize) {
158-
let approvals_iter = frame_support::storage::types::StorageNMap::<
159-
LocalAssetsStorageApprovals,
160-
(
161-
NMapKey<Blake2_128Concat, u128>, // asset id
162-
NMapKey<Blake2_128Concat, T::AccountId>, // owner
163-
NMapKey<Blake2_128Concat, T::AccountId>, // delegate
164-
),
165-
Approval<T::Balance, T::Balance>,
166-
>::drain_prefix((asset_id,));
167-
for ((owner, _), approval) in approvals_iter {
168-
allowed_removals = allowed_removals.saturating_sub(1);
169-
// Unreserve deposit (most likely will be zero)
170-
pallet_balances::Pallet::<T>::unreserve(&owner, approval.deposit);
171-
// Check if the removal limit was reached
172-
if allowed_removals < 1 {
173-
break;
174-
}
175-
}
176-
// Remove asset, since it does not contain more approvals
177-
AssetMap::remove(asset_id);
178-
allowed_removals = allowed_removals.saturating_sub(1);
179-
// Check if the removal limit was reached
180-
if allowed_removals < 1 {
181-
break;
182-
}
183-
}
184-
185-
// Remove remaining storage
186-
if allowed_removals > 0 {
187-
let hashed_prefix = sp_io::hashing::twox_128(PALLET_PREFIX.as_bytes());
188-
189-
let keys_removed =
190-
match sp_io::storage::clear_prefix(&hashed_prefix, Some(allowed_removals)) {
191-
sp_io::KillStorageResult::AllRemoved(value) => {
192-
LocalAssetsMigrationCompleted::<T>::set(true);
193-
value
194-
}
195-
sp_io::KillStorageResult::SomeRemaining(value) => value,
196-
};
197-
198-
allowed_removals = allowed_removals.saturating_sub(keys_removed);
199-
}
200-
201-
log::info!(
202-
"Removed {} storge keys 🧹",
203-
limit.saturating_sub(allowed_removals)
204-
);
205-
206-
Ok(Pays::No.into())
207-
}
208-
20972
// TODO(rodrigo): This extrinsic should be removed once the storage of destroyed contracts
21073
// has been removed
21174
#[pallet::call_index(1)]

pallets/moonbeam-lazy-migrations/src/tests.rs

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use {
2020
mock::{ExtBuilder, LazyMigrations, RuntimeOrigin, Test},
2121
Error,
2222
},
23-
frame_support::{assert_noop, assert_ok},
23+
frame_support::assert_noop,
2424
rlp::RlpStream,
2525
sp_core::{H160, H256},
2626
sp_io::hashing::keccak_256,
@@ -263,64 +263,3 @@ fn test_clear_suicided_mixed_suicided_and_non_suicided() {
263263
);
264264
})
265265
}
266-
267-
/// TODO(rodrigo): This test should be removed once LocalAssets pallet storage is removed
268-
#[test]
269-
fn test_call_clear_local_assets_storage() {
270-
let mut context = ExtBuilder::default().build();
271-
272-
let pallet_prefix = sp_io::hashing::twox_128("LocalAssets".as_bytes());
273-
let total_storage_entries: u8 = 5;
274-
275-
let gen_dummy_entry = |dummy: u8| -> [u8; 32] {
276-
[pallet_prefix, sp_io::hashing::twox_128(&[dummy])]
277-
.concat()
278-
.try_into()
279-
.unwrap()
280-
};
281-
282-
context.execute_with(|| {
283-
for i in 0u8..total_storage_entries {
284-
let dummy_data = gen_dummy_entry(i);
285-
sp_io::storage::set(&dummy_data, &dummy_data);
286-
dbg!(sp_io::storage::exists(&dummy_data));
287-
}
288-
});
289-
290-
// Commit changes
291-
let _ = context.commit_all();
292-
293-
// Next block
294-
context.execute_with(|| {
295-
// Check that the storage entries exist before attempting to remove it
296-
for i in 0u8..total_storage_entries {
297-
let dummy_data = gen_dummy_entry(i);
298-
assert!(sp_io::storage::exists(&dummy_data));
299-
}
300-
// Clear all storage entries
301-
assert_ok!(LazyMigrations::clear_local_assets_storage(
302-
RuntimeOrigin::signed(AccountId32::from([0; 32])),
303-
1,
304-
total_storage_entries.into()
305-
));
306-
// Check that all storage entries got deleted
307-
for i in 0u8..total_storage_entries {
308-
let dummy_data = gen_dummy_entry(i);
309-
assert!(!sp_io::storage::exists(&dummy_data));
310-
}
311-
});
312-
313-
// Commit changes
314-
let _ = context.commit_all();
315-
316-
// Next block
317-
context.execute_with(|| {
318-
// No more storage entries to be removed (expect failure)
319-
assert!(LazyMigrations::clear_local_assets_storage(
320-
RuntimeOrigin::signed(AccountId32::from([0; 32])),
321-
1,
322-
1
323-
)
324-
.is_err())
325-
});
326-
}

runtime/moonbase/src/asset_config.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ pub type ForeignAssetModifierOrigin = EitherOfDiverse<
179179
>,
180180
>;
181181

182-
pub type LocalAssetModifierOrigin =
183-
EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
184-
185182
impl pallet_asset_manager::Config for Runtime {
186183
type RuntimeEvent = RuntimeEvent;
187184
type Balance = Balance;

runtime/moonbase/tests/xcm_mock/parachain.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ impl pallet_balances::Config for Runtime {
126126
}
127127

128128
pub type ForeignAssetInstance = ();
129-
pub type LocalAssetInstance = pallet_assets::Instance1;
130129

131130
// Required for runtime benchmarks
132131
pallet_assets::runtime_benchmarks_enabled! {
@@ -174,30 +173,6 @@ impl pallet_assets::Config<ForeignAssetInstance> for Runtime {
174173
}
175174
}
176175

177-
impl pallet_assets::Config<LocalAssetInstance> for Runtime {
178-
type RuntimeEvent = RuntimeEvent;
179-
type Balance = Balance;
180-
type AssetId = AssetId;
181-
type Currency = Balances;
182-
type ForceOrigin = EnsureRoot<AccountId>;
183-
type AssetDeposit = AssetDeposit;
184-
type MetadataDepositBase = MetadataDepositBase;
185-
type MetadataDepositPerByte = MetadataDepositPerByte;
186-
type ApprovalDeposit = ApprovalDeposit;
187-
type StringLimit = AssetsStringLimit;
188-
type Freezer = ();
189-
type Extra = ();
190-
type AssetAccountDeposit = AssetAccountDeposit;
191-
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
192-
type RemoveItemsLimit = ConstU32<656>;
193-
type AssetIdParameter = AssetId;
194-
type CreateOrigin = AsEnsureOriginWithArg<EnsureNever<AccountId>>;
195-
type CallbackHandle = ();
196-
pallet_assets::runtime_benchmarks_enabled! {
197-
type BenchmarkHelper = BenchmarkHelper;
198-
}
199-
}
200-
201176
/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
202177
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
203178
/// `Transact` in order to determine the dispatch Origin.
@@ -1092,7 +1067,6 @@ construct_runtime!(
10921067
AssetManager: pallet_asset_manager,
10931068
XcmTransactor: pallet_xcm_transactor,
10941069
Treasury: pallet_treasury,
1095-
LocalAssets: pallet_assets::<Instance1>,
10961070
Proxy: pallet_proxy,
10971071

10981072
Timestamp: pallet_timestamp,

runtime/moonbeam/src/asset_config.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ pub type ForeignAssetModifierOrigin = EitherOfDiverse<
177177
>,
178178
>;
179179

180-
pub type LocalAssetModifierOrigin =
181-
EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
182-
183180
impl pallet_asset_manager::Config for Runtime {
184181
type RuntimeEvent = RuntimeEvent;
185182
type Balance = Balance;

runtime/moonriver/src/asset_config.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ pub type ForeignAssetModifierOrigin = EitherOfDiverse<
177177
governance::custom_origins::GeneralAdmin,
178178
>,
179179
>;
180-
pub type LocalAssetModifierOrigin =
181-
EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
182180

183181
impl pallet_asset_manager::Config for Runtime {
184182
type RuntimeEvent = RuntimeEvent;

0 commit comments

Comments
 (0)