chore: make stages types no-std (#14334)

This commit is contained in:
Matthias Seitz
2025-02-08 17:40:52 +01:00
committed by GitHub
parent 2b16b06a39
commit 7d0f5b757f
6 changed files with 22 additions and 6 deletions

View File

@ -34,6 +34,13 @@ rand.workspace = true
bytes.workspace = true
[features]
default = ["std"]
std = [
"alloy-primitives/std",
"bytes?/std",
"reth-trie-common/std",
"serde?/std",
]
reth-codec = [
"dep:reth-codecs",
"dep:bytes",
@ -41,11 +48,13 @@ reth-codec = [
"reth-trie-common/reth-codec",
]
test-utils = [
"dep:arbitrary",
"arbitrary",
"reth-codecs?/test-utils",
"reth-trie-common/test-utils",
]
arbitrary = [
"std",
"dep:arbitrary",
"alloy-primitives/arbitrary",
"reth-codecs?/arbitrary",
"reth-trie-common/arbitrary",

View File

@ -1,5 +1,5 @@
use super::StageId;
use alloc::vec::Vec;
use alloc::{format, string::String, vec::Vec};
use alloy_primitives::{Address, BlockNumber, B256};
use core::ops::RangeInclusive;
use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode};
@ -170,6 +170,11 @@ impl EntitiesCheckpoint {
let percentage = 100.0 * self.processed as f64 / self.total as f64;
// Truncate to 2 decimal places, rounding down so that 99.999% becomes 99.99% and not 100%.
#[cfg(not(feature = "std"))]
{
Some(format!("{:.2}%", (percentage * 100.0) / 100.0))
}
#[cfg(feature = "std")]
Some(format!("{:.2}%", (percentage * 100.0).floor() / 100.0))
}
}

View File

@ -97,8 +97,8 @@ impl StageId {
}
}
impl std::fmt::Display for StageId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Display for StageId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}

View File

@ -7,6 +7,7 @@
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
@ -68,7 +69,7 @@ impl From<BlockHash> for PipelineTarget {
}
impl core::fmt::Display for PipelineTarget {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Sync(block) => {
write!(f, "Sync({block})")

View File

@ -46,4 +46,5 @@ std = [
"reth-primitives/std",
"reth-primitives-traits/std",
"revm/std",
"reth-stages-types/std",
]