Skip to content

Commit

Permalink
Update to recent Substrate (#236)
Browse files Browse the repository at this point in the history
* port to Substrate ac4366b

* bump substrate version

* Bump substrate to 39278096

* Rename Trait to Config (like in Substrate)

* A few more `Trait`s

* Fix mock

* fix more mocks

* change branch name back to frontier

* remove unnecessary match

* Remove TODO
  • Loading branch information
JoshOrndorff authored Dec 11, 2020
1 parent 2ca1d1b commit e4bf5ef
Show file tree
Hide file tree
Showing 13 changed files with 722 additions and 959 deletions.
1,459 changes: 625 additions & 834 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ pub enum ReturnValue {
}

/// A type alias for the balance type from this pallet's point of view.
pub type BalanceOf<T> = <T as pallet_balances::Trait>::Balance;
pub type BalanceOf<T> = <T as pallet_balances::Config>::Balance;

/// Trait for Ethereum pallet.
pub trait Trait: frame_system::Trait<Hash=H256> + pallet_balances::Trait + pallet_timestamp::Trait + pallet_evm::Trait {
/// Configuration trait for Ethereum pallet.
pub trait Config: frame_system::Config<Hash=H256> + pallet_balances::Config + pallet_timestamp::Config + pallet_evm::Config {
/// The overarching event type.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
/// Find author for Ethereum.
type FindAuthor: FindAuthor<H160>;
}

decl_storage! {
trait Store for Module<T: Trait> as Ethereum {
trait Store for Module<T: Config> as Ethereum {
/// Current building block's transactions and receipts.
Pending: Vec<(ethereum::Transaction, TransactionStatus, ethereum::Receipt)>;

Expand Down Expand Up @@ -100,20 +100,20 @@ decl_event!(

decl_error! {
/// Ethereum pallet errors.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Signature is invalid.
InvalidSignature,
}
}

decl_module! {
/// Ethereum pallet module.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// Deposit one of this pallet's events by using the default implementation.
fn deposit_event() = default;

/// Transact an Ethereum transaction.
#[weight = <T as pallet_evm::Trait>::GasToWeight::gas_to_weight(transaction.gas_limit.low_u32())]
#[weight = <T as pallet_evm::Config>::GasToWeight::gas_to_weight(transaction.gas_limit.low_u32())]
fn transact(origin, transaction: ethereum::Transaction) -> DispatchResultWithPostInfo {
ensure_none(origin)?;

Expand Down Expand Up @@ -212,7 +212,7 @@ enum TransactionValidationError {
InvalidSignature,
}

impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;

fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
Expand Down Expand Up @@ -254,7 +254,7 @@ impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
}
}

impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
fn recover_signer(transaction: &ethereum::Transaction) -> Option<H160> {
let mut sig = [0u8; 65];
let mut msg = [0u8; 32];
Expand Down
12 changes: 6 additions & 6 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Test utilities
use super::*;
use crate::{Module, Trait};
use crate::{Module, Config};
use ethereum::{TransactionAction, TransactionSignature};
use frame_support::{
impl_outer_origin, parameter_types, weights::Weight, ConsensusEngineId
Expand Down Expand Up @@ -48,7 +48,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type Origin = Origin;
Expand Down Expand Up @@ -83,7 +83,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 500;
}

impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
type Balance = u64;
type Event = ();
Expand All @@ -97,7 +97,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = 6000 / 2;
}

impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
Expand Down Expand Up @@ -136,7 +136,7 @@ impl AddressMapping<AccountId32> for HashedAddressMapping {
}
}

impl pallet_evm::Trait for Test {
impl pallet_evm::Config for Test {
type FeeCalculator = FixedGasPrice;
type GasToWeight = ();
type CallOrigin = EnsureAddressTruncated;
Expand All @@ -149,7 +149,7 @@ impl pallet_evm::Trait for Test {
type ChainId = ChainId;
}

impl Trait for Test {
impl Config for Test {
type Event = ();
type FindAuthor = EthereumFindAuthor;
}
Expand Down
2 changes: 1 addition & 1 deletion frame/evm/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# EVM Module

The EVM module allows unmodified EVM code to be executed in a Substrate-based blockchain.
- [`evm::Trait`](https://docs.rs/pallet-evm/2.0.0/pallet_evm/trait.Trait.html)
- [`evm::Config`](https://docs.rs/pallet-evm/2.0.0/pallet_evm/trait.Trait.html)

## EVM Engine

Expand Down
24 changes: 12 additions & 12 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! # EVM Module
//!
//! The EVM module allows unmodified EVM code to be executed in a Substrate-based blockchain.
//! - [`evm::Trait`]
//! - [`evm::Config`]
//!
//! ## EVM Engine
//!
Expand Down Expand Up @@ -74,10 +74,10 @@ use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_system::RawOrigin;
use sp_core::{U256, H256, H160, Hasher};
use sp_runtime::{AccountId32, traits::{UniqueSaturatedInto, BadOrigin}};
use evm::Config;
use evm::Config as EvmConfig;

/// Type alias for currency balance.
pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
pub type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

/// Trait that outputs the current transaction gas price.
pub trait FeeCalculator {
Expand Down Expand Up @@ -227,10 +227,10 @@ impl Get<u64> for SystemChainId {
}
}

static ISTANBUL_CONFIG: Config = Config::istanbul();
static ISTANBUL_CONFIG: EvmConfig = EvmConfig::istanbul();

/// EVM module trait
pub trait Trait: frame_system::Trait + pallet_timestamp::Trait {
pub trait Config: frame_system::Config + pallet_timestamp::Config {
/// Calculator for current gas price.
type FeeCalculator: FeeCalculator;

Expand All @@ -248,7 +248,7 @@ pub trait Trait: frame_system::Trait + pallet_timestamp::Trait {
type Currency: Currency<Self::AccountId>;

/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Precompiles associated with this EVM engine.
type Precompiles: Precompiles;
/// Chain ID of EVM.
Expand All @@ -257,7 +257,7 @@ pub trait Trait: frame_system::Trait + pallet_timestamp::Trait {
type Runner: Runner<Self>;

/// EVM config used in the module.
fn config() -> &'static Config {
fn config() -> &'static EvmConfig {
&ISTANBUL_CONFIG
}
}
Expand All @@ -277,7 +277,7 @@ pub struct GenesisAccount {
}

decl_storage! {
trait Store for Module<T: Trait> as EVM {
trait Store for Module<T: Config> as EVM {
AccountCodes get(fn account_codes): map hasher(blake2_128_concat) H160 => Vec<u8>;
AccountStorages get(fn account_storages):
double_map hasher(blake2_128_concat) H160, hasher(blake2_128_concat) H256 => H256;
Expand Down Expand Up @@ -313,7 +313,7 @@ decl_storage! {
decl_event! {
/// EVM events
pub enum Event<T> where
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::AccountId,
{
/// Ethereum events from contracts.
Log(Log),
Expand All @@ -333,7 +333,7 @@ decl_event! {
}

decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Not enough balance to perform action
BalanceLow,
/// Calculating total fee overflowed
Expand All @@ -350,7 +350,7 @@ decl_error! {
}

decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;

fn deposit_event() = default;
Expand Down Expand Up @@ -506,7 +506,7 @@ decl_module! {
}
}

impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Check whether an account is empty.
pub fn is_account_empty(address: &H160) -> bool {
let account = Self::account_basic(address);
Expand Down
20 changes: 10 additions & 10 deletions frame/evm/src/runner/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ use evm::{
ExternalOpcode, Opcode, ExitError, ExitReason, Capture, Context, CreateScheme, Stack,
Transfer, ExitSucceed, Runtime,
};
use evm_runtime::{Config, Handler as HandlerT};
use evm_runtime::{Config as EvmConfig, Handler as HandlerT};
use evm_gasometer::{self as gasometer, Gasometer};
use crate::{
Trait, Vicinity, Module, Event, Log, AccountCodes, AccountStorages, AddressMapping,
Config, Vicinity, Module, Event, Log, AccountCodes, AccountStorages, AddressMapping,
Runner as RunnerT, Error, CallInfo, CreateInfo, FeeCalculator, precompiles::Precompiles,
};

#[derive(Default)]
pub struct Runner<T: Trait> {
pub struct Runner<T: Config> {
_marker: PhantomData<T>,
}

impl<T: Trait> RunnerT<T> for Runner<T> {
impl<T: Config> RunnerT<T> for Runner<T> {
type Error = Error<T>;

fn call(
Expand Down Expand Up @@ -280,9 +280,9 @@ fn l64(gas: usize) -> usize {
gas - gas / 64
}

pub struct Handler<'vicinity, 'config, T: Trait> {
pub struct Handler<'vicinity, 'config, T: Config> {
vicinity: &'vicinity Vicinity,
config: &'config Config,
config: &'config EvmConfig,
gasometer: Gasometer<'config>,
deleted: BTreeSet<H160>,
logs: Vec<Log>,
Expand All @@ -292,13 +292,13 @@ pub struct Handler<'vicinity, 'config, T: Trait> {
_marker: PhantomData<T>,
}

impl<'vicinity, 'config, T: Trait> Handler<'vicinity, 'config, T> {
impl<'vicinity, 'config, T: Config> Handler<'vicinity, 'config, T> {
/// Create a new handler with given vicinity.
pub fn new_with_precompile(
vicinity: &'vicinity Vicinity,
gas_limit: usize,
is_static: bool,
config: &'config Config,
config: &'config EvmConfig,
precompile: fn(H160, &[u8], Option<usize>) ->
Option<Result<(ExitSucceed, Vec<u8>, usize), ExitError>>,
) -> Self {
Expand Down Expand Up @@ -411,7 +411,7 @@ impl<'vicinity, 'config, T: Trait> Handler<'vicinity, 'config, T> {
}
}

impl<'vicinity, 'config, T: Trait> HandlerT for Handler<'vicinity, 'config, T> {
impl<'vicinity, 'config, T: Config> HandlerT for Handler<'vicinity, 'config, T> {
type CreateInterrupt = Infallible;
type CreateFeedback = Infallible;
type CallInterrupt = Infallible;
Expand Down Expand Up @@ -782,7 +782,7 @@ impl<'vicinity, 'config, T: Trait> HandlerT for Handler<'vicinity, 'config, T> {
}
}

impl<'vicinity, 'config, T: Trait> Drop for Handler<'vicinity, 'config, T> {
impl<'vicinity, 'config, T: Config> Drop for Handler<'vicinity, 'config, T> {
fn drop(&mut self) {
let mut deleted = BTreeSet::new();
mem::swap(&mut deleted, &mut self.deleted);
Expand Down
4 changes: 2 additions & 2 deletions frame/evm/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub mod builtin;
use sp_std::vec::Vec;
use sp_core::{H160, U256, H256};
use fp_evm::{CallInfo, CreateInfo};
use crate::Trait;
use crate::Config;

pub trait Runner<T: Trait> {
pub trait Runner<T: Config> {
type Error: Into<sp_runtime::DispatchError>;

fn call(
Expand Down
14 changes: 7 additions & 7 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ use fp_evm::{ExecutionInfo, CallInfo, CreateInfo, Account, Log, Vicinity};
use evm::ExitReason;
use evm::backend::{Backend as BackendT, ApplyBackend, Apply};
use evm::executor::StackExecutor;
use crate::{Trait, AccountStorages, FeeCalculator, AccountCodes, Module, Event, Error, AddressMapping};
use crate::{Config, AccountStorages, FeeCalculator, AccountCodes, Module, Event, Error, AddressMapping};
use crate::runner::Runner as RunnerT;
use crate::precompiles::Precompiles;

#[derive(Default)]
pub struct Runner<T: Trait> {
pub struct Runner<T: Config> {
_marker: PhantomData<T>,
}

impl<T: Trait> Runner<T> {
impl<T: Config> Runner<T> {
/// Execute an EVM operation.
pub fn execute<F, R>(
source: H160,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<T: Trait> Runner<T> {
}
}

impl<T: Trait> RunnerT<T> for Runner<T> {
impl<T: Config> RunnerT<T> for Runner<T> {
type Error = Error<T>;

fn call(
Expand Down Expand Up @@ -210,7 +210,7 @@ pub struct Backend<'vicinity, T> {
_marker: PhantomData<T>,
}

impl<'vicinity, T: Trait> Backend<'vicinity, T> {
impl<'vicinity, T: Config> Backend<'vicinity, T> {
/// Create a new backend with given vicinity.
pub fn new(vicinity: &'vicinity Vicinity) -> Self {
Self { vicinity, _marker: PhantomData }
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<'vicinity, T: Trait> Backend<'vicinity, T> {
}
}

impl<'vicinity, T: Trait> BackendT for Backend<'vicinity, T> {
impl<'vicinity, T: Config> BackendT for Backend<'vicinity, T> {
fn gas_price(&self) -> U256 { self.vicinity.gas_price }
fn origin(&self) -> H160 { self.vicinity.origin }

Expand Down Expand Up @@ -307,7 +307,7 @@ impl<'vicinity, T: Trait> BackendT for Backend<'vicinity, T> {
}
}

impl<'vicinity, T: Trait> ApplyBackend for Backend<'vicinity, T> {
impl<'vicinity, T: Config> ApplyBackend for Backend<'vicinity, T> {
fn apply<A, I, L>(
&mut self,
values: A,
Expand Down
Loading

0 comments on commit e4bf5ef

Please sign in to comment.