diff --git a/bin/reth-bench/src/bench/output.rs b/bin/reth-bench/src/bench/output.rs index f976b5d28..83103418d 100644 --- a/bin/reth-bench/src/bench/output.rs +++ b/bin/reth-bench/src/bench/output.rs @@ -1,20 +1,10 @@ //! Contains various benchmark output formats, either for logging or for //! serialization to / from files. -//! -//! This also contains common constants for units, for example [GIGAGAS]. +use reth_primitives::constants::gas_units::GIGAGAS; use serde::{ser::SerializeStruct, Serialize}; use std::time::Duration; -/// Represents one Kilogas, or `1_000` gas. -const KILOGAS: u64 = 1_000; - -/// Represents one Megagas, or `1_000_000` gas. -const MEGAGAS: u64 = KILOGAS * 1_000; - -/// Represents one Gigagas, or `1_000_000_000` gas. -const GIGAGAS: u64 = MEGAGAS * 1_000; - /// This is the suffix for gas output csv files. pub(crate) const GAS_OUTPUT_SUFFIX: &str = "total_gas.csv"; diff --git a/crates/primitives/src/constants/gas_units.rs b/crates/primitives/src/constants/gas_units.rs new file mode 100644 index 000000000..9916de864 --- /dev/null +++ b/crates/primitives/src/constants/gas_units.rs @@ -0,0 +1,8 @@ +/// Represents one Kilogas, or `1_000` gas. +pub const KILOGAS: u64 = 1_000; + +/// Represents one Megagas, or `1_000_000` gas. +pub const MEGAGAS: u64 = KILOGAS * 1_000; + +/// Represents one Gigagas, or `1_000_000_000` gas. +pub const GIGAGAS: u64 = MEGAGAS * 1_000; diff --git a/crates/primitives/src/constants/mod.rs b/crates/primitives/src/constants/mod.rs index 191e6e1b2..41a26d609 100644 --- a/crates/primitives/src/constants/mod.rs +++ b/crates/primitives/src/constants/mod.rs @@ -10,6 +10,9 @@ pub use reth_primitives_traits::constants::*; #[cfg(feature = "optimism")] use crate::chain::BaseFeeParams; +/// Gas units, for example [`GIGAGAS`](gas_units::GIGAGAS). +pub mod gas_units; + /// [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#parameters) constants. pub mod eip4844; diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 0f2e5db65..b5b66cca7 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -5,7 +5,10 @@ use reth_db::{static_file::HeaderMask, tables}; use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx}; use reth_evm::execute::{BatchExecutor, BlockExecutorProvider}; use reth_exex::{ExExManagerHandle, ExExNotification}; -use reth_primitives::{BlockNumber, Header, StaticFileSegment}; +use reth_primitives::{ + constants::gas_units::{GIGAGAS, KILOGAS, MEGAGAS}, + BlockNumber, Header, StaticFileSegment, +}; use reth_provider::{ providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter}, BlockReader, Chain, DatabaseProviderRW, ExecutionOutcome, HeaderProvider, @@ -611,12 +614,12 @@ impl From for ExecutionStageThresholds { /// Depending on the magnitude of the gas throughput. pub fn format_gas_throughput(gas: u64, execution_duration: Duration) -> String { let gas_per_second = gas as f64 / execution_duration.as_secs_f64(); - if gas_per_second < 1_000_000.0 { - format!("{:.} Kgas/second", gas_per_second / 1_000.0) - } else if gas_per_second < 1_000_000_000.0 { - format!("{:.} Mgas/second", gas_per_second / 1_000_000.0) + if gas_per_second < MEGAGAS as f64 { + format!("{:.} Kgas/second", gas_per_second / KILOGAS as f64) + } else if gas_per_second < GIGAGAS as f64 { + format!("{:.} Mgas/second", gas_per_second / MEGAGAS as f64) } else { - format!("{:.} Ggas/second", gas_per_second / 1_000_000_000.0) + format!("{:.} Ggas/second", gas_per_second / GIGAGAS as f64) } }