chore: move gas units to primitives constants (#8849)

This commit is contained in:
Dan Cline
2024-06-14 15:28:08 -04:00
committed by GitHub
parent f9165fb9af
commit 3b27da59dc
4 changed files with 21 additions and 17 deletions

View File

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

View File

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

View File

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

View File

@ -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<ExecutionConfig> 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)
}
}