difftreelog
doc(pallet-evm-migration): document public api
in: master
4 files changed
pallets/evm-migration/README.mddiffbeforeafterboth--- /dev/null
+++ b/pallets/evm-migration/README.md
@@ -0,0 +1,18 @@
+# EVM contract migration pallet
+
+This pallet is only callable by root, it has functionality to migrate contract
+from other ethereum chain to pallet-evm
+
+Contract data includes contract code, and contract storage,
+where contract storage is a mapping from evm word to evm word (evm word = 32 byte)
+
+To import contract data into pallet-evm admin should call this pallet multiple times:
+1. Start migration via `begin`
+2. Insert all contract data using single or
+ multiple (If data can't be fit into single extrinsic) calls
+ to `set_data`
+3. Finish migration using `finish`, providing contract code
+
+During migration no one can insert code at address of this contract,
+as [`pallet::OnMethodCall`] prevents this, and no one can call this contract,
+as code is only supplied at final stage of contract deployment
\ No newline at end of file
pallets/evm-migration/src/benchmarking.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use super::{Call, Config, Pallet};18use frame_benchmarking::benchmarks;19use frame_system::RawOrigin;20use sp_core::{H160, H256};21use sp_std::vec::Vec;2223benchmarks! {24 begin {25 }: _(RawOrigin::Root, H160::default())2627 set_data {28 let b in 0..80;29 let address = H160::from_low_u64_be(b as u64);30 let mut data = Vec::new();31 for i in 0..b {32 data.push((33 H256::from_low_u64_be(i as u64),34 H256::from_low_u64_be(i as u64),35 ));36 }37 <Pallet<T>>::begin(RawOrigin::Root.into(), address)?;38 }: _(RawOrigin::Root, address, data)3940 finish {41 let b in 0..80;42 let address = H160::from_low_u64_be(b as u64);43 let data: Vec<u8> = (0..b as u8).collect();44 <Pallet<T>>::begin(RawOrigin::Root.into(), address)?;45 }: _(RawOrigin::Root, address, data)46}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![allow(missing_docs)]1819use super::{Call, Config, Pallet};20use frame_benchmarking::benchmarks;21use frame_system::RawOrigin;22use sp_core::{H160, H256};23use sp_std::vec::Vec;2425benchmarks! {26 begin {27 }: _(RawOrigin::Root, H160::default())2829 set_data {30 let b in 0..80;31 let address = H160::from_low_u64_be(b as u64);32 let mut data = Vec::new();33 for i in 0..b {34 data.push((35 H256::from_low_u64_be(i as u64),36 H256::from_low_u64_be(i as u64),37 ));38 }39 <Pallet<T>>::begin(RawOrigin::Root.into(), address)?;40 }: _(RawOrigin::Root, address, data)4142 finish {43 let b in 0..80;44 let address = H160::from_low_u64_be(b as u64);45 let data: Vec<u8> = (0..b as u8).collect();46 <Pallet<T>>::begin(RawOrigin::Root.into(), address)?;47 }: _(RawOrigin::Root, address, data)48}pallets/evm-migration/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/lib.rs
+++ b/pallets/evm-migration/src/lib.rs
@@ -14,7 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
+#![deny(missing_docs)]
pub use pallet::*;
#[cfg(feature = "runtime-benchmarks")]
@@ -32,6 +34,7 @@
#[pallet::config]
pub trait Config: frame_system::Config + pallet_evm::Config {
+ /// Weights
type WeightInfo: WeightInfo;
}
@@ -43,7 +46,9 @@
#[pallet::error]
pub enum Error<T> {
+ /// Can only migrate to empty address.
AccountNotEmpty,
+ /// Migration of this account is not yet started, or already finished.
AccountIsNotMigrating,
}
@@ -53,6 +58,8 @@
#[pallet::call]
impl<T: Config> Pallet<T> {
+ /// Start contract migration, inserts contract stub at target address,
+ /// and marks account as pending, allowing to insert storage
#[pallet::weight(<SelfWeightOf<T>>::begin())]
pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {
ensure_root(origin)?;
@@ -65,6 +72,8 @@
Ok(())
}
+ /// Insert items into contract storage, this method can be called
+ /// multiple times
#[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]
pub fn set_data(
origin: OriginFor<T>,
@@ -83,6 +92,9 @@
Ok(())
}
+ /// Finish contract migration, allows it to be called.
+ /// It is not possible to alter contract storage via [`Self::set_data`]
+ /// after this call.
#[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]
pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {
ensure_root(origin)?;
@@ -97,6 +109,7 @@
}
}
+ /// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration
pub struct OnMethodCall<T>(PhantomData<T>);
impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {
fn is_reserved(contract: &H160) -> bool {
pallets/evm-migration/src/weights.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/weights.rs
+++ b/pallets/evm-migration/src/weights.rs
@@ -26,6 +26,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(missing_docs)]
#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};