Skip to content

Commit

Permalink
Remove suicided contracts lazy migration (#3039)
Browse files Browse the repository at this point in the history
* remove suicided contracts lazy migration

* remove benchmarks from pallet-moonbeam-lazy-migrations

* removed unused imports

* removed suicided contracts lazy migration test
  • Loading branch information
RomarQ authored Nov 18, 2024
1 parent 8455090 commit c26c7db
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 528 deletions.
77 changes: 0 additions & 77 deletions pallets/moonbeam-lazy-migrations/src/benchmarks.rs

This file was deleted.

67 changes: 0 additions & 67 deletions pallets/moonbeam-lazy-migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#![allow(non_camel_case_types)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(any(test, feature = "runtime-benchmarks"))]
mod benchmarks;
#[cfg(test)]
mod mock;
#[cfg(test)]
Expand Down Expand Up @@ -50,10 +48,6 @@ pub mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::storage]
/// The total number of suicided contracts that were removed
pub(crate) type SuicidedContractsRemoved<T: Config> = StorageValue<_, u32, ValueQuery>;

#[pallet::storage]
pub(crate) type StateMigrationStatusValue<T: Config> =
StorageValue<_, (StateMigrationStatus, u64), ValueQuery>;
Expand Down Expand Up @@ -82,12 +76,6 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
/// The limit cannot be zero
LimitCannotBeZero,
/// There must be at least one address
AddressesLengthCannotBeZero,
/// The contract is not corrupted (Still exist or properly suicided)
ContractNotCorrupted,
/// The contract already have metadata
ContractMetadataAlreadySet,
/// Contract not exist
Expand Down Expand Up @@ -323,61 +311,6 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
// TODO(rodrigo): This extrinsic should be removed once the storage of destroyed contracts
// has been removed
#[pallet::call_index(1)]
#[pallet::weight({
let addresses_len = addresses.len() as u32;
<T as crate::Config>::WeightInfo::clear_suicided_storage(addresses_len, *limit)
})]
pub fn clear_suicided_storage(
origin: OriginFor<T>,
addresses: BoundedVec<H160, GetArrayLimit>,
limit: u32,
) -> DispatchResultWithPostInfo {
ensure_signed(origin)?;

ensure!(limit != 0, Error::<T>::LimitCannotBeZero);
ensure!(
addresses.len() != 0,
Error::<T>::AddressesLengthCannotBeZero
);

let mut limit = limit as usize;

for address in &addresses {
// Ensure that the contract is corrupted by checking
// that it has no code and at least one storage entry.
let suicided = pallet_evm::Suicided::<T>::contains_key(&address);
let has_code = pallet_evm::AccountCodes::<T>::contains_key(&address);
ensure!(
!suicided
&& !has_code && pallet_evm::AccountStorages::<T>::iter_key_prefix(&address)
.next()
.is_some(),
Error::<T>::ContractNotCorrupted
);

let deleted = pallet_evm::AccountStorages::<T>::drain_prefix(*address)
.take(limit)
.count();

// Check if the storage of this contract has been completly removed
if pallet_evm::AccountStorages::<T>::iter_key_prefix(&address)
.next()
.is_none()
{
// All entries got removed, lets count this address as migrated
SuicidedContractsRemoved::<T>::mutate(|x| *x = x.saturating_add(1));
}

limit = limit.saturating_sub(deleted);
if limit == 0 {
return Ok(Pays::No.into());
}
}
Ok(Pays::No.into())
}
#[pallet::call_index(2)]
#[pallet::weight(Pallet::<T>::create_contract_metadata_weight(MAX_CONTRACT_CODE_SIZE))]
pub fn create_contract_metadata(
Expand Down
38 changes: 3 additions & 35 deletions pallets/moonbeam-lazy-migrations/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
use super::*;
use crate as pallet_moonbeam_lazy_migrations;
use frame_support::{
construct_runtime, ord_parameter_types, parameter_types,
traits::{EqualPrivilegeOnly, Everything, SortedMembers},
construct_runtime, parameter_types,
traits::Everything,
weights::{RuntimeDbWeight, Weight},
};
use frame_system::EnsureRoot;
use pallet_evm::{AddressMapping, EnsureAddressTruncated};
use sp_core::{ConstU32, H160, H256, U256};
use sp_core::{H160, H256, U256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
AccountId32, BuildStorage, Perbill,
Expand All @@ -43,7 +42,6 @@ construct_runtime!(
Timestamp: pallet_timestamp,
EVM: pallet_evm,
LazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call},
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -113,36 +111,6 @@ impl pallet_balances::Config for Test {
type RuntimeFreezeReason = ();
}

impl pallet_scheduler::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = ();
type ScheduleOrigin = EnsureRoot<Self::AccountId>;
type MaxScheduledPerBlock = ConstU32<100>;
type WeightInfo = ();
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type Preimages = ();
}

ord_parameter_types! {
pub const One: u64 = 1;
pub const Two: u64 = 2;
pub const Three: u64 = 3;
pub const Four: u64 = 4;
pub const Five: u64 = 5;
pub const Six: u64 = 6;
}
pub struct OneToFive;
impl SortedMembers<u64> for OneToFive {
fn sorted_members() -> Vec<u64> {
vec![1, 2, 3, 4, 5]
}
#[cfg(feature = "runtime-benchmarks")]
fn add(_m: &u64) {}
}

parameter_types! {
pub const MinimumPeriod: u64 = 6000 / 2;
}
Expand Down
Loading

0 comments on commit c26c7db

Please sign in to comment.