git.delta.rocks / unique-network / refs/commits / 68058b4890a6

difftreelog

doc(pallet-evm-migration): document public api

Yaroslav Bolyukin2022-07-12parent: #19dbab9.patch.diff
in: master

4 files changed

addedpallets/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
modifiedpallets/evm-migration/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/evm-migration/src/benchmarking.rs
+++ b/pallets/evm-migration/src/benchmarking.rs
@@ -14,6 +14,8 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
+#![allow(missing_docs)]
+
 use super::{Call, Config, Pallet};
 use frame_benchmarking::benchmarks;
 use frame_system::RawOrigin;
modifiedpallets/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 {
modifiedpallets/evm-migration/src/weights.rsdiffbeforeafterboth
before · pallets/evm-migration/src/weights.rs
1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_evm_migration4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-08-15, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// pallet13// --pallet14// pallet-evm-migration15// --wasm-execution16// compiled17// --extrinsic18// *19// --template20// .maintain/frame-weight-template.hbs21// --steps=5022// --repeat=8023// --heap-pages=409624// --output=./pallets/evm-migration/src/weights.rs2526#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]28#![allow(unused_imports)]29#![allow(clippy::unnecessary_cast)]3031use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};32use sp_std::marker::PhantomData;3334/// Weight functions needed for pallet_evm_migration.35pub trait WeightInfo {36	fn begin() -> Weight;37	fn set_data(b: u32, ) -> Weight;38	fn finish(b: u32, ) -> Weight;39}4041/// Weights for pallet_evm_migration using the Substrate node and recommended hardware.42pub struct SubstrateWeight<T>(PhantomData<T>);43impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {44	// Storage: EvmMigration MigrationPending (r:1 w:1)45	// Storage: System Account (r:1 w:0)46	// Storage: EVM AccountCodes (r:1 w:0)47	fn begin() -> Weight {48		(8_035_000 as Weight)49			.saturating_add(T::DbWeight::get().reads(3 as Weight))50			.saturating_add(T::DbWeight::get().writes(1 as Weight))51	}52	// Storage: EvmMigration MigrationPending (r:1 w:0)53	// Storage: EVM AccountStorages (r:0 w:1)54	fn set_data(b: u32, ) -> Weight {55		(3_076_000 as Weight)56			// Standard Error: 057			.saturating_add((828_000 as Weight).saturating_mul(b as Weight))58			.saturating_add(T::DbWeight::get().reads(1 as Weight))59			.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))60	}61	// Storage: EvmMigration MigrationPending (r:1 w:1)62	// Storage: EVM AccountCodes (r:0 w:1)63	fn finish(_b: u32, ) -> Weight {64		(6_591_000 as Weight)65			.saturating_add(T::DbWeight::get().reads(1 as Weight))66			.saturating_add(T::DbWeight::get().writes(2 as Weight))67	}68}6970// For backwards compatibility and tests71impl WeightInfo for () {72	// Storage: EvmMigration MigrationPending (r:1 w:1)73	// Storage: System Account (r:1 w:0)74	// Storage: EVM AccountCodes (r:1 w:0)75	fn begin() -> Weight {76		(8_035_000 as Weight)77			.saturating_add(RocksDbWeight::get().reads(3 as Weight))78			.saturating_add(RocksDbWeight::get().writes(1 as Weight))79	}80	// Storage: EvmMigration MigrationPending (r:1 w:0)81	// Storage: EVM AccountStorages (r:0 w:1)82	fn set_data(b: u32, ) -> Weight {83		(3_076_000 as Weight)84			// Standard Error: 085			.saturating_add((828_000 as Weight).saturating_mul(b as Weight))86			.saturating_add(RocksDbWeight::get().reads(1 as Weight))87			.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))88	}89	// Storage: EvmMigration MigrationPending (r:1 w:1)90	// Storage: EVM AccountCodes (r:0 w:1)91	fn finish(_b: u32, ) -> Weight {92		(6_591_000 as Weight)93			.saturating_add(RocksDbWeight::get().reads(1 as Weight))94			.saturating_add(RocksDbWeight::get().writes(2 as Weight))95	}96}
after · pallets/evm-migration/src/weights.rs
1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_evm_migration4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-08-15, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// pallet13// --pallet14// pallet-evm-migration15// --wasm-execution16// compiled17// --extrinsic18// *19// --template20// .maintain/frame-weight-template.hbs21// --steps=5022// --repeat=8023// --heap-pages=409624// --output=./pallets/evm-migration/src/weights.rs2526#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]28#![allow(unused_imports)]29#![allow(missing_docs)]30#![allow(clippy::unnecessary_cast)]3132use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};33use sp_std::marker::PhantomData;3435/// Weight functions needed for pallet_evm_migration.36pub trait WeightInfo {37	fn begin() -> Weight;38	fn set_data(b: u32, ) -> Weight;39	fn finish(b: u32, ) -> Weight;40}4142/// Weights for pallet_evm_migration using the Substrate node and recommended hardware.43pub struct SubstrateWeight<T>(PhantomData<T>);44impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {45	// Storage: EvmMigration MigrationPending (r:1 w:1)46	// Storage: System Account (r:1 w:0)47	// Storage: EVM AccountCodes (r:1 w:0)48	fn begin() -> Weight {49		(8_035_000 as Weight)50			.saturating_add(T::DbWeight::get().reads(3 as Weight))51			.saturating_add(T::DbWeight::get().writes(1 as Weight))52	}53	// Storage: EvmMigration MigrationPending (r:1 w:0)54	// Storage: EVM AccountStorages (r:0 w:1)55	fn set_data(b: u32, ) -> Weight {56		(3_076_000 as Weight)57			// Standard Error: 058			.saturating_add((828_000 as Weight).saturating_mul(b as Weight))59			.saturating_add(T::DbWeight::get().reads(1 as Weight))60			.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))61	}62	// Storage: EvmMigration MigrationPending (r:1 w:1)63	// Storage: EVM AccountCodes (r:0 w:1)64	fn finish(_b: u32, ) -> Weight {65		(6_591_000 as Weight)66			.saturating_add(T::DbWeight::get().reads(1 as Weight))67			.saturating_add(T::DbWeight::get().writes(2 as Weight))68	}69}7071// For backwards compatibility and tests72impl WeightInfo for () {73	// Storage: EvmMigration MigrationPending (r:1 w:1)74	// Storage: System Account (r:1 w:0)75	// Storage: EVM AccountCodes (r:1 w:0)76	fn begin() -> Weight {77		(8_035_000 as Weight)78			.saturating_add(RocksDbWeight::get().reads(3 as Weight))79			.saturating_add(RocksDbWeight::get().writes(1 as Weight))80	}81	// Storage: EvmMigration MigrationPending (r:1 w:0)82	// Storage: EVM AccountStorages (r:0 w:1)83	fn set_data(b: u32, ) -> Weight {84		(3_076_000 as Weight)85			// Standard Error: 086			.saturating_add((828_000 as Weight).saturating_mul(b as Weight))87			.saturating_add(RocksDbWeight::get().reads(1 as Weight))88			.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))89	}90	// Storage: EvmMigration MigrationPending (r:1 w:1)91	// Storage: EVM AccountCodes (r:0 w:1)92	fn finish(_b: u32, ) -> Weight {93		(6_591_000 as Weight)94			.saturating_add(RocksDbWeight::get().reads(1 as Weight))95			.saturating_add(RocksDbWeight::get().writes(2 as Weight))96	}97}