diff --git a/Cargo.lock b/Cargo.lock index 87cb0af0b2..94cb19fa07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2171,6 +2171,7 @@ version = "3.0.0-dev" dependencies = [ "evm", "frame-support", + "frame-system", "parity-scale-codec", "serde", "sp-core", diff --git a/frame/ethereum/src/mock.rs b/frame/ethereum/src/mock.rs index 9614fb8a0c..9b313f2799 100644 --- a/frame/ethereum/src/mock.rs +++ b/frame/ethereum/src/mock.rs @@ -152,7 +152,7 @@ impl AddressMapping for HashedAddressMapping { } impl pallet_evm::Config for Test { - type AccountProvider = pallet_evm::NativeSystemAccountProvider; + type AccountProvider = fp_evm::NativeSystemAccountProvider; type FeeCalculator = FixedGasPrice; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; diff --git a/frame/evm/precompile/dispatch/src/mock.rs b/frame/evm/precompile/dispatch/src/mock.rs index 7163d8ea2d..2c6c0346a7 100644 --- a/frame/evm/precompile/dispatch/src/mock.rs +++ b/frame/evm/precompile/dispatch/src/mock.rs @@ -139,15 +139,17 @@ parameter_types! { pub WeightPerGas: Weight = Weight::from_ref_time(20_000); } impl pallet_evm::Config for Test { - type AccountProvider = pallet_evm::NativeSystemAccountProvider; + type AccountProvider = fp_evm::NativeSystemAccountProvider; type FeeCalculator = FixedGasPrice; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; - type CallOrigin = EnsureAddressRoot<::AccountId>; + type CallOrigin = + EnsureAddressRoot<::AccountId>; - type WithdrawOrigin = EnsureAddressNever<::AccountId>; + type WithdrawOrigin = + EnsureAddressNever<::AccountId>; type AddressMapping = IdentityAddressMapping; type Currency = Balances; diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 76bfb498a2..56dc414a60 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -64,9 +64,6 @@ pub mod runner; #[cfg(test)] mod tests; -mod account_provider; -pub use account_provider::{AccountProvider, NativeSystemAccountProvider}; - use frame_support::{ dispatch::{DispatchResultWithPostInfo, Pays, PostDispatchInfo}, traits::{ @@ -79,7 +76,7 @@ use frame_system::RawOrigin; use impl_trait_for_tuples::impl_for_tuples; use sp_core::{Hasher, H160, H256, U256}; use sp_runtime::{ - traits::{BadOrigin, Saturating, UniqueSaturatedInto, AtLeast32Bit, Zero}, + traits::{BadOrigin, Saturating, UniqueSaturatedInto, Zero}, AccountId32, DispatchErrorWithPostInfo, }; use sp_std::{cmp::min, vec::Vec}; @@ -90,9 +87,9 @@ pub use evm::{ #[cfg(feature = "std")] use fp_evm::GenesisAccount; pub use fp_evm::{ - Account, CallInfo, CreateInfo, ExecutionInfo, FeeCalculator, InvalidEvmTransactionError, - LinearCostPrecompile, Log, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput, - PrecompileResult, PrecompileSet, Vicinity, + Account, AccountProvider, CallInfo, CreateInfo, ExecutionInfo, FeeCalculator, + InvalidEvmTransactionError, LinearCostPrecompile, Log, Precompile, PrecompileFailure, + PrecompileHandle, PrecompileOutput, PrecompileResult, PrecompileSet, Vicinity, }; pub use self::{ @@ -131,12 +128,16 @@ pub mod pallet { /// Allow the origin to call on behalf of given address. type CallOrigin: EnsureAddressOrigin; /// Allow the origin to withdraw on behalf of given address. - type WithdrawOrigin: EnsureAddressOrigin::AccountId>; + type WithdrawOrigin: EnsureAddressOrigin< + Self::RuntimeOrigin, + Success = ::AccountId, + >; /// Mapping from address to account id. type AddressMapping: AddressMapping<::AccountId>; /// Currency type for withdraw and balance storage. - type Currency: Currency<::AccountId> + Inspect<::AccountId>; + type Currency: Currency<::AccountId> + + Inspect<::AccountId>; /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -517,12 +518,14 @@ pub mod pallet { } /// Type alias for currency balance. -pub type BalanceOf = - <::Currency as Currency<<::AccountProvider as AccountProvider>::AccountId>>::Balance; +pub type BalanceOf = <::Currency as Currency< + <::AccountProvider as AccountProvider>::AccountId, +>>::Balance; /// Type alias for negative imbalance during fees -type NegativeImbalanceOf = - ::AccountProvider as AccountProvider>::AccountId>>::NegativeImbalance; +type NegativeImbalanceOf = ::AccountProvider as AccountProvider>::AccountId, +>>::NegativeImbalance; pub trait EnsureAddressOrigin { /// Success return type. @@ -788,7 +791,9 @@ where Opposite = C::PositiveImbalance, >, OU: OnUnbalanced>, - U256: UniqueSaturatedInto<::AccountProvider as AccountProvider>::AccountId>>::Balance>, + U256: UniqueSaturatedInto< + ::AccountProvider as AccountProvider>::AccountId>>::Balance, + >, { // Kept type as Option to satisfy bound of Default type LiquidityInfo = Option>; diff --git a/frame/evm/src/mock.rs b/frame/evm/src/mock.rs index ad886616db..e6e5d82264 100644 --- a/frame/evm/src/mock.rs +++ b/frame/evm/src/mock.rs @@ -132,15 +132,17 @@ parameter_types! { pub MockPrecompiles: MockPrecompileSet = MockPrecompileSet; } impl crate::Config for Test { - type AccountProvider = crate::NativeSystemAccountProvider; + type AccountProvider = fp_evm::NativeSystemAccountProvider; type FeeCalculator = FixedGasPrice; type GasWeightMapping = crate::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type BlockHashMapping = crate::SubstrateBlockHashMapping; - type CallOrigin = EnsureAddressRoot<::AccountId>; + type CallOrigin = + EnsureAddressRoot<::AccountId>; - type WithdrawOrigin = EnsureAddressNever<::AccountId>; + type WithdrawOrigin = + EnsureAddressNever<::AccountId>; type AddressMapping = IdentityAddressMapping; type Currency = Balances; diff --git a/primitives/evm/Cargo.toml b/primitives/evm/Cargo.toml index 02e1e43e0e..ddb4e3767d 100644 --- a/primitives/evm/Cargo.toml +++ b/primitives/evm/Cargo.toml @@ -16,6 +16,7 @@ scale-codec = { package = "parity-scale-codec", workspace = true } serde = { workspace = true, optional = true } # Substrate frame-support = { workspace = true } +frame-system = { workspace = true } sp-core = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } @@ -29,6 +30,7 @@ std = [ "scale-codec/std", # Substrate "frame-support/std", + "frame-system/std", "sp-core/std", "sp-runtime/std", "sp-std/std", diff --git a/frame/evm/src/account_provider.rs b/primitives/evm/src/account_provider.rs similarity index 91% rename from frame/evm/src/account_provider.rs rename to primitives/evm/src/account_provider.rs index 69484222cf..7be007f32c 100644 --- a/frame/evm/src/account_provider.rs +++ b/primitives/evm/src/account_provider.rs @@ -1,6 +1,6 @@ //! Custom account provider logic. -use super::*; +use sp_runtime::traits::AtLeast32Bit; /// The account provider interface abstraction layer. /// @@ -43,9 +43,9 @@ pub trait AccountProvider { /// Native system account provider that `frame_system` provides. pub struct NativeSystemAccountProvider(sp_std::marker::PhantomData); -impl AccountProvider for NativeSystemAccountProvider { - type AccountId = ::AccountId; - type Index = ::Index; +impl AccountProvider for NativeSystemAccountProvider { + type AccountId = T::AccountId; + type Index = T::Index; fn account_nonce(who: &Self::AccountId) -> Self::Index { frame_system::Pallet::::account_nonce(&who) diff --git a/primitives/evm/src/lib.rs b/primitives/evm/src/lib.rs index 43e0929cda..4b241b1da0 100644 --- a/primitives/evm/src/lib.rs +++ b/primitives/evm/src/lib.rs @@ -17,6 +17,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +mod account_provider; mod precompile; mod validation; @@ -34,6 +35,7 @@ pub use evm::{ }; pub use self::{ + account_provider::{AccountProvider, NativeSystemAccountProvider}, precompile::{ Context, ExitError, ExitRevert, ExitSucceed, LinearCostPrecompile, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileResult, PrecompileSet, diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 2316298271..29a0f2d509 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -326,7 +326,7 @@ parameter_types! { } impl pallet_evm::Config for Runtime { - type AccountProvider = pallet_evm::NativeSystemAccountProvider; + type AccountProvider = fp_evm::NativeSystemAccountProvider; type FeeCalculator = BaseFee; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas;