From 3b0ad9262c9f3a73580fa3a471f304d690cafefb Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 17 Dec 2024 20:26:12 +0100 Subject: [PATCH] chore: remove `no-std` support (#69) * fix: use `OnceLock` for Sync reqs on `BlockOutput` * chore: remove no-std support (#70) * chore: remove no-std action * chore: remove no std support --- .github/workflows/rust-ci.yml | 18 +----------------- Cargo.toml | 17 +++++++---------- src/connect.rs | 2 +- src/db/sync_state.rs | 6 ++++-- src/driver/alloy.rs | 3 --- src/driver/mod.rs | 1 - src/evm.rs | 2 +- src/fill/zenith.rs | 3 --- src/journal/coder.rs | 18 +++++++----------- src/journal/index.rs | 2 +- src/lib.rs | 6 +----- src/lifecycle/output.rs | 5 ++--- src/system/eip6110.rs | 2 -- src/test_utils.rs | 2 -- 14 files changed, 25 insertions(+), 62 deletions(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index eb17d8a..06a8226 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -11,20 +11,4 @@ env: jobs: rust-base: - uses: init4tech/actions/.github/workflows/rust-base.yml@main - - test-no-features: - name: Test Suite (no default features) - runs-on: - group: init4-runners - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - name: Run tests - env: - CARGO_NET_GIT_FETCH_WITH_CLI: true - run: | - cargo test --no-default-features \ No newline at end of file + uses: init4tech/actions/.github/workflows/rust-base.yml@main \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 972d0cc..ea7a155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,16 +27,16 @@ option-if-let-else = "warn" redundant-clone = "warn" [dependencies] -alloy-rlp = { version = "0.3.10", default-features = false } +alloy-rlp = { version = "0.3.10", default-features = false, features = ["std"]} -alloy-primitives = { version = "0.8.11", default-features = false } -alloy-sol-types = { version = "0.8.11", default-features = false } +alloy-primitives = { version = "0.8.11", default-features = false, features = ["std"]} +alloy-sol-types = { version = "0.8.11", default-features = false, features = ["std"]} -alloy = { version = "=0.7.3", default-features = false, features = ["consensus", "rpc-types-mev", "eips", "k256"] } +alloy = { version = "=0.7.3", default-features = false, features = ["consensus", "rpc-types-mev", "eips", "k256", "std"] } -revm = { version = "18.0.0", default-features = false } +revm = { version = "18.0.0", default-features = false, features = ["std"] } -zenith-types = { version = "0.10", optional = true } +zenith-types = { version = "0.11" } dashmap = { version = "6.1.0", optional = true } @@ -57,7 +57,6 @@ tokio = { version = "1.39", features = ["macros", "rt-multi-thread"] } [features] default = [ - "std", "concurrent-db", "revm/std", "revm/c-kzg", @@ -66,9 +65,7 @@ default = [ "revm/secp256k1", ] -std = ["revm/std", "alloy/std", "alloy-rlp/std", "alloy-primitives/std", "alloy-sol-types/std", "dep:zenith-types"] - -concurrent-db = ["std", "dep:dashmap"] +concurrent-db = ["dep:dashmap"] test-utils = ["revm/test-utils", "revm/std", "revm/serde-json", "revm/alloydb"] diff --git a/src/connect.rs b/src/connect.rs index a5291f4..32a5292 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -1,9 +1,9 @@ -use alloc::format; use core::convert::Infallible; use revm::{ primitives::{EVMError, ResultAndState}, Database, DatabaseCommit, }; +use std::format; use crate::{ Block, Cfg, EvmErrored, EvmNeedsBlock, EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, Tx, diff --git a/src/db/sync_state.rs b/src/db/sync_state.rs index 5b25bd7..7157446 100644 --- a/src/db/sync_state.rs +++ b/src/db/sync_state.rs @@ -1,5 +1,4 @@ use crate::db::ConcurrentCacheState; -use alloc::{collections::BTreeMap, vec::Vec}; use alloy_primitives::{Address, B256, U256}; use dashmap::mapref::one::RefMut; use revm::{ @@ -10,7 +9,10 @@ use revm::{ primitives::{Account, AccountInfo, Bytecode}, Database, DatabaseCommit, DatabaseRef, TransitionAccount, TransitionState, }; -use std::{collections::hash_map, sync::RwLock}; +use std::{ + collections::{hash_map, BTreeMap}, + sync::RwLock, +}; /// State of the blockchain. /// diff --git a/src/driver/alloy.rs b/src/driver/alloy.rs index c164d6f..c671872 100644 --- a/src/driver/alloy.rs +++ b/src/driver/alloy.rs @@ -1,9 +1,6 @@ -#![cfg(feature = "std")] - use crate::{ trevm_bail, trevm_ensure, unwrap_or_trevm_err, Block, BundleDriver, DriveBundleResult, }; -use alloc::vec::Vec; use alloy::{ consensus::{Transaction, TxEip4844Variant, TxEnvelope}, eips::{eip2718::Decodable2718, BlockNumberOrTag}, diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 1749864..1978a87 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -1,5 +1,4 @@ mod alloy; -#[cfg(feature = "std")] pub use alloy::{BundleError, BundleProcessor}; mod block; diff --git a/src/evm.rs b/src/evm.rs index 3fb4127..f6e605b 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -4,7 +4,6 @@ use crate::{ EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, HasBlock, HasCfg, HasTx, NeedsCfg, NeedsTx, TransactedState, Tx, }; -use alloc::{boxed::Box, fmt}; use alloy_primitives::{Address, Bytes, U256}; use core::convert::Infallible; use revm::{ @@ -15,6 +14,7 @@ use revm::{ }, Database, DatabaseCommit, DatabaseRef, Evm, }; +use std::fmt; /// Trevm provides a type-safe interface to the EVM, using the typestate pattern. /// diff --git a/src/fill/zenith.rs b/src/fill/zenith.rs index c1bd7c6..8ceda30 100644 --- a/src/fill/zenith.rs +++ b/src/fill/zenith.rs @@ -1,7 +1,4 @@ -#![cfg(feature = "std")] - use crate::Tx; -use alloc::vec; use alloy_primitives::{Address, U256}; use alloy_sol_types::SolCall; use revm::primitives::{TransactTo, TxEnv}; diff --git a/src/journal/coder.rs b/src/journal/coder.rs index 0967cd3..2261028 100644 --- a/src/journal/coder.rs +++ b/src/journal/coder.rs @@ -1,11 +1,4 @@ use crate::journal::{AcctDiff, BundleStateIndex, InfoOutcome}; -use alloc::{ - borrow::{Cow, ToOwned}, - collections::BTreeMap, - fmt::Debug, - sync::Arc, - vec::Vec, -}; use alloy_primitives::{Address, Bytes, B256, U256}; use alloy_rlp::{Buf, BufMut}; use revm::{ @@ -14,8 +7,14 @@ use revm::{ eof::EofDecodeError, AccountInfo, Bytecode, Eip7702Bytecode, Eip7702DecodeError, Eof, }, }; +use std::{ + borrow::{Cow, ToOwned}, + collections::BTreeMap, + fmt::Debug, + sync::Arc, + vec::Vec, +}; -#[cfg(feature = "std")] use zenith_types::Zenith; type Result = core::result::Result; @@ -413,7 +412,6 @@ impl JournalEncode for BundleState { } } -#[cfg(feature = "std")] impl JournalEncode for Zenith::BlockHeader { fn serialized_size(&self) -> usize { ZENITH_HEADER_BYTES @@ -639,7 +637,6 @@ impl JournalDecode for BundleState { } } -#[cfg(feature = "std")] impl JournalDecode for Zenith::BlockHeader { fn decode(buf: &mut &[u8]) -> Result { Ok(Self { @@ -655,7 +652,6 @@ impl JournalDecode for Zenith::BlockHeader { #[cfg(test)] mod test { use super::*; - use alloc::vec; fn roundtrip(expected: &T) { let enc = JournalEncode::encoded(expected); diff --git a/src/journal/index.rs b/src/journal/index.rs index ada18c2..02a4ab9 100644 --- a/src/journal/index.rs +++ b/src/journal/index.rs @@ -1,9 +1,9 @@ -use alloc::{borrow::Cow, collections::BTreeMap}; use alloy_primitives::{Address, Sign, B256, I256, U256}; use revm::{ db::{states::StorageSlot, AccountStatus, BundleAccount, BundleState}, primitives::{AccountInfo, Bytecode, HashMap}, }; +use std::{borrow::Cow, collections::BTreeMap}; /// Outcome of an account info after block execution. /// diff --git a/src/lib.rs b/src/lib.rs index 689a7c0..6bd4824 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -359,9 +359,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![deny(unused_must_use, rust_2018_idioms)] #![warn(missing_docs, missing_copy_implementations, missing_debug_implementations)] -#![cfg_attr(not(feature = "std"), no_std)] - -extern crate alloc; mod connect; pub use connect::{DbConnect, EvmFactory}; @@ -375,7 +372,7 @@ pub use driver::{ BlockDriver, BundleDriver, ChainDriver, DriveBlockResult, DriveBundleResult, DriveChainResult, RunTxResult, }; -#[cfg(feature = "std")] + pub use driver::{BundleError, BundleProcessor}; mod evm; @@ -387,7 +384,6 @@ pub use ext::EvmExtUnchecked; mod fill; pub use fill::{Block, Cfg, DisableGasChecks, DisableNonceCheck, NoopBlock, NoopCfg, Tx}; -#[cfg(feature = "std")] pub mod journal; mod lifecycle; diff --git a/src/lifecycle/output.rs b/src/lifecycle/output.rs index aa55fd6..23807e2 100644 --- a/src/lifecycle/output.rs +++ b/src/lifecycle/output.rs @@ -1,7 +1,6 @@ -use alloc::vec::Vec; use alloy::consensus::{ReceiptEnvelope, TxReceipt}; use alloy_primitives::{Address, Bloom, Bytes, Log}; -use core::cell::OnceCell; +use std::sync::OnceLock; /// Information externalized during block execution. /// @@ -16,7 +15,7 @@ pub struct BlockOutput { senders: Vec
, /// The logs bloom of the block. - bloom: OnceCell, + bloom: OnceLock, } impl Default for BlockOutput { diff --git a/src/system/eip6110.rs b/src/system/eip6110.rs index 7144764..c63fe36 100644 --- a/src/system/eip6110.rs +++ b/src/system/eip6110.rs @@ -1,4 +1,3 @@ -use alloc::vec::Vec; use alloy::consensus::ReceiptEnvelope; use alloy_primitives::{Bytes, Log}; use alloy_rlp::BufMut; @@ -147,7 +146,6 @@ where #[cfg(test)] mod tests { use super::*; - use alloc::vec; use alloy::consensus::{Receipt, ReceiptEnvelope}; use alloy_primitives::bytes; diff --git a/src/test_utils.rs b/src/test_utils.rs index 9e8d38e..e31451e 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -7,7 +7,6 @@ use revm::{ EvmBuilder, GetInspector, }; -#[cfg(feature = "std")] use revm::inspectors::TracerEip3155; pub use revm::test_utils as revm_test_utils; @@ -115,7 +114,6 @@ pub fn test_state_trevm() -> EvmNeedsCfg<'static, (), State> { /// Make a new [`Trevm`] with an in-memory database and a tracer inspector. /// The tracer will print all EVM instructions to stdout. -#[cfg(feature = "std")] pub fn test_trevm_tracing() -> EvmNeedsCfg<'static, TracerEip3155, CacheDB> { test_trevm_with_inspector(TracerEip3155::new(Box::new(std::io::stdout()))) }