Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the LocalAssets pallet-asset instance #2634

Merged
merged 45 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
476e19e
feat(Deprecate Mintables XC-20s): remove LocalAssets pallet instance …
RomarQ Jan 31, 2024
dc1a951
feat(Remove LocalAssets): remove todo!()
RomarQ Jan 31, 2024
8f8be58
Update tests
RomarQ Jan 31, 2024
e19b2a9
feat(Remove LocalAssets): Remove storage from LocalAssets pallet_asse…
RomarQ Feb 1, 2024
2656848
feat(Remove LocalAssets): Blacklist all local xc-20s created on moonbase
RomarQ Feb 2, 2024
f021f3d
feat(Remove LocalAssets): test revert on all local xc-20 addresses
RomarQ Feb 3, 2024
ee00131
fix lint issues
RomarQ Feb 4, 2024
3b1d1a8
feat(Remove LocalAssets): update migration to remove account codes of…
RomarQ Feb 5, 2024
04e81d2
feat(Remove LocalAssets): only run LocalAssets storage migration when…
RomarQ Feb 5, 2024
6386160
feat(Remove LocalAssets): remove LocalAssets from moonriver runtime
RomarQ Feb 5, 2024
051e728
feat(Remove LocalAssets): remove LocalAssets from moonbeam\ runtime
RomarQ Feb 5, 2024
468211e
feat(Remove LocalAssets): refactor revert logic for local asset preco…
RomarQ Feb 5, 2024
974a7e8
test(Remove LocalAssets): Local assets must be inactive in the precom…
RomarQ Feb 5, 2024
445d69d
test(Remove LocalAssets): Remove local asset logic from assets-erc20 …
RomarQ Feb 5, 2024
b13c70a
fix from review
RomarQ Feb 6, 2024
f703506
deprecate LocalAssetReserve variant in CurrencyId enum
RomarQ Feb 6, 2024
bc99c30
move storage migration to a different PR
RomarQ Feb 6, 2024
b975a0a
fix: do not remove AccountCodes when destroying foreign assets
RomarQ Feb 6, 2024
2f86ff9
use explicit type in test
RomarQ Feb 7, 2024
1c4adfb
Adds a new pallet for removing the LocalAssets pallet
RomarQ Feb 8, 2024
8086e28
fix pallet-manual-migrations tests
RomarQ Feb 8, 2024
790d02a
fix linting
RomarQ Feb 8, 2024
6d8770c
Update pallets/manual-migrations/src/lib.rs
RomarQ Feb 12, 2024
27ddf63
Merge branch 'master' into rq/deprecate-mintable-xc20s
RomarQ Feb 12, 2024
4c02182
Merge branch 'master' into rq/deprecate-mintable-xc20s
RomarQ Feb 12, 2024
fc79439
rename pallet
RomarQ Feb 13, 2024
367fc73
raname pallet in the runtime
RomarQ Feb 13, 2024
26125f1
Support moonbeam dev tests (#2636)
RomarQ Feb 13, 2024
97f711c
improve weight calculation for removing LocalAssets storage
RomarQ Feb 13, 2024
13c5ea3
add PoV size test for LocalAssets storage removal
RomarQ Feb 13, 2024
63da3c1
remove unused imports
RomarQ Feb 13, 2024
0173c6d
fix lint issues in test
RomarQ Feb 13, 2024
aa96bd8
improve lazy migration pallet
RomarQ Feb 13, 2024
085a591
fix format
RomarQ Feb 13, 2024
5beb714
Update pallets/moonbeam-lazy-migrations/src/lib.rs
RomarQ Feb 14, 2024
d05ad3f
Update pallets/moonbeam-lazy-migrations/src/lib.rs
RomarQ Feb 14, 2024
550e929
Merge branch 'master' into rq/deprecate-mintable-xc20s
RomarQ Feb 14, 2024
fc35aad
fix format
RomarQ Feb 14, 2024
b9ea462
fix rustfmt
RomarQ Feb 14, 2024
55cda4d
fix editorconfig errors
RomarQ Feb 14, 2024
cb94d7d
chore(ci): revert changes to build-and-coverage step
RomarQ Feb 14, 2024
e6ea552
Merge branch 'master' into rq/deprecate-mintable-xc20s
RomarQ Feb 14, 2024
c1511f8
fix pipeline
RomarQ Feb 14, 2024
54b7949
remove unused import
RomarQ Feb 14, 2024
143d41b
improvements from review
RomarQ Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ jobs:
needs: ["set-tags", "build"]
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
chain: ["moonbase"]
chain: ["moonbase", "moonbeam"]
env:
GH_WORKFLOW_MATRIX_CHAIN: ${{ matrix.chain }}
DEBUG_COLORS: 1
Expand Down
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pallet-moonbeam-orbiters = { path = "pallets/moonbeam-orbiters", default-feature
pallet-parachain-staking = { path = "pallets/parachain-staking", default-features = false }
pallet-proxy-genesis-companion = { path = "pallets/proxy-genesis-companion", default-features = false }
pallet-xcm-transactor = { path = "pallets/xcm-transactor", default-features = false }
pallet-moonbeam-lazy-migrations = { path = "pallets/moonbeam-lazy-migrations", default-features = false }
precompile-utils = { path = "precompiles/utils", default-features = false }
xcm-primitives = { path = "primitives/xcm", default-features = false }

Expand Down
40 changes: 40 additions & 0 deletions pallets/moonbeam-lazy-migrations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "pallet-moonbeam-lazy-migrations"
authors = { workspace = true }
description = "A pallet for performing migrations from extrinsics"
edition = "2021"
version = "0.1.0"

[dependencies]
log = { workspace = true }

# Substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true, features = ["derive"] }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

# Benchmarks
frame-benchmarking = { workspace = true, optional = true }

[dev-dependencies]
pallet-balances = { workspace = true }
frame-benchmarking = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }

[features]
default = ["std"]
std = [
"pallet-balances/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
110 changes: 110 additions & 0 deletions pallets/moonbeam-lazy-migrations/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2024 Moonbeam foundation
// This file is part of Moonbeam.

// Moonbeam 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.

// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! # Lazy Migration Pallet

#![allow(non_camel_case_types)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

use frame_support::pallet;

pub use pallet::*;

#[pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

const INTERMEDIATES_NODES_SIZE: u64 = 4096;
const MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE: u64 =
(/* biggest key on moonbeam */136) + (/* biggest value on moonbeam */142);

/// Pallet for multi block migrations
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::storage]
/// If true, it means that LocalAssets storage has been removed.
pub(crate) type LocalAssetsMigrationCompleted<T: Config> = StorageValue<_, bool, ValueQuery>;

/// Configuration trait of this pallet.
#[pallet::config]
pub trait Config: frame_system::Config {}

#[pallet::error]
pub enum Error<T> {
/// There are no more storage entries to be removed
AllStorageEntriesHaveBeenRemoved,
}

#[pallet::call]
impl<T: Config> Pallet<T> {
// TODO(rodrigo): This extrinsic should be removed once LocalAssets pallet storage is removed
#[pallet::call_index(0)]
#[pallet::weight(Weight::from_parts(0,
INTERMEDIATES_NODES_SIZE + (MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE * <u64>::from(*limit)))
.saturating_add(<T as frame_system::Config>::DbWeight::get()
.reads_writes((*limit + 1).into(), (*limit + 1).into()))
)]
pub fn clear_local_assets_storage(
origin: OriginFor<T>,
limit: u32,
) -> DispatchResultWithPostInfo {
ensure_signed(origin)?;
ensure!(limit != 0, "Limit cannot be zero!");

let mut weight = <T as frame_system::Config>::DbWeight::get().reads(1);
ensure!(
!LocalAssetsMigrationCompleted::<T>::get(),
Error::<T>::AllStorageEntriesHaveBeenRemoved
);
RomarQ marked this conversation as resolved.
Show resolved Hide resolved

let hashed_prefix = sp_io::hashing::twox_128("LocalAssets".as_bytes());

let keys_removed = match sp_io::storage::clear_prefix(&hashed_prefix, Some(limit)) {
sp_io::KillStorageResult::AllRemoved(value) => {
LocalAssetsMigrationCompleted::<T>::set(true);
weight
.saturating_accrue(<T as frame_system::Config>::DbWeight::get().writes(1));
value
}
sp_io::KillStorageResult::SomeRemaining(value) => value,
} as u64;

log::info!("Removed {} keys 🧹", keys_removed);

Ok(Some(
weight
.saturating_add(Weight::from_parts(
0,
INTERMEDIATES_NODES_SIZE
+ MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE * keys_removed,
))
.saturating_add(
<T as frame_system::Config>::DbWeight::get()
.reads_writes(keys_removed, keys_removed),
),
)
.into())
}
}
}
120 changes: 120 additions & 0 deletions pallets/moonbeam-lazy-migrations/src/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright 2024 Moonbeam foundation
// This file is part of Moonbeam.

// Moonbeam 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.

// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! A minimal runtime including the multi block migrations pallet

use super::*;
use crate as pallet_moonbeam_lazy_migrations;
use frame_support::{
construct_runtime, parameter_types,
traits::Everything,
weights::{constants::RocksDbWeight, Weight},
};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage, Perbill,
};

pub type AccountId = u64;
pub type Balance = u128;
type Block = frame_system::mocking::MockBlock<Runtime>;

// Configure a mock runtime to test the pallet.
construct_runtime!(
pub enum Runtime
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
LazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call},
}
);

parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: Weight = Weight::from_parts(1024, 1);
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const SS58Prefix: u8 = 42;
}
impl frame_system::Config for Runtime {
type BaseCallFilter = Everything;
type DbWeight = RocksDbWeight;
type RuntimeOrigin = RuntimeOrigin;
type Nonce = u64;
type Block = Block;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type BlockWeights = ();
type BlockLength = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

parameter_types! {
pub const ExistentialDeposit: u128 = 0;
}
impl pallet_balances::Config for Runtime {
type MaxReserves = ();
type ReserveIdentifier = ();
type MaxLocks = ();
type Balance = Balance;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
type RuntimeFreezeReason = ();
}

impl Config for Runtime {}

/// Externality builder for pallet migration's mock runtime
pub(crate) struct ExtBuilder;

impl Default for ExtBuilder {
fn default() -> ExtBuilder {
Self
}
}

impl ExtBuilder {
pub(crate) fn build(self) -> sp_io::TestExternalities {
let storage = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.expect("Frame system builds valid default genesis config");

let mut ext = sp_io::TestExternalities::new(storage);
ext.execute_with(|| System::set_block_number(1));
ext
}
}
Loading
Loading