Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: decouple pallet-timestamp from pallet-evm and pallet-ethereum #1050

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand All @@ -55,7 +53,6 @@ std = [
# Substrate
"frame-support/std",
"frame-system/std",
"pallet-timestamp/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
Expand All @@ -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
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl pallet_evm::Config for Test {
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type Timestamp = Timestamp;
type WeightInfo = ();
}

Expand Down
5 changes: 1 addition & 4 deletions frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"]
Expand All @@ -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",
Expand All @@ -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
Expand Up @@ -159,6 +159,7 @@ impl pallet_evm::Config for Test {
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type Timestamp = Timestamp;
type WeightInfo = ();
}

Expand Down
7 changes: 5 additions & 2 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

Expand Down