Skip to content

Commit

Permalink
chore: no_std for reth-execution-types (#14465)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Feb 13, 2025
1 parent a699ee5 commit cfb91e9
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .github/assets/check_rv32imac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ crates_to_check=(
reth-chainspec
reth-consensus
reth-consensus-common
reth-prune-types
reth-static-file-types
reth-storage-errors
reth-execution-errors
reth-execution-types

## ethereum
reth-ethereum-forks
Expand Down
3 changes: 2 additions & 1 deletion .github/assets/check_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ exclude_crates=(
reth-ethereum-cli
reth-ethereum-payload-builder
reth-etl
reth-evm
reth-exex
reth-exex-test-utils
reth-ipc
Expand Down Expand Up @@ -58,7 +59,7 @@ exclude_crates=(
reth-invalid-block-hooks # reth-provider
reth-libmdbx # mdbx
reth-mdbx-sys # mdbx
reth-payload-builder # reth-metrics
reth-payload-builder # reth-metrics
reth-provider # tokio
reth-prune # tokio
reth-stages-api # reth-provider, reth-prune
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ reth-etl = { path = "crates/etl" }
reth-evm = { path = "crates/evm" }
reth-evm-ethereum = { path = "crates/ethereum/evm" }
reth-optimism-evm = { path = "crates/optimism/evm" }
reth-execution-errors = { path = "crates/evm/execution-errors" }
reth-execution-types = { path = "crates/evm/execution-types" }
reth-execution-errors = { path = "crates/evm/execution-errors", default-features = false }
reth-execution-types = { path = "crates/evm/execution-types", default-features = false }
reth-exex = { path = "crates/exex/exex" }
reth-exex-test-utils = { path = "crates/exex/test-utils" }
reth-exex-types = { path = "crates/exex/types" }
Expand Down Expand Up @@ -394,7 +394,7 @@ reth-primitives = { path = "crates/primitives", default-features = false }
reth-primitives-traits = { path = "crates/primitives-traits", default-features = false }
reth-provider = { path = "crates/storage/provider" }
reth-prune = { path = "crates/prune/prune" }
reth-prune-types = { path = "crates/prune/types" }
reth-prune-types = { path = "crates/prune/types", default-features = false }
reth-revm = { path = "crates/revm", default-features = false }
reth-rpc = { path = "crates/rpc/rpc" }
reth-rpc-api = { path = "crates/rpc/rpc-api" }
Expand All @@ -410,9 +410,9 @@ reth-stages = { path = "crates/stages/stages" }
reth-stages-api = { path = "crates/stages/api" }
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-static-file-types = { path = "crates/static-file/types", default-features = false }
reth-storage-api = { path = "crates/storage/storage-api" }
reth-storage-errors = { path = "crates/storage/errors" }
reth-storage-errors = { path = "crates/storage/errors", default-features = false }
reth-tasks = { path = "crates/tasks" }
reth-testing-utils = { path = "testing/testing-utils" }
reth-tokio-util = { path = "crates/tokio-util" }
Expand All @@ -436,7 +436,7 @@ alloy-chains = { version = "0.1.32", default-features = false }
alloy-dyn-abi = "0.8.20"
alloy-eip2124 = { version = "0.1.0", default-features = false }
alloy-primitives = { version = "0.8.20", default-features = false, features = ["map-foldhash"] }
alloy-rlp = { version = "0.3.10", default-features = false }
alloy-rlp = { version = "0.3.10", default-features = false, features = ["core-net"] }
alloy-sol-types = "0.8.20"
alloy-trie = { version = "0.7", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions crates/ethereum/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ std = [
"reth-primitives-traits/std",
"reth-chainspec/std",
"derive_more/std",
"reth-execution-types/std",
]
3 changes: 3 additions & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ std = [
"reth-ethereum-primitives/std",
"reth-chainspec/std",
"reth-consensus-common/std",
"reth-execution-errors/std",
"reth-storage-errors/std",
"reth-execution-types/std",
]
test-utils = [
"dep:parking_lot",
Expand Down
1 change: 1 addition & 0 deletions crates/evm/execution-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ std = [
"alloy-rlp/std",
"thiserror/std",
"nybbles/std",
"reth-storage-errors/std",
]
14 changes: 5 additions & 9 deletions crates/evm/execution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ repository.workspace = true
workspace = true

[dependencies]
reth-primitives.workspace = true
reth-ethereum-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-execution-errors.workspace = true
reth-trie-common = { workspace = true, optional = true }
reth-trie.workspace = true
reth-trie-common.workspace = true

revm.workspace = true

Expand All @@ -31,7 +30,6 @@ serde_with = { workspace = true, optional = true }
arbitrary.workspace = true
bincode.workspace = true
rand.workspace = true
reth-primitives = { workspace = true, features = ["arbitrary", "test-utils"] }
reth-ethereum-primitives.workspace = true

[features]
Expand All @@ -45,28 +43,26 @@ serde = [
"alloy-primitives/serde",
"reth-primitives-traits/serde",
"alloy-consensus/serde",
"reth-trie/serde",
"reth-trie-common?/serde",
"reth-trie-common/serde",
]
serde-bincode-compat = [
"serde",
"reth-trie-common/serde-bincode-compat",
"reth-primitives/serde-bincode-compat",
"reth-primitives-traits/serde-bincode-compat",
"serde_with",
"alloy-eips/serde-bincode-compat",
"alloy-consensus/serde-bincode-compat",
"reth-ethereum-primitives/serde-bincode-compat",
]
std = [
"reth-primitives/std",
"alloy-eips/std",
"alloy-primitives/std",
"revm/std",
"serde?/std",
"reth-primitives-traits/std",
"alloy-consensus/std",
"serde_with?/std",
"reth-trie-common?/std",
"reth-trie-common/std",
"reth-ethereum-primitives/std",
"reth-execution-errors/std",
]
51 changes: 20 additions & 31 deletions crates/evm/execution-types/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
use crate::ExecutionOutcome;
use alloc::{borrow::Cow, boxed::Box, collections::BTreeMap, vec::Vec};
use alloy_consensus::BlockHeader;
use alloy_consensus::{transaction::Recovered, BlockHeader};
use alloy_eips::{eip1898::ForkBlock, eip2718::Encodable2718, BlockNumHash};
use alloy_primitives::{Address, BlockHash, BlockNumber, TxHash};
use core::{fmt, ops::RangeInclusive};
use reth_execution_errors::{BlockExecutionError, InternalBlockExecutionError};
use reth_primitives::{
transaction::SignedTransactionIntoRecoveredExt, Recovered, RecoveredBlock, SealedHeader,
use reth_primitives_traits::{
transaction::signed::SignedTransactionIntoRecoveredExt, Block, BlockBody, NodePrimitives,
RecoveredBlock, SealedHeader, SignedTransaction,
};
use reth_primitives_traits::{Block, BlockBody, NodePrimitives, SignedTransaction};
use reth_trie::updates::TrieUpdates;
use reth_trie_common::updates::TrieUpdates;
use revm::db::BundleState;

/// A chain of blocks and their final state.
Expand All @@ -26,7 +26,7 @@ use revm::db::BundleState;
/// A chain of blocks should not be empty.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Chain<N: NodePrimitives = reth_primitives::EthPrimitives> {
pub struct Chain<N: NodePrimitives = reth_ethereum_primitives::EthPrimitives> {
/// All blocks in this chain.
blocks: BTreeMap<BlockNumber, RecoveredBlock<N::Block>>,
/// The outcome of block execution for this chain.
Expand Down Expand Up @@ -470,7 +470,7 @@ impl<B: Block> IntoIterator for ChainBlocks<'_, B> {

/// Used to hold receipts and their attachment.
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct BlockReceipts<T = reth_primitives::Receipt> {
pub struct BlockReceipts<T = reth_ethereum_primitives::Receipt> {
/// Block identifier
pub block: BlockNumHash,
/// Transaction identifier and receipt.
Expand Down Expand Up @@ -500,7 +500,7 @@ impl From<BlockHash> for ChainSplitTarget {

/// Result of a split chain.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ChainSplit<N: NodePrimitives = reth_primitives::EthPrimitives> {
pub enum ChainSplit<N: NodePrimitives = reth_ethereum_primitives::EthPrimitives> {
/// Chain is not split. Pending chain is returned.
/// Given block split is higher than last block.
/// Or in case of split by hash when hash is unknown.
Expand Down Expand Up @@ -529,8 +529,11 @@ pub(super) mod serde_bincode_compat {
use crate::ExecutionOutcome;
use alloc::borrow::Cow;
use alloy_primitives::BlockNumber;
use reth_primitives::{serde_bincode_compat::RecoveredBlock, EthPrimitives, NodePrimitives};
use reth_primitives_traits::{serde_bincode_compat::SerdeBincodeCompat, Block};
use reth_ethereum_primitives::EthPrimitives;
use reth_primitives_traits::{
serde_bincode_compat::{RecoveredBlock, SerdeBincodeCompat},
Block, NodePrimitives,
};
use reth_trie_common::serde_bincode_compat::updates::TrieUpdates;
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{DeserializeAs, SerializeAs};
Expand Down Expand Up @@ -568,7 +571,7 @@ pub(super) mod serde_bincode_compat {
'a,
B: reth_primitives_traits::Block<Header: SerdeBincodeCompat, Body: SerdeBincodeCompat>
+ 'static,
>(Cow<'a, BTreeMap<BlockNumber, reth_primitives::RecoveredBlock<B>>>);
>(Cow<'a, BTreeMap<BlockNumber, reth_primitives_traits::RecoveredBlock<B>>>);

impl<B> Serialize for RecoveredBlocks<'_, B>
where
Expand Down Expand Up @@ -666,7 +669,7 @@ pub(super) mod serde_bincode_compat {
use super::super::{serde_bincode_compat, Chain};
use arbitrary::Arbitrary;
use rand::Rng;
use reth_primitives::RecoveredBlock;
use reth_primitives_traits::RecoveredBlock;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;

Expand Down Expand Up @@ -705,23 +708,9 @@ mod tests {
use reth_ethereum_primitives::Receipt;
use revm::primitives::{AccountInfo, HashMap};

// TODO: this is temporary, until we fully switch over to `reth_ethereum_primitives` for the
// `Receipt` type in `EthPrimitives`.
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
struct TestPrimitives;

impl reth_primitives_traits::NodePrimitives for TestPrimitives {
type Block = reth_primitives::Block;
type BlockHeader = alloy_consensus::Header;
type BlockBody = reth_primitives::BlockBody;
type SignedTx = reth_primitives::TransactionSigned;
type Receipt = Receipt;
}

#[test]
fn chain_append() {
let block: RecoveredBlock<reth_primitives::Block> = Default::default();
let block: RecoveredBlock<reth_ethereum_primitives::Block> = Default::default();
let block1_hash = B256::new([0x01; 32]);
let block2_hash = B256::new([0x02; 32]);
let block3_hash = B256::new([0x03; 32]);
Expand Down Expand Up @@ -785,13 +774,13 @@ mod tests {
vec![],
);

let mut block1: RecoveredBlock<reth_primitives::Block> = Default::default();
let mut block1: RecoveredBlock<reth_ethereum_primitives::Block> = Default::default();
let block1_hash = B256::new([15; 32]);
block1.set_block_number(1);
block1.set_hash(block1_hash);
block1.push_sender(Address::new([4; 20]));

let mut block2: RecoveredBlock<reth_primitives::Block> = Default::default();
let mut block2: RecoveredBlock<reth_ethereum_primitives::Block> = Default::default();
let block2_hash = B256::new([16; 32]);
block2.set_block_number(2);
block2.set_hash(block2_hash);
Expand Down Expand Up @@ -852,7 +841,7 @@ mod tests {
#[test]
fn receipts_by_block_hash() {
// Create a default RecoveredBlock object
let block: RecoveredBlock<reth_primitives::Block> = Default::default();
let block: RecoveredBlock<reth_ethereum_primitives::Block> = Default::default();

// Define block hashes for block1 and block2
let block1_hash = B256::new([0x01; 32]);
Expand Down Expand Up @@ -896,7 +885,7 @@ mod tests {

// Create a Chain object with a BTreeMap of blocks mapped to their block numbers,
// including block1_hash and block2_hash, and the execution_outcome
let chain: Chain<TestPrimitives> = Chain {
let chain: Chain = Chain {
blocks: BTreeMap::from([(10, block1), (11, block2)]),
execution_outcome: execution_outcome.clone(),
..Default::default()
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloc::{vec, vec::Vec};
use alloy_eips::eip7685::Requests;
use alloy_primitives::{logs_bloom, map::HashMap, Address, BlockNumber, Bloom, Log, B256, U256};
use reth_primitives_traits::{Account, Bytecode, Receipt, StorageEntry};
use reth_trie::{HashedPostState, KeyHasher};
use reth_trie_common::{HashedPostState, KeyHasher};
use revm::{
db::{states::BundleState, BundleAccount},
primitives::AccountInfo,
Expand Down Expand Up @@ -33,7 +33,7 @@ impl ChangedAccount {
/// blocks, capturing the resulting state, receipts, and requests following the execution.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExecutionOutcome<T = reth_primitives::Receipt> {
pub struct ExecutionOutcome<T = reth_ethereum_primitives::Receipt> {
/// Bundle state with reverts.
pub bundle: BundleState,
/// The collection of receipts.
Expand Down Expand Up @@ -390,7 +390,7 @@ impl ExecutionOutcome {
pub fn ethereum_receipts_root(&self, block_number: BlockNumber) -> Option<B256> {
self.generic_receipts_root_slow(
block_number,
reth_primitives::Receipt::calculate_receipt_root_no_memo,
reth_ethereum_primitives::Receipt::calculate_receipt_root_no_memo,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/net/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ std = [
"alloy-consensus/std",
"derive_more/std",
"reth-network-peers/std",
"reth-storage-errors/std",
]
2 changes: 2 additions & 0 deletions crates/optimism/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ std = [
"reth-chainspec/std",
"reth-optimism-consensus/std",
"reth-consensus-common/std",
"reth-execution-errors/std",
"reth-execution-types/std",
]
optimism = [
"reth-execution-types/optimism",
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ std = [
"reth-ethereum-primitives/std",
"alloy-rlp/std",
"alloy-primitives/std",
"reth-static-file-types/std",
]
reth-codec = [
"std",
Expand Down
8 changes: 8 additions & 0 deletions crates/prune/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ test-fuzz.workspace = true
toml.workspace = true

[features]
default = ["std"]
std = [
"alloy-primitives/std",
"derive_more/std",
"serde?/std",
"serde_json/std",
"thiserror/std",
]
test-utils = [
"dep:arbitrary",
"reth-codecs?/test-utils",
Expand Down
3 changes: 2 additions & 1 deletion crates/prune/types/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::PrunedSegmentInfo;
use alloc::vec::Vec;
use alloy_primitives::BlockNumber;
use std::time::Duration;
use core::time::Duration;

/// An event emitted by a pruner.
#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down
Loading

0 comments on commit cfb91e9

Please sign in to comment.