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(primitives): use alloy eth conversion constants #11892

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/consensus/common/src/calc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_consensus::constants::ETH_TO_WEI;
use alloy_primitives::{BlockNumber, U256};
use reth_chainspec::{EthereumHardfork, Hardforks};
use reth_primitives::constants::ETH_TO_WEI;

/// Calculates the base block reward.
///
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn base_block_reward_pre_merge(chain_spec: impl Hardforks, block_number: Blo
/// ```
/// # use reth_chainspec::MAINNET;
/// # use reth_consensus_common::calc::{base_block_reward, block_reward};
/// # use reth_primitives::constants::ETH_TO_WEI;
/// # use alloy_consensus::constants::ETH_TO_WEI;
/// # use alloy_primitives::U256;
/// #
/// // This is block 126 on mainnet.
Expand Down
6 changes: 2 additions & 4 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl EthExecutorProvider {
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::{Header, TxLegacy};
use alloy_consensus::{constants::ETH_TO_WEI, Header, TxLegacy};
use alloy_eips::{
eip2935::{HISTORY_STORAGE_ADDRESS, HISTORY_STORAGE_CODE},
eip4788::{BEACON_ROOTS_ADDRESS, BEACON_ROOTS_CODE, SYSTEM_ADDRESS},
Expand All @@ -314,9 +314,7 @@ mod tests {
BasicBlockExecutorProvider, BatchExecutor, BlockExecutorProvider, Executor,
};
use reth_execution_types::BlockExecutionOutput;
use reth_primitives::{
constants::ETH_TO_WEI, public_key_to_address, Account, Block, BlockBody, Transaction,
};
use reth_primitives::{public_key_to_address, Account, Block, BlockBody, Transaction};
use reth_revm::{
database::StateProviderDatabase, test_utils::StateProviderTest, TransitionState,
};
Expand Down
36 changes: 19 additions & 17 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,29 @@ parking_lot = { workspace = true, optional = true }
[dev-dependencies]
parking_lot.workspace = true
reth-ethereum-forks.workspace = true
alloy-consensus.workspace = true

[features]
default = ["std"]
std = [
"dep:metrics",
"dep:reth-metrics",
"reth-consensus/std",
"reth-primitives/std",
"reth-primitives-traits/std",
"reth-revm/std",
"alloy-eips/std",
"alloy-primitives/std",
"revm-primitives/std",
"revm/std"
"dep:metrics",
"dep:reth-metrics",
"reth-consensus/std",
"reth-primitives/std",
"reth-primitives-traits/std",
"reth-revm/std",
"alloy-eips/std",
"alloy-primitives/std",
"alloy-consensus/std",
"revm-primitives/std",
"revm/std",
]
test-utils = [
"dep:parking_lot",
"reth-chainspec/test-utils",
"reth-consensus/test-utils",
"reth-primitives/test-utils",
"reth-primitives-traits/test-utils",
"reth-revm/test-utils",
"revm/test-utils"
"dep:parking_lot",
"reth-chainspec/test-utils",
"reth-consensus/test-utils",
"reth-primitives/test-utils",
"reth-primitives-traits/test-utils",
"reth-revm/test-utils",
"revm/test-utils",
]
2 changes: 1 addition & 1 deletion crates/evm/src/state_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub fn insert_post_block_withdrawals_balance_increments<ChainSpec: EthereumHardf
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::constants::GWEI_TO_WEI;
use reth_chainspec::ChainSpec;
use reth_ethereum_forks::{ChainHardforks, EthereumHardfork, ForkCondition};
use reth_primitives::constants::GWEI_TO_WEI;

/// Tests that the function correctly inserts balance increments when the Shanghai hardfork is
/// active and there are withdrawals.
Expand Down
5 changes: 2 additions & 3 deletions crates/exex/exex/src/backfill/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use alloy_consensus::TxEip2930;
use alloy_consensus::{constants::ETH_TO_WEI, TxEip2930};
use alloy_genesis::{Genesis, GenesisAccount};
use alloy_primitives::{b256, Address, TxKind, U256};
use eyre::OptionExt;
Expand All @@ -10,8 +10,7 @@ use reth_evm::execute::{
};
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_primitives::{
constants::ETH_TO_WEI, Block, BlockBody, BlockWithSenders, Header, Receipt,
SealedBlockWithSenders, Transaction,
Block, BlockBody, BlockWithSenders, Header, Receipt, SealedBlockWithSenders, Transaction,
};
use reth_provider::{
providers::ProviderNodeTypes, BlockWriter as _, ExecutionOutcome, LatestStateProviderRef,
Expand Down
1 change: 1 addition & 0 deletions crates/node/events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ reth-primitives-traits.workspace = true
# ethereum
alloy-primitives.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-consensus.workspace = true

# async
tokio.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/node/events/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Support for handling events emitted by node components.

use crate::cl::ConsensusLayerHealthEvent;
use alloy_consensus::constants::GWEI_TO_WEI;
use alloy_primitives::{BlockNumber, B256};
use alloy_rpc_types_engine::ForkchoiceState;
use futures::Stream;
Expand Down Expand Up @@ -263,7 +264,7 @@ impl NodeState {
gas=%format_gas(block.header.gas_used),
gas_throughput=%format_gas_throughput(block.header.gas_used, elapsed),
full=%format!("{:.1}%", block.header.gas_used as f64 * 100.0 / block.header.gas_limit as f64),
base_fee=%format!("{:.2}gwei", block.header.base_fee_per_gas.unwrap_or(0) as f64 / constants::GWEI_TO_WEI as f64),
base_fee=%format!("{:.2}gwei", block.header.base_fee_per_gas.unwrap_or(0) as f64 / GWEI_TO_WEI as f64),
blobs=block.header.blob_gas_used.unwrap_or(0) / constants::eip4844::DATA_GAS_PER_BLOB,
excess_blobs=block.header.excess_blob_gas.unwrap_or(0) / constants::eip4844::DATA_GAS_PER_BLOB,
?elapsed,
Expand Down
9 changes: 0 additions & 9 deletions crates/primitives-traits/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ pub const OP_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u128 = 6;
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
pub const BASE_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u128 = 10;

/// Multiplier for converting gwei to wei.
pub const GWEI_TO_WEI: u64 = 1_000_000_000;

/// Multiplier for converting finney (milliether) to wei.
pub const FINNEY_TO_WEI: u128 = (GWEI_TO_WEI as u128) * 1_000_000;

/// Multiplier for converting ether to wei.
pub const ETH_TO_WEI: u128 = FINNEY_TO_WEI * 1000;

/// Sepolia genesis hash: `0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9`
pub const SEPOLIA_GENESIS_HASH: B256 =
b256!("25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9");
Expand Down
27 changes: 15 additions & 12 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ revm.workspace = true
reth-trie.workspace = true
reth-ethereum-forks.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true

[features]
default = ["std"]
std = [
"reth-primitives/std",
"alloy-primitives/std",
"revm/std",
"alloy-eips/std"
"reth-primitives/std",
"alloy-primitives/std",
"revm/std",
"alloy-eips/std",
"alloy-consensus/std",
]
test-utils = [
"dep:reth-trie",
"reth-primitives/test-utils",
"reth-trie?/test-utils",
"revm/test-utils"
"dep:reth-trie",
"reth-primitives/test-utils",
"reth-trie?/test-utils",
"revm/test-utils",
]
serde = [
"revm/serde",
"reth-trie?/serde",
"alloy-eips/serde",
"alloy-primitives/serde"
"revm/serde",
"reth-trie?/serde",
"alloy-eips/serde",
"alloy-primitives/serde",
"alloy-consensus/serde",
]
3 changes: 2 additions & 1 deletion crates/rpc/rpc-eth-types/src/gas_oracle.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! An implementation of the eth gas price oracle, used for providing gas price estimates based on
//! previous blocks.

use alloy_consensus::constants::GWEI_TO_WEI;
use alloy_primitives::{B256, U256};
use alloy_rpc_types::BlockId;
use derive_more::{Deref, DerefMut, From, Into};
use itertools::Itertools;
use reth_primitives::{constants::GWEI_TO_WEI, BlockNumberOrTag};
use reth_primitives::BlockNumberOrTag;
use reth_rpc_server_types::constants;
use reth_storage_api::BlockReaderIdExt;
use schnellru::{ByLength, LruMap};
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-types/src/revm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use reth_primitives::constants::GWEI_TO_WEI;
use alloy_consensus::constants::GWEI_TO_WEI;

#[test]
fn test_ensure_0_fallback() {
Expand Down
Loading