mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: move gas units to primitives constants (#8849)
This commit is contained in:
@ -1,20 +1,10 @@
|
|||||||
//! Contains various benchmark output formats, either for logging or for
|
//! Contains various benchmark output formats, either for logging or for
|
||||||
//! serialization to / from files.
|
//! 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 serde::{ser::SerializeStruct, Serialize};
|
||||||
use std::time::Duration;
|
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.
|
/// This is the suffix for gas output csv files.
|
||||||
pub(crate) const GAS_OUTPUT_SUFFIX: &str = "total_gas.csv";
|
pub(crate) const GAS_OUTPUT_SUFFIX: &str = "total_gas.csv";
|
||||||
|
|
||||||
|
|||||||
8
crates/primitives/src/constants/gas_units.rs
Normal file
8
crates/primitives/src/constants/gas_units.rs
Normal 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;
|
||||||
@ -10,6 +10,9 @@ pub use reth_primitives_traits::constants::*;
|
|||||||
#[cfg(feature = "optimism")]
|
#[cfg(feature = "optimism")]
|
||||||
use crate::chain::BaseFeeParams;
|
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.
|
/// [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#parameters) constants.
|
||||||
pub mod eip4844;
|
pub mod eip4844;
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,10 @@ use reth_db::{static_file::HeaderMask, tables};
|
|||||||
use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx};
|
use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx};
|
||||||
use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
|
use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
|
||||||
use reth_exex::{ExExManagerHandle, ExExNotification};
|
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::{
|
use reth_provider::{
|
||||||
providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter},
|
providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter},
|
||||||
BlockReader, Chain, DatabaseProviderRW, ExecutionOutcome, HeaderProvider,
|
BlockReader, Chain, DatabaseProviderRW, ExecutionOutcome, HeaderProvider,
|
||||||
@ -611,12 +614,12 @@ impl From<ExecutionConfig> for ExecutionStageThresholds {
|
|||||||
/// Depending on the magnitude of the gas throughput.
|
/// Depending on the magnitude of the gas throughput.
|
||||||
pub fn format_gas_throughput(gas: u64, execution_duration: Duration) -> String {
|
pub fn format_gas_throughput(gas: u64, execution_duration: Duration) -> String {
|
||||||
let gas_per_second = gas as f64 / execution_duration.as_secs_f64();
|
let gas_per_second = gas as f64 / execution_duration.as_secs_f64();
|
||||||
if gas_per_second < 1_000_000.0 {
|
if gas_per_second < MEGAGAS as f64 {
|
||||||
format!("{:.} Kgas/second", gas_per_second / 1_000.0)
|
format!("{:.} Kgas/second", gas_per_second / KILOGAS as f64)
|
||||||
} else if gas_per_second < 1_000_000_000.0 {
|
} else if gas_per_second < GIGAGAS as f64 {
|
||||||
format!("{:.} Mgas/second", gas_per_second / 1_000_000.0)
|
format!("{:.} Mgas/second", gas_per_second / MEGAGAS as f64)
|
||||||
} else {
|
} else {
|
||||||
format!("{:.} Ggas/second", gas_per_second / 1_000_000_000.0)
|
format!("{:.} Ggas/second", gas_per_second / GIGAGAS as f64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user