Skip to content

Commit

Permalink
Use Get<H256> for state root instead of EthereumExt (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored Jan 7, 2021
1 parent 82a501c commit 690b090
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ use evm::ExitReason;
use fp_evm::CallOrCreateInfo;
use pallet_evm::{Runner, GasWeightMapping};
use sha3::{Digest, Keccak256};
use codec::Encode;
use codec::{Encode, Decode};
use fp_consensus::{FRONTIER_ENGINE_ID, ConsensusLog};

pub use fp_rpc::{TransactionStatus, EthereumExt};
pub use fp_rpc::TransactionStatus;
pub use ethereum::{Transaction, Log, Block, Receipt, TransactionAction, TransactionMessage};

#[cfg(all(feature = "std", test))]
Expand All @@ -62,14 +62,23 @@ 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::Config>::Balance;

pub struct IntermediateStateRoot;

impl Get<H256> for IntermediateStateRoot {
fn get() -> H256 {
H256::decode(&mut &sp_io::storage::root()[..])
.expect("Node is configured to use the same hash; qed")
}
}

/// 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::Config>::Event>;
/// Find author for Ethereum.
type FindAuthor: FindAuthor<H160>;
/// User configurable functions.
type Extension: EthereumExt;
/// How Ethereum state root is calculated.
type StateRoot: Get<H256>;
}

decl_storage! {
Expand Down Expand Up @@ -310,7 +319,7 @@ impl<T: Config> Module<T> {
nonce: H64::default(),
};
let mut block = ethereum::Block::new(partial_header, transactions.clone(), ommers);
block.header.state_root = T::Extension::eth_state_root();
block.header.state_root = T::StateRoot::get();

let mut transaction_hashes = Vec::new();

Expand Down
7 changes: 2 additions & 5 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, Config};
use crate::{Module, Config, IntermediateStateRoot};
use ethereum::{TransactionAction, TransactionSignature};
use frame_support::{
impl_outer_origin, parameter_types, weights::Weight, ConsensusEngineId
Expand All @@ -32,7 +32,6 @@ use sp_runtime::{
ModuleId, Perbill,
};
use sp_runtime::AccountId32;
use fp_rpc::EthereumExt;

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
Expand Down Expand Up @@ -150,12 +149,10 @@ impl pallet_evm::Config for Test {
type ChainId = ChainId;
}

impl EthereumExt for Test {}

impl Config for Test {
type Event = ();
type FindAuthor = EthereumFindAuthor;
type Extension = Self;
type StateRoot = IntermediateStateRoot;
}

pub type System = frame_system::Module<Test>;
Expand Down
3 changes: 1 addition & 2 deletions frame/evm/precompile/ed25519/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
extern crate alloc;

use alloc::vec::Vec;
use core::{cmp::min, convert::TryFrom};
use core::convert::TryFrom;
use fp_evm::LinearCostPrecompile;
use evm::{ExitSucceed, ExitError};
use ed25519_dalek::{PublicKey, Verifier, Signature};
Expand Down Expand Up @@ -153,4 +153,3 @@ mod tests {
}

}

1 change: 0 additions & 1 deletion frame/evm/precompile/modexp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
extern crate alloc;

use alloc::vec::Vec;
use core::cmp::max;
use fp_evm::LinearCostPrecompile;
use evm::{ExitSucceed, ExitError};
use num::{BigUint, Zero, One, ToPrimitive, FromPrimitive};
Expand Down
7 changes: 0 additions & 7 deletions primitives/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ use ethereum_types::Bloom;
use codec::{Encode, Decode};
use sp_std::vec::Vec;

pub trait EthereumExt {
fn eth_state_root() -> H256 {
H256::decode(&mut &sp_io::storage::root()[..])
.expect("Node is configured to use the same hash; qed")
}
}

#[derive(Eq, PartialEq, Clone, Encode, Decode, sp_runtime::RuntimeDebug)]
pub struct TransactionStatus {
pub transaction_hash: H256,
Expand Down
10 changes: 5 additions & 5 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ use pallet_evm::{
Account as EVMAccount, FeeCalculator, HashedAddressMapping,
EnsureAddressTruncated, Runner,
};
use fp_rpc::{TransactionStatus, EthereumExt};
pub type BlockNumber = u32;
use fp_rpc::TransactionStatus;
use pallet_transaction_payment::CurrencyAdapter;

/// Type of block number.
pub type BlockNumber = u32;

/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = MultiSignature;

Expand Down Expand Up @@ -314,12 +316,10 @@ impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F>
}
}

impl EthereumExt for Runtime {}

impl pallet_ethereum::Config for Runtime {
type Event = Event;
type FindAuthor = EthereumFindAuthor<Aura>;
type Extension = Self;
type StateRoot = pallet_ethereum::IntermediateStateRoot;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down

0 comments on commit 690b090

Please sign in to comment.