From b2276e44f55dbd459cf8f5552d3b3474a3089fdd Mon Sep 17 00:00:00 2001 From: frostburn Date: Mon, 22 Jul 2024 12:23:32 -0700 Subject: [PATCH] no_std support for reth-revm and fixed tests (#9634) Co-authored-by: Matthias Seitz --- crates/revm/src/batch.rs | 11 +++++++++-- crates/revm/src/state_change.rs | 10 +--------- crates/revm/src/test_utils.rs | 5 ++++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/revm/src/batch.rs b/crates/revm/src/batch.rs index 02ffba017b..400a3044e1 100644 --- a/crates/revm/src/batch.rs +++ b/crates/revm/src/batch.rs @@ -1,12 +1,14 @@ //! Helper for handling execution of multiple blocks. -use crate::{precompile::Address, primitives::alloy_primitives::BlockNumber}; +use crate::{ + precompile::{Address, HashSet}, + primitives::alloy_primitives::BlockNumber, +}; use core::time::Duration; use reth_execution_errors::BlockExecutionError; use reth_primitives::{Receipt, Receipts, Request, Requests}; use reth_prune_types::{PruneMode, PruneModes, PruneSegmentError, MINIMUM_PRUNING_DISTANCE}; use revm::db::states::bundle_state::BundleRetention; -use std::collections::HashSet; use tracing::debug; #[cfg(not(feature = "std"))] @@ -216,7 +218,12 @@ mod tests { use super::*; use reth_primitives::{Address, Log, Receipt}; use reth_prune_types::{PruneMode, ReceiptsLogPruneConfig}; + #[cfg(feature = "std")] use std::collections::BTreeMap; + #[cfg(not(feature = "std"))] + extern crate alloc; + #[cfg(not(feature = "std"))] + use alloc::collections::BTreeMap; #[test] fn test_save_receipts_empty() { diff --git a/crates/revm/src/state_change.rs b/crates/revm/src/state_change.rs index f0ca125577..b8bd293de0 100644 --- a/crates/revm/src/state_change.rs +++ b/crates/revm/src/state_change.rs @@ -1,3 +1,4 @@ +use crate::precompile::HashMap; use alloy_eips::eip2935::{HISTORY_STORAGE_ADDRESS, HISTORY_STORAGE_CODE}; use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_consensus_common::calc; @@ -9,15 +10,6 @@ use revm::{ Database, DatabaseCommit, }; -// reuse revm's hashbrown implementation for no-std -#[cfg(not(feature = "std"))] -use crate::precompile::HashMap; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, string::ToString, vec::Vec}; - -#[cfg(feature = "std")] -use std::collections::HashMap; - /// Collect all balance changes at the end of the block. /// /// Balance changes might include the block reward, uncle rewards, withdrawals, or irregular diff --git a/crates/revm/src/test_utils.rs b/crates/revm/src/test_utils.rs index 09c66d588c..b55cd3fd01 100644 --- a/crates/revm/src/test_utils.rs +++ b/crates/revm/src/test_utils.rs @@ -1,3 +1,4 @@ +use crate::precompile::HashMap; use reth_primitives::{ keccak256, Account, Address, BlockNumber, Bytecode, Bytes, StorageKey, B256, U256, }; @@ -6,7 +7,9 @@ use reth_storage_api::{ }; use reth_storage_errors::provider::ProviderResult; use reth_trie::{updates::TrieUpdates, AccountProof, HashedPostState}; -use std::collections::HashMap; + +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; /// Mock state for testing #[derive(Debug, Default, Clone, Eq, PartialEq)]