difftreelog
feat evm migration pallet
in: master
5 files changed
pallets/evm-migration/Cargo.tomldiffbeforeafterbothno changes
pallets/evm-migration/src/benchmarking.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/evm-migration/src/benchmarking.rs
@@ -0,0 +1,30 @@
+use super::{Call, Config, Pallet};
+use frame_benchmarking::benchmarks;
+use frame_system::RawOrigin;
+use sp_core::{H160, H256};
+use sp_std::vec::Vec;
+
+benchmarks! {
+ begin {
+ }: _(RawOrigin::Root, H160::default())
+
+ set_data {
+ let b in 0..80;
+ let address = H160::from_low_u64_be(b as u64);
+ let mut data = Vec::new();
+ for i in 0..b {
+ data.push((
+ H256::from_low_u64_be(i as u64),
+ H256::from_low_u64_be(i as u64),
+ ));
+ }
+ <Pallet<T>>::begin(RawOrigin::Root.into(), address)?;
+ }: _(RawOrigin::Root, address, data)
+
+ finish {
+ let b in 0..80;
+ let address = H160::from_low_u64_be(b as u64);
+ let data: Vec<u8> = (0..b as u8).collect();
+ <Pallet<T>>::begin(RawOrigin::Root.into(), address)?;
+ }: _(RawOrigin::Root, address, data)
+}
pallets/evm-migration/src/lib.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/evm-migration/src/lib.rs
@@ -0,0 +1,111 @@
+#![cfg_attr(not(feature = "std"), no_std)]
+
+pub use pallet::*;
+#[cfg(feature = "runtime-benchmarks")]
+pub mod benchmarking;
+pub mod weights;
+
+#[frame_support::pallet]
+pub mod pallet {
+ use frame_support::{pallet_prelude::*, transactional};
+ use frame_system::pallet_prelude::*;
+ use sp_core::{H160, H256};
+ use sp_std::vec::Vec;
+ use super::weights::WeightInfo;
+
+ #[pallet::config]
+ pub trait Config: frame_system::Config + pallet_evm::Config {
+ type WeightInfo: WeightInfo;
+ }
+
+ type SelfWeightOf<T> = <T as Config>::WeightInfo;
+
+ #[pallet::pallet]
+ #[pallet::generate_store(pub(super) trait Store)]
+ pub struct Pallet<T>(_);
+
+ #[pallet::error]
+ pub enum Error<T> {
+ AccountNotEmpty,
+ AccountIsNotMigrating,
+ }
+
+ #[pallet::storage]
+ pub(super) type MigrationPending<T: Config> =
+ StorageMap<Hasher = Twox64Concat, Key = H160, Value = bool, QueryKind = ValueQuery>;
+
+ #[pallet::call]
+ impl<T: Config> Pallet<T> {
+ #[pallet::weight(<SelfWeightOf<T>>::begin())]
+ pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {
+ ensure_root(origin)?;
+ ensure!(
+ <pallet_evm::Pallet<T>>::is_account_empty(&address)
+ && !<MigrationPending<T>>::get(&address),
+ <Error<T>>::AccountNotEmpty,
+ );
+
+ <MigrationPending<T>>::insert(address, true);
+ Ok(())
+ }
+
+ #[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]
+ pub fn set_data(
+ origin: OriginFor<T>,
+ address: H160,
+ data: Vec<(H256, H256)>,
+ ) -> DispatchResult {
+ use frame_support::StorageDoubleMap;
+ ensure_root(origin)?;
+ ensure!(
+ <MigrationPending<T>>::get(&address),
+ <Error<T>>::AccountIsNotMigrating,
+ );
+
+ for (k, v) in data {
+ pallet_evm::AccountStorages::insert(&address, k, v);
+ }
+ Ok(())
+ }
+
+ #[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]
+ #[transactional]
+ pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {
+ use frame_support::StorageMap;
+ ensure_root(origin)?;
+ ensure!(
+ <MigrationPending<T>>::get(&address),
+ <Error<T>>::AccountIsNotMigrating,
+ );
+
+ pallet_evm::AccountCodes::insert(&address, code);
+ <MigrationPending<T>>::remove(address);
+ Ok(())
+ }
+ }
+
+ pub struct OnMethodCall<T>(PhantomData<T>);
+ impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {
+ fn is_reserved(contract: &H160) -> bool {
+ <MigrationPending<T>>::get(&contract)
+ }
+
+ fn is_used(_contract: &H160) -> bool {
+ false
+ }
+
+ fn call(
+ _source: &H160,
+ _arget: &H160,
+ _gas_left: u64,
+ _input: &[u8],
+ _value: sp_core::U256,
+ ) -> Option<pallet_evm::PrecompileOutput> {
+ None
+ }
+
+ fn get_code(_contract: &H160) -> Option<Vec<u8>> {
+ None
+ }
+ }
+}
runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -23,6 +23,7 @@
'frame-support/runtime-benchmarks',
'frame-system-benchmarking',
'frame-system/runtime-benchmarks',
+ 'pallet-evm-migration/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-nft/runtime-benchmarks',
@@ -56,6 +57,7 @@
'pallet-treasury/std',
'pallet-vesting/std',
'pallet-evm/std',
+ 'pallet-evm-migration/std',
'pallet-evm-contract-helpers/std',
'pallet-evm-transaction-payment/std',
'pallet-evm-coder-substrate/std',
@@ -392,6 +394,7 @@
# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }
pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }
+pallet-evm-migration = { path = '../pallets/evm-migration', default-features = false }
pallet-evm-contract-helpers = { path = '../pallets/evm-contract-helpers', default-features = false }
pallet-evm-transaction-payment = { path = '../pallets/evm-transaction-payment', default-features = false }
pallet-evm-coder-substrate = { default-features = false, path = "../pallets/evm-coder-substrate" }
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -252,6 +252,7 @@
type Currency = Balances;
type Event = Event;
type OnMethodCall = (
+ pallet_evm_migration::OnMethodCall<Self>,
pallet_nft::NftErcSupport<Self>,
pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
);
@@ -263,6 +264,10 @@
type FindAuthor = EthereumFindAuthor<Aura>;
}
+impl pallet_evm_migration::Config for Runtime {
+ type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;
+}
+
pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
@@ -819,6 +824,7 @@
EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,
EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,
EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,
+ EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,
}
);
@@ -1180,6 +1186,7 @@
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
+ add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);
add_benchmark!(params, batches, pallet_nft, Nft);
add_benchmark!(params, batches, pallet_inflation, Inflation);