Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make stages types no-std #14334

Merged
merged 4 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ reth-rpc-server-types = { path = "crates/rpc/rpc-server-types" }
reth-rpc-types-compat = { path = "crates/rpc/rpc-types-compat" }
reth-stages = { path = "crates/stages/stages" }
reth-stages-api = { path = "crates/stages/api" }
reth-stages-types = { path = "crates/stages/types" }
reth-stages-types = { path = "crates/stages/types", default-features = false }
reth-static-file = { path = "crates/static-file/static-file" }
reth-static-file-types = { path = "crates/static-file/types" }
reth-storage-api = { path = "crates/storage/storage-api" }
Expand Down
11 changes: 10 additions & 1 deletion crates/stages/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,27 @@ 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",
"dep:modular-bitfield",
"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",
Expand Down
7 changes: 6 additions & 1 deletion crates/stages/types/src/checkpoints.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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))
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/stages/types/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/stages/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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})")
Expand Down
1 change: 1 addition & 0 deletions crates/storage/storage-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ std = [
"reth-primitives/std",
"reth-primitives-traits/std",
"revm/std",
"reth-stages-types/std",
]
Loading