diff --git a/.github/assets/check_rv32imac.sh b/.github/assets/check_rv32imac.sh index 59dd578a72..1d23655e34 100755 --- a/.github/assets/check_rv32imac.sh +++ b/.github/assets/check_rv32imac.sh @@ -25,6 +25,7 @@ crates_to_check=( reth-evm-ethereum reth-ethereum-forks reth-ethereum-primitives + reth-ethereum-consensus ## optimism reth-optimism-chainspec diff --git a/Cargo.toml b/Cargo.toml index 33457c81c5..0658d9cf05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -349,7 +349,7 @@ reth-era-downloader = { path = "crates/era-downloader" } reth-eth-wire = { path = "crates/net/eth-wire" } reth-eth-wire-types = { path = "crates/net/eth-wire-types" } reth-ethereum-cli = { path = "crates/ethereum/cli" } -reth-ethereum-consensus = { path = "crates/ethereum/consensus" } +reth-ethereum-consensus = { path = "crates/ethereum/consensus", default-features = false } reth-ethereum-engine-primitives = { path = "crates/ethereum/engine-primitives", default-features = false } reth-ethereum-forks = { path = "crates/ethereum-forks", default-features = false } reth-ethereum-payload-builder = { path = "crates/ethereum/payload" } diff --git a/crates/ethereum/consensus/Cargo.toml b/crates/ethereum/consensus/Cargo.toml index 12e17a29f4..d389f940cd 100644 --- a/crates/ethereum/consensus/Cargo.toml +++ b/crates/ethereum/consensus/Cargo.toml @@ -25,6 +25,21 @@ alloy-consensus.workspace = true tracing.workspace = true +[features] +default = ["std"] +std = [ + "alloy-consensus/std", + "alloy-eips/std", + "alloy-primitives/std", + "reth-chainspec/std", + "reth-consensus/std", + "reth-consensus-common/std", + "reth-ethereum-primitives/std", + "reth-execution-types/std", + "reth-primitives-traits/std", + "tracing/std", +] + [dev-dependencies] reth-ethereum-primitives.workspace = true alloy-primitives = { workspace = true, features = ["getrandom"] } diff --git a/crates/ethereum/consensus/src/lib.rs b/crates/ethereum/consensus/src/lib.rs index c1087a0a28..8dce0efe53 100644 --- a/crates/ethereum/consensus/src/lib.rs +++ b/crates/ethereum/consensus/src/lib.rs @@ -7,9 +7,13 @@ )] #![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; + +use alloc::{fmt::Debug, sync::Arc}; use alloy_consensus::EMPTY_OMMER_ROOT_HASH; -use alloy_eips::{eip7840::BlobParams, merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS}; +use alloy_eips::eip7840::BlobParams; use alloy_primitives::U256; use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_consensus::{Consensus, ConsensusError, FullConsensus, HeaderValidator}; @@ -24,7 +28,6 @@ use reth_primitives_traits::{ constants::{GAS_LIMIT_BOUND_DIVISOR, MINIMUM_GAS_LIMIT}, Block, BlockHeader, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader, }; -use std::{fmt::Debug, sync::Arc, time::SystemTime}; mod validation; pub use validation::validate_block_post_execution; @@ -241,14 +244,20 @@ where // order, making those checks obsolete. // Check if timestamp is in the future. Clock can drift but this can be consensus issue. - let present_timestamp = - SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs(); - - if header.timestamp() > present_timestamp + ALLOWED_FUTURE_BLOCK_TIME_SECONDS { - return Err(ConsensusError::TimestampIsInFuture { - timestamp: header.timestamp(), - present_timestamp, - }) + #[cfg(feature = "std")] + { + let present_timestamp = std::time::SystemTime::now() + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs(); + if header.timestamp() > + present_timestamp + alloy_eips::merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS + { + return Err(ConsensusError::TimestampIsInFuture { + timestamp: header.timestamp(), + present_timestamp, + }) + } } validate_header_extra_data(header)?; diff --git a/crates/ethereum/consensus/src/validation.rs b/crates/ethereum/consensus/src/validation.rs index ccad0ce7a6..726d7464d5 100644 --- a/crates/ethereum/consensus/src/validation.rs +++ b/crates/ethereum/consensus/src/validation.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use alloy_consensus::{proofs::calculate_receipt_root, BlockHeader, TxReceipt}; use alloy_eips::eip7685::Requests; use alloy_primitives::{Bloom, B256}; diff --git a/crates/ethereum/reth/Cargo.toml b/crates/ethereum/reth/Cargo.toml index b70452ef03..09132f88d5 100644 --- a/crates/ethereum/reth/Cargo.toml +++ b/crates/ethereum/reth/Cargo.toml @@ -49,6 +49,7 @@ default = ["std"] std = [ "reth-chainspec/std", "reth-ethereum-primitives/std", + "reth-ethereum-consensus/std", "reth-primitives-traits/std", "reth-consensus?/std", "reth-consensus-common?/std", @@ -84,7 +85,17 @@ test-utils = [ "reth-transaction-pool?/test-utils", ] -full = ["consensus", "evm", "node", "provider", "rpc", "exex", "trie", "pool", "network"] +full = [ + "consensus", + "evm", + "node", + "provider", + "rpc", + "exex", + "trie", + "pool", + "network", +] alloy-compat = ["reth-ethereum-primitives/alloy-compat"] cli = ["dep:reth-ethereum-cli"]