Skip to content

Commit

Permalink
chore: decouple pallet-timestamp from pallet-evm and pallet-ethereum (#…
Browse files Browse the repository at this point in the history
koushiro authored May 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e02aaa5 commit de9368d
Showing 9 changed files with 17 additions and 20 deletions.
7 changes: 1 addition & 6 deletions frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -16,15 +16,12 @@ ethereum-types = { workspace = true }
evm = { workspace = true, features = ["with-codec"] }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }

# Substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-timestamp = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Frontier
fp-consensus = { workspace = true }
fp-ethereum = { workspace = true }
@@ -39,6 +36,7 @@ libsecp256k1 = { workspace = true, features = ["static-context", "hmac"] }
rlp = { workspace = true }
# Substrate
pallet-balances = { workspace = true, features = ["default"] }
pallet-timestamp = { workspace = true, features = ["default"] }
sp-core = { workspace = true, features = ["default"] }
# Frontier
fp-self-contained = { workspace = true, features = ["default"] }
@@ -55,7 +53,6 @@ std = [
# Substrate
"frame-support/std",
"frame-system/std",
"pallet-timestamp/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
@@ -71,13 +68,11 @@ std = [
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-evm/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-evm/try-runtime",
]
forbid-evm-reentrancy = ["pallet-evm/forbid-evm-reentrancy"]
8 changes: 3 additions & 5 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ use frame_support::{
codec::{Decode, Encode, MaxEncodedLen},
dispatch::{DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo},
scale_info::TypeInfo,
traits::{EnsureOrigin, Get, PalletInfoAccess},
traits::{EnsureOrigin, Get, PalletInfoAccess, Time},
weights::Weight,
};
use frame_system::{pallet_prelude::OriginFor, CheckWeight, WeightInfo};
@@ -188,7 +188,7 @@ pub mod pallet {
pub type Origin = RawOrigin;

#[pallet::config]
pub trait Config: frame_system::Config + pallet_timestamp::Config + pallet_evm::Config {
pub trait Config: frame_system::Config + pallet_evm::Config {
/// The overarching event type.
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// How Ethereum state root is calculated.
@@ -423,9 +423,7 @@ impl<T: Config> Pallet<T> {
number: block_number,
gas_limit: T::BlockGasLimit::get(),
gas_used: cumulative_gas_used,
timestamp: UniqueSaturatedInto::<u64>::unique_saturated_into(
pallet_timestamp::Pallet::<T>::get(),
),
timestamp: T::Timestamp::now().unique_saturated_into(),
extra_data: Vec::new(),
mix_hash: H256::default(),
nonce: H64::default(),
1 change: 1 addition & 0 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
@@ -169,6 +169,7 @@ impl pallet_evm::Config for Test {
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type Timestamp = Timestamp;
type WeightInfo = ();
}

5 changes: 1 addition & 4 deletions frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ scale-info = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-timestamp = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
@@ -37,6 +36,7 @@ fp-evm = { workspace = true }
# Substrate
pallet-balances = { workspace = true, features = ["default"] }
pallet-evm-precompile-simple = { workspace = true, features = ["default"] }
pallet-timestamp = { workspace = true, features = ["default"] }

[features]
default = ["std"]
@@ -53,7 +53,6 @@ std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"pallet-timestamp/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
@@ -66,11 +65,9 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-timestamp/try-runtime",
]
forbid-evm-reentrancy = ["dep:environmental"]
1 change: 1 addition & 0 deletions frame/evm/precompile/dispatch/src/mock.rs
Original file line number Diff line number Diff line change
@@ -159,6 +159,7 @@ impl pallet_evm::Config for Test {
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type Timestamp = Timestamp;
type WeightInfo = ();
}

7 changes: 5 additions & 2 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ use frame_support::{
dispatch::{DispatchResultWithPostInfo, Pays, PostDispatchInfo},
traits::{
tokens::fungible::Inspect, Currency, ExistenceRequirement, FindAuthor, Get, Imbalance,
OnUnbalanced, SignedImbalance, WithdrawReasons,
OnUnbalanced, SignedImbalance, Time, WithdrawReasons,
},
weights::Weight,
};
@@ -112,7 +112,7 @@ pub mod pallet {
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config + pallet_timestamp::Config {
pub trait Config: frame_system::Config {
/// Calculator for current gas price.
type FeeCalculator: FeeCalculator;

@@ -158,6 +158,9 @@ pub mod pallet {
/// Find author for the current block.
type FindAuthor: FindAuthor<H160>;

/// Get the timestamp for the current block.
type Timestamp: Time;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;

3 changes: 2 additions & 1 deletion frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
@@ -152,10 +152,11 @@ impl crate::Config for Test {
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type Timestamp = Timestamp;
type WeightInfo = ();
}

/// Exemple PrecompileSet with only Identity precompile.
/// Example PrecompileSet with only Identity precompile.
pub struct MockPrecompileSet;

impl PrecompileSet for MockPrecompileSet {
4 changes: 2 additions & 2 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ use evm::{
ExitError, ExitReason, Transfer,
};
use fp_evm::{CallInfo, CreateInfo, ExecutionInfo, Log, PrecompileSet, Vicinity};
use frame_support::traits::{Currency, ExistenceRequirement, Get};
use frame_support::traits::{Currency, ExistenceRequirement, Get, Time};
use sp_core::{H160, H256, U256};
use sp_runtime::traits::UniqueSaturatedInto;
use sp_std::{
@@ -634,7 +634,7 @@ impl<'vicinity, 'config, T: Config> BackendT for SubstrateStackState<'vicinity,
}

fn block_timestamp(&self) -> U256 {
let now: u128 = pallet_timestamp::Pallet::<T>::get().unique_saturated_into();
let now: u128 = T::Timestamp::now().unique_saturated_into();
U256::from(now / 1000)
}

1 change: 1 addition & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -345,6 +345,7 @@ impl pallet_evm::Config for Runtime {
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated<Aura>;
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}

0 comments on commit de9368d

Please sign in to comment.