chore(primitives): use alloy eth conversion constants (#11892)

This commit is contained in:
Thomas Coratger
2024-10-22 12:34:53 +02:00
committed by GitHub
parent 2973f0c3e8
commit e52f647644
12 changed files with 50 additions and 51 deletions

3
Cargo.lock generated
View File

@ -7441,6 +7441,7 @@ dependencies = [
name = "reth-evm"
version = "1.1.0"
dependencies = [
"alloy-consensus",
"alloy-eips",
"alloy-primitives",
"auto_impl",
@ -8053,6 +8054,7 @@ dependencies = [
name = "reth-node-events"
version = "1.1.0"
dependencies = [
"alloy-consensus",
"alloy-primitives",
"alloy-rpc-types-engine",
"futures",
@ -8590,6 +8592,7 @@ dependencies = [
name = "reth-revm"
version = "1.1.0"
dependencies = [
"alloy-consensus",
"alloy-eips",
"alloy-primitives",
"reth-ethereum-forks",

View File

@ -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.
///
@ -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.

View File

@ -296,7 +296,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},
@ -309,9 +309,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,
};

View File

@ -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",
]

View File

@ -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.

View File

@ -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;
@ -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,

View File

@ -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

View File

@ -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;
@ -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,

View File

@ -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");

View File

@ -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",
]

View File

@ -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};

View File

@ -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() {