git.delta.rocks / unique-network / refs/commits / 326c9b419cb9

difftreelog

feat evm migration pallet

Yaroslav Bolyukin2021-08-12parent: #b7be484.patch.diff
in: master

5 files changed

addedpallets/evm-migration/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/pallets/evm-migration/Cargo.toml
@@ -0,0 +1,36 @@
+[package]
+name = "pallet-evm-migration"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+frame-system = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+frame-benchmarking = { default-features = false, version = '3.0.0', optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+sp-runtime = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+sp-std = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+sp-io = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+sp-core = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+pallet-evm = { default-features = false, version = "5.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "injected-transactions-parachain" }
+fp-evm = { default-features = false, version = "2.0.0", git = "https://github.com/uniquenetwork/frontier.git", branch = "injected-transactions-parachain" }
+
+[dependencies.codec]
+default-features = false
+features = ['derive']
+package = 'parity-scale-codec'
+version = '2.0.0'
+
+[features]
+default = ["std", "runtime-benchmarks"]
+std = [
+    "frame-support/std",
+    "frame-system/std",
+    "frame-benchmarking/std",
+    "sp-runtime/std",
+    "sp-std/std",
+    "sp-io/std",
+    "sp-core/std",
+    "pallet-evm/std",
+    "fp-evm/std",
+]
+runtime-benchmarks = ["frame-benchmarking"]
addedpallets/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)
+}
addedpallets/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
+		}
+	}
+}
modifiedruntime/Cargo.tomldiffbeforeafterboth
before · runtime/Cargo.toml
1################################################################################2# Package 34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6build = 'build.rs'7description = 'Substrate node nft'8edition = '2018'9homepage = 'https://unique.network'10license = 'All Rights Reserved'11name = 'nft-runtime'12repository = 'https://github.com/usetech-llc/nft_private/'13version = '3.0.0'1415[package.metadata.docs.rs]16targets = ['x86_64-unknown-linux-gnu']1718[features]19default = ['std']20runtime-benchmarks = [21    'hex-literal',22    'frame-benchmarking',23    'frame-support/runtime-benchmarks',24    'frame-system-benchmarking',25    'frame-system/runtime-benchmarks',26    'pallet-balances/runtime-benchmarks',27    'pallet-timestamp/runtime-benchmarks',28    'pallet-nft/runtime-benchmarks',29    'pallet-inflation/runtime-benchmarks',30    'sp-runtime/runtime-benchmarks',31]32std = [33    'codec/std',34    'max-encoded-len/std',35    'cumulus-pallet-aura-ext/std',36    'cumulus-pallet-parachain-system/std',37    'cumulus-pallet-xcm/std',38    'cumulus-pallet-xcmp-queue/std',39    'cumulus-primitives-core/std',40    'cumulus-primitives-utility/std',41    'frame-executive/std',42    'frame-support/std',43    'frame-system/std',44    'frame-system-rpc-runtime-api/std',45    'pallet-aura/std',46    'pallet-balances/std',47    # 'pallet-contracts/std',48    # 'pallet-contracts-primitives/std',49    # 'pallet-contracts-rpc-runtime-api/std',50    # 'pallet-contract-helpers/std',51    'pallet-randomness-collective-flip/std',52    'pallet-sudo/std',53    'pallet-timestamp/std',54    'pallet-transaction-payment/std',55    'pallet-transaction-payment-rpc-runtime-api/std',56    'pallet-treasury/std',57    'pallet-vesting/std',58    'pallet-evm/std',59    'pallet-evm-contract-helpers/std',60    'pallet-evm-transaction-payment/std',61    'pallet-evm-coder-substrate/std',62    'pallet-ethereum/std',63    'fp-rpc/std',64    'parachain-info/std',65    'serde',66    'pallet-inflation/std',67    'pallet-nft/std',68    'pallet-scheduler/std',69    'pallet-nft-charge-transaction/std',70    'pallet-nft-transaction-payment/std',71    'nft-data-structs/std',72    'sp-api/std',73    'sp-block-builder/std',74    "sp-consensus-aura/std",75    'sp-core/std',76    'sp-inherents/std',77    'sp-io/std',78    'sp-offchain/std',79    'sp-runtime/std',80    'sp-session/std',81    'sp-std/std',82    'sp-transaction-pool/std',83    'sp-version/std',84    'xcm/std',85    'xcm-builder/std',86    'xcm-executor/std',87]88limit-testing = [89    'pallet-nft/limit-testing',90    'nft-data-structs/limit-testing',91]9293################################################################################94# Substrate Dependencies9596[dependencies.codec]97default-features = false98features = ['derive']99package = 'parity-scale-codec'100version = '2.0.0'101102[dependencies.frame-benchmarking]103default-features = false104git = 'https://github.com/paritytech/substrate.git'105optional = true106branch = 'polkadot-v0.9.8'107version = '3.0.0'108109[dependencies.frame-executive]110default-features = false111git = 'https://github.com/paritytech/substrate.git'112branch = 'polkadot-v0.9.8'113version = '3.0.0'114115[dependencies.frame-support]116default-features = false117git = 'https://github.com/paritytech/substrate.git'118branch = 'polkadot-v0.9.8'119version = '3.0.0'120121[dependencies.frame-system]122default-features = false123git = 'https://github.com/paritytech/substrate.git'124branch = 'polkadot-v0.9.8'125version = '3.0.0'126127[dependencies.frame-system-benchmarking]128default-features = false129git = 'https://github.com/paritytech/substrate.git'130optional = true131branch = 'polkadot-v0.9.8'132version = '3.0.0'133134[dependencies.frame-system-rpc-runtime-api]135default-features = false136git = 'https://github.com/paritytech/substrate.git'137branch = 'polkadot-v0.9.8'138version = '3.0.0'139140[dependencies.hex-literal]141optional = true142version = '0.3.1'143144[dependencies.serde]145default-features = false146features = ['derive']147optional = true148version = '1.0.119'149150[dependencies.pallet-aura]151default-features = false152git = 'https://github.com/paritytech/substrate.git'153branch = 'polkadot-v0.9.8'154version = '3.0.0'155156[dependencies.pallet-balances]157default-features = false158git = 'https://github.com/paritytech/substrate.git'159branch = 'polkadot-v0.9.8'160version = '3.0.0'161162# Contracts specific packages163# [dependencies.pallet-contracts]164# git = 'https://github.com/paritytech/substrate.git'165# default-features = false166# branch = 'polkadot-v0.9.8'167# version = '3.0.0'168169# [dependencies.pallet-contracts-primitives]170# git = 'https://github.com/paritytech/substrate.git'171# default-features = false172# branch = 'polkadot-v0.9.8'173# version = '3.0.0'174175# [dependencies.pallet-contracts-rpc-runtime-api]176# git = 'https://github.com/paritytech/substrate.git'177# default-features = false178# branch = 'polkadot-v0.9.8'179# version = '3.0.0'180181[dependencies.pallet-randomness-collective-flip]182default-features = false183git = 'https://github.com/paritytech/substrate.git'184branch = 'polkadot-v0.9.8'185version = '3.0.0'186187[dependencies.pallet-sudo]188default-features = false189git = 'https://github.com/paritytech/substrate.git'190branch = 'polkadot-v0.9.8'191version = '3.0.0'192193[dependencies.pallet-timestamp]194default-features = false195git = 'https://github.com/paritytech/substrate.git'196branch = 'polkadot-v0.9.8'197version = '3.0.0'198199[dependencies.pallet-transaction-payment]200default-features = false201git = 'https://github.com/paritytech/substrate.git'202branch = 'polkadot-v0.9.8'203version = '3.0.0'204205[dependencies.pallet-transaction-payment-rpc-runtime-api]206default-features = false207git = 'https://github.com/paritytech/substrate.git'208branch = 'polkadot-v0.9.8'209version = '3.0.0'210211[dependencies.pallet-treasury]212default-features = false213git = 'https://github.com/paritytech/substrate.git'214branch = 'polkadot-v0.9.8'215version = '3.0.0'216217[dependencies.pallet-vesting]218default-features = false219git = 'https://github.com/paritytech/substrate.git'220branch = 'polkadot-v0.9.8'221version = '3.0.0'222223[dependencies.sp-arithmetic]224default-features = false225git = 'https://github.com/paritytech/substrate.git'226branch = 'polkadot-v0.9.8'227version = '3.0.0'228229[dependencies.sp-api]230default-features = false231git = 'https://github.com/paritytech/substrate.git'232branch = 'polkadot-v0.9.8'233version = '3.0.0'234235[dependencies.sp-block-builder]236default-features = false237git = 'https://github.com/paritytech/substrate.git'238branch = 'polkadot-v0.9.8'239version = '3.0.0'240241[dependencies.sp-core]242default-features = false243git = 'https://github.com/paritytech/substrate.git'244branch = 'polkadot-v0.9.8'245version = '3.0.0'246247[dependencies.sp-consensus-aura]248default-features = false249git = 'https://github.com/paritytech/substrate.git'250branch = 'polkadot-v0.9.8'251version = '0.9.0'252253[dependencies.sp-inherents]254default-features = false255git = 'https://github.com/paritytech/substrate.git'256branch = 'polkadot-v0.9.8'257version = '3.0.0'258259[dependencies.sp-io]260default-features = false261git = 'https://github.com/paritytech/substrate.git'262branch = 'polkadot-v0.9.8'263version = '3.0.0'264265[dependencies.sp-offchain]266default-features = false267git = 'https://github.com/paritytech/substrate.git'268branch = 'polkadot-v0.9.8'269version = '3.0.0'270271[dependencies.sp-runtime]272default-features = false273git = 'https://github.com/paritytech/substrate.git'274branch = 'polkadot-v0.9.8'275version = '3.0.0'276277[dependencies.sp-session]278default-features = false279git = 'https://github.com/paritytech/substrate.git'280branch = 'polkadot-v0.9.8'281version = '3.0.0'282283[dependencies.sp-std]284default-features = false285git = 'https://github.com/paritytech/substrate.git'286branch = 'polkadot-v0.9.8'287version = '3.0.0'288289[dependencies.sp-transaction-pool]290default-features = false291git = 'https://github.com/paritytech/substrate.git'292branch = 'polkadot-v0.9.8'293version = '3.0.0'294295[dependencies.sp-version]296default-features = false297git = 'https://github.com/paritytech/substrate.git'298branch = 'polkadot-v0.9.8'299version = '3.0.0'300301[dependencies.smallvec]302version = '1.4.1'303304################################################################################305# Cumulus dependencies306307[dependencies.parachain-info]308default-features = false309git = 'https://github.com/paritytech/cumulus.git'310branch = 'polkadot-v0.9.8'311version = '0.1.0'312313[dependencies.cumulus-pallet-aura-ext]314git = 'https://github.com/paritytech/cumulus.git'315branch = 'polkadot-v0.9.8'316default-features = false317318[dependencies.cumulus-pallet-parachain-system]319git = 'https://github.com/paritytech/cumulus.git'320branch = 'polkadot-v0.9.8'321default-features = false322323[dependencies.cumulus-primitives-core]324git = 'https://github.com/paritytech/cumulus.git'325branch = 'polkadot-v0.9.8'326default-features = false327328[dependencies.cumulus-pallet-xcm]329git = 'https://github.com/paritytech/cumulus.git'330branch = 'polkadot-v0.9.8'331default-features = false332333[dependencies.cumulus-pallet-dmp-queue]334git = 'https://github.com/paritytech/cumulus.git'335branch = 'polkadot-v0.9.8'336default-features = false337338[dependencies.cumulus-pallet-xcmp-queue]339git = 'https://github.com/paritytech/cumulus.git'340branch = 'polkadot-v0.9.8'341default-features = false342343[dependencies.cumulus-primitives-utility]344git = 'https://github.com/paritytech/cumulus.git'345branch = 'polkadot-v0.9.8'346default-features = false347348[dependencies.cumulus-primitives-timestamp]349git = 'https://github.com/paritytech/cumulus.git'350branch = 'polkadot-v0.9.8'351default-features = false352353################################################################################354# Polkadot dependencies355356[dependencies.polkadot-parachain]357git = 'https://github.com/paritytech/polkadot'358branch = 'release-v0.9.8'359default-features = false360361[dependencies.xcm]362git = 'https://github.com/paritytech/polkadot'363branch = 'release-v0.9.8'364default-features = false365366[dependencies.xcm-builder]367git = 'https://github.com/paritytech/polkadot'368branch = 'release-v0.9.8'369default-features = false370371[dependencies.xcm-executor]372git = 'https://github.com/paritytech/polkadot'373branch = 'release-v0.9.8'374default-features = false375376[dependencies.pallet-xcm]377git = 'https://github.com/paritytech/polkadot'378branch = 'release-v0.9.8'379default-features = false380381382################################################################################383# local dependencies384385[dependencies]386max-encoded-len = { default-features = false, features = ['derive'], version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }387derivative = "2.2.0"388pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }389pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }390nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }391pallet-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }392# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }393pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }394pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }395pallet-evm-contract-helpers = { path = '../pallets/evm-contract-helpers', default-features = false }396pallet-evm-transaction-payment = { path = '../pallets/evm-transaction-payment', default-features = false }397pallet-evm-coder-substrate = { default-features = false, path = "../pallets/evm-coder-substrate" }398399pallet-evm = { default-features = false, version = "5.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "injected-transactions-parachain" }400pallet-ethereum = { default-features = false, version = "3.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "injected-transactions-parachain" }401fp-rpc = { default-features = false, version = "2.0.0", git = "https://github.com/uniquenetwork/frontier.git", branch = "injected-transactions-parachain" }402403################################################################################404# Build Dependencies405406[build-dependencies]407substrate-wasm-builder = '4.0.0'
modifiedruntime/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);