diff --git a/Cargo.lock b/Cargo.lock index cfd76f2b..51645899 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1248,6 +1248,7 @@ name = "cli" version = "0.6.0" dependencies = [ "alloy", + "anyhow", "clap", "client", "common", @@ -1255,7 +1256,6 @@ dependencies = [ "consensus", "ctrlc", "dirs", - "eyre", "futures", "tokio", "tracing", @@ -1267,11 +1267,11 @@ name = "client" version = "0.6.0" dependencies = [ "alloy", + "anyhow", "common", "config", "consensus", "execution", - "eyre", "futures", "gloo-timers 0.3.0", "hex", @@ -1302,12 +1302,13 @@ name = "common" version = "0.6.0" dependencies = [ "alloy", - "eyre", + "anyhow", "hex", "serde", "serde_json", "superstruct", "thiserror", + "thiserror-no-std", "tracing", "zduny-wasm-timer", ] @@ -1317,10 +1318,10 @@ name = "config" version = "0.6.0" dependencies = [ "alloy", + "anyhow", "common", "consensus-core", "dirs", - "eyre", "figment", "futures", "hex", @@ -1339,12 +1340,12 @@ name = "consensus" version = "0.6.0" dependencies = [ "alloy", + "anyhow", "async-trait", "chrono", "common", "config", "consensus-core", - "eyre", "futures", "getrandom 0.2.15", "hex", @@ -1367,16 +1368,17 @@ dependencies = [ name = "consensus-core" version = "0.6.0" dependencies = [ - "alloy", + "alloy-primitives", + "anyhow", "bls12_381", "ethereum_ssz 0.6.0", "ethereum_ssz_derive 0.6.0", - "eyre", + "getrandom 0.2.15", "serde", "sha2 0.9.9", "ssz_types", "superstruct", - "thiserror", + "thiserror-no-std", "tracing", "tree_hash", "tree_hash_derive", @@ -2055,10 +2057,10 @@ name = "execution" version = "0.6.0" dependencies = [ "alloy", + "anyhow", "async-trait", "common", "consensus", - "eyre", "futures", "hex", "openssl", @@ -2073,16 +2075,6 @@ dependencies = [ "wasm-bindgen-futures", ] -[[package]] -name = "eyre" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" -dependencies = [ - "indenter", - "once_cell", -] - [[package]] name = "fastrand" version = "2.1.0" @@ -2611,7 +2603,6 @@ dependencies = [ "dirs", "dotenv", "execution", - "eyre", "hex", "plotters", "pretty_assertions", @@ -2629,13 +2620,13 @@ name = "helios-ts" version = "0.1.0" dependencies = [ "alloy", + "anyhow", "client", "common", "config", "consensus", "console_error_panic_hook", "execution", - "eyre", "hex", "serde", "serde-wasm-bindgen", @@ -2984,12 +2975,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - [[package]] name = "indexmap" version = "1.9.3" @@ -5250,6 +5235,26 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + [[package]] name = "thread_local" version = "1.1.8" diff --git a/Cargo.toml b/Cargo.toml index 670916d4..d100bf36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,8 @@ tree_hash = "0.7.0" sha2 = "0.9" bls12_381 = { version = "0.8.0", features = ["experimental"] } +anyhow = { version = "1.0", default-features = false } + # execution alloy = { version = "0.2.1", features = [ "rpc-types", @@ -43,14 +45,14 @@ alloy = { version = "0.2.1", features = [ "sol-types", "network", "ssz", -]} +] } revm = { version = "12.1.0", default-features = false, features = [ "std", "serde", "optional_block_gas_limit", "optional_eip3607", "optional_no_base_fee", -]} +] } triehash-ethereum = { git = "https://github.com/openethereum/parity-ethereum", rev = "55c90d4016505317034e3e98f699af07f5404b63" } # async/futures @@ -60,16 +62,16 @@ tokio = { version = "1", features = ["rt", "sync", "macros"] } # io reqwest = { version = "0.12.4", features = ["json"] } -serde = { version = "1.0.143", features = ["derive"] } +serde = { version = "1.0.143", features = ["derive"], default-features = false } serde_json = "1.0.85" # misc -eyre = "0.6.8" hex = "0.4.3" toml = "0.5.9" tracing = "0.1.37" chrono = "0.4.23" -thiserror = "1.0.37" +thiserror = { version = "1.0.37", default-features = false } +thiserror-no-std = "2.0.2" superstruct = "0.7.0" openssl = { version = "0.10", features = ["vendored"] } zduny-wasm-timer = "0.2.8" @@ -96,7 +98,6 @@ serde = { version = "1.0.154", features = ["derive"] } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] alloy = { version = "0.2.1", features = ["full"] } tokio = { version = "1", features = ["full"] } -eyre = "0.6.8" dirs = "5.0.1" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing = "0.1.37" diff --git a/README.md b/README.md index 79041a35..79304ecb 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ use std::{path::PathBuf, str::FromStr, env}; use helios::{client::ClientBuilder, config::networks::Network, types::BlockTag, prelude::*}; use alloy::primitives::{utils, Address}; -use eyre::Result; +use anyhow::Result; #[tokio::main] async fn main() -> Result<()> { @@ -136,7 +136,7 @@ Below we demonstrate fetching checkpoints from the community-maintained list of > This is a community-maintained list and thus no security guarantees are provided. Attacks on your light client can occur if malicious checkpoints are set in the list. Please use the explicit `checkpoint` flag, environment variable, or config setting with an updated, and verified checkpoint. ```rust -use eyre::Result; +use anyhow::Result; use helios::config::{checkpoints, networks}; #[tokio::main] diff --git a/benches/harness.rs b/benches/harness.rs index 7586300a..6a671508 100644 --- a/benches/harness.rs +++ b/benches/harness.rs @@ -14,7 +14,7 @@ use std::{path::PathBuf, str::FromStr}; /// The `build` method will fetch a list of [CheckpointFallbackService](config::CheckpointFallbackService)s from a community-mainained list by ethPandaOps. /// This list is NOT guaranteed to be secure, but is provided in good faith. /// The raw list can be found here: https://github.com/ethpandaops/checkpoint-sync-health-checks/blob/master/_data/endpoints.yaml -pub async fn fetch_mainnet_checkpoint() -> eyre::Result { +pub async fn fetch_mainnet_checkpoint() -> anyhow::Result { let cf = config::CheckpointFallback::new().build().await.unwrap(); cf.fetch_latest_checkpoint(&networks::Network::MAINNET) .await @@ -26,11 +26,11 @@ pub async fn fetch_mainnet_checkpoint() -> eyre::Result { /// The client is parameterized with a [FileDB](client::FileDB). /// It will also use the environment variable `MAINNET_EXECUTION_RPC` to connect to a mainnet node. /// The client will use `https://www.lightclientdata.org` as the consensus RPC. -pub fn construct_mainnet_client(rt: &tokio::runtime::Runtime) -> eyre::Result> { +pub fn construct_mainnet_client(rt: &tokio::runtime::Runtime) -> anyhow::Result> { rt.block_on(inner_construct_mainnet_client()) } -pub async fn inner_construct_mainnet_client() -> eyre::Result> { +pub async fn inner_construct_mainnet_client() -> anyhow::Result> { let benchmark_rpc_url = std::env::var("MAINNET_EXECUTION_RPC")?; let mut client = client::ClientBuilder::new() .network(networks::Network::MAINNET) @@ -45,7 +45,7 @@ pub async fn inner_construct_mainnet_client() -> eyre::Result> { pub async fn construct_mainnet_client_with_checkpoint( checkpoint: B256, -) -> eyre::Result> { +) -> anyhow::Result> { let benchmark_rpc_url = std::env::var("MAINNET_EXECUTION_RPC")?; let mut client = client::ClientBuilder::new() .network(networks::Network::MAINNET) @@ -75,7 +75,7 @@ pub fn construct_runtime() -> tokio::runtime::Runtime { /// The client is parameterized with a [FileDB](client::FileDB). /// It will also use the environment variable `GOERLI_EXECUTION_RPC` to connect to a mainnet node. /// The client will use `http://testing.prater.beacon-api.nimbus.team` as the consensus RPC. -pub fn construct_goerli_client(rt: &tokio::runtime::Runtime) -> eyre::Result> { +pub fn construct_goerli_client(rt: &tokio::runtime::Runtime) -> anyhow::Result> { rt.block_on(async { let benchmark_rpc_url = std::env::var("GOERLI_EXECUTION_RPC")?; let mut client = client::ClientBuilder::new() @@ -94,7 +94,7 @@ pub fn get_balance( rt: &tokio::runtime::Runtime, client: Client, address: &str, -) -> eyre::Result { +) -> anyhow::Result { rt.block_on(async { let block = BlockTag::Latest; let address = Address::from_str(address)?; diff --git a/cli/Cargo.toml b/cli/Cargo.toml index f369922f..7cd5d785 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -9,7 +9,7 @@ path = "src/main.rs" [dependencies] tokio.workspace = true -eyre.workspace = true +anyhow.workspace = true tracing.workspace = true futures.workspace = true alloy.workspace = true diff --git a/cli/src/main.rs b/cli/src/main.rs index b7b83f72..399e5d51 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -9,7 +9,7 @@ use std::{ use alloy::primitives::B256; use clap::Parser; use dirs::home_dir; -use eyre::Result; +use anyhow::Result; use futures::executor::block_on; use tracing::{error, info}; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; diff --git a/client/Cargo.toml b/client/Cargo.toml index 25f0eb42..31967f48 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] alloy.workspace = true -eyre.workspace = true +anyhow.workspace = true serde.workspace = true hex.workspace = true futures.workspace = true diff --git a/client/src/client.rs b/client/src/client.rs index edea7ffd..e9556347 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -7,7 +7,7 @@ use alloy::primitives::{Address, Bytes, B256, U256}; use alloy::rpc::types::{ Filter, Log, SyncStatus, Transaction, TransactionReceipt, TransactionRequest, }; -use eyre::{eyre, Result}; +use anyhow::{anyhow, Result}; use tracing::{info, warn}; use zduny_wasm_timer::Delay; @@ -112,7 +112,7 @@ impl ClientBuilder { let config = self .config .as_ref() - .ok_or(eyre!("missing network config"))?; + .ok_or(anyhow!("missing network config"))?; config.to_base_config() }; diff --git a/client/src/errors.rs b/client/src/errors.rs index 18640050..8eaa0bac 100644 --- a/client/src/errors.rs +++ b/client/src/errors.rs @@ -1,4 +1,4 @@ -use eyre::Report; +use anyhow::Report; use thiserror::Error; use common::errors::BlockNotFoundError; diff --git a/client/src/node.rs b/client/src/node.rs index a835838d..9f98f627 100644 --- a/client/src/node.rs +++ b/client/src/node.rs @@ -4,7 +4,7 @@ use alloy::primitives::{Address, Bytes, B256, U256}; use alloy::rpc::types::{ Filter, Log, SyncInfo, SyncStatus, Transaction, TransactionReceipt, TransactionRequest, }; -use eyre::{eyre, Result}; +use anyhow::{anyhow, Result}; use zduny_wasm_timer::{SystemTime, UNIX_EPOCH}; use common::types::{Block, BlockTag}; @@ -119,7 +119,7 @@ impl Node { let value = account.slots.get(&slot); match value { Some(value) => Ok(*value), - None => Err(eyre!("slot not found")), + None => Err(anyhow!("slot not found")), } } diff --git a/client/src/rpc.rs b/client/src/rpc.rs index c87f14ce..fa1981dc 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -5,7 +5,7 @@ use alloy::primitives::{Address, Bytes, B256, U256, U64}; use alloy::rpc::types::{ Filter, Log, SyncStatus, Transaction, TransactionReceipt, TransactionRequest, }; -use eyre::Result; +use anyhow::Result; use jsonrpsee::{ core::{async_trait, server::Methods, Error}, proc_macros::rpc, diff --git a/common/Cargo.toml b/common/Cargo.toml index 44ca75eb..1d5545ec 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,11 +5,12 @@ edition = "2021" [dependencies] alloy = { version = "0.2.1", features = ["rpc-types"] } -eyre.workspace = true +anyhow.workspace = true serde.workspace = true hex.workspace = true serde_json.workspace = true superstruct.workspace = true thiserror.workspace = true +thiserror-no-std.workspace = true tracing.workspace = true zduny-wasm-timer.workspace = true diff --git a/common/src/errors.rs b/common/src/errors.rs index 5ab5c971..c961b90b 100644 --- a/common/src/errors.rs +++ b/common/src/errors.rs @@ -1,5 +1,6 @@ +use alloc::string::{String, ToString}; use alloy::primitives::B256; -use thiserror::Error; +use thiserror_no_std::Error; use crate::types::BlockTag; @@ -42,3 +43,13 @@ impl RpcError { } } } + +impl From> for anyhow::Error { + fn from(error: RpcError) -> Self { + anyhow::anyhow!( + "RPC error in method '{}': {}", + error.method, + error.error.to_string() + ) + } +} diff --git a/common/src/lib.rs b/common/src/lib.rs index 422d6694..99a3a4a7 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,2 +1,6 @@ +#![no_std] + +extern crate alloc; + pub mod errors; pub mod types; diff --git a/common/src/types.rs b/common/src/types.rs index cd349f61..2b5de877 100644 --- a/common/src/types.rs +++ b/common/src/types.rs @@ -1,4 +1,7 @@ -use std::fmt::Display; +use core::fmt::Display; + +use alloc::string::{String, ToString}; +use alloc::vec::Vec; use alloy::primitives::{Address, Bytes, B256, U256, U64}; use alloy::rpc::types::Transaction; @@ -54,7 +57,7 @@ impl Transactions { } impl Serialize for Transactions { - fn serialize(&self, s: S) -> std::result::Result + fn serialize(&self, s: S) -> core::result::Result where S: serde::Serializer, { @@ -87,7 +90,7 @@ pub enum BlockTag { } impl Display for BlockTag { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let formatted = match self { Self::Latest => "latest".to_string(), Self::Finalized => "finalized".to_string(), diff --git a/config/Cargo.toml b/config/Cargo.toml index 29360404..72ed17d7 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] alloy.workspace = true -eyre.workspace = true +anyhow.workspace = true serde.workspace = true hex.workspace = true thiserror.workspace = true diff --git a/config/src/checkpoints.rs b/config/src/checkpoints.rs index f8e659fc..6a9c85ba 100644 --- a/config/src/checkpoints.rs +++ b/config/src/checkpoints.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use alloy::primitives::B256; -use eyre::Result; +use anyhow::Result; use retri::{retry, BackoffSettings}; use serde::{ de::{self, Error}, @@ -81,7 +81,7 @@ pub struct CheckpointFallback { async fn get(req: &str) -> Result { retry( - || async { Ok::<_, eyre::Report>(reqwest::get(req).await?) }, + || async { Ok::<_, anyhow::Error>(reqwest::get(req).await?) }, BackoffSettings::default(), ) .await @@ -104,7 +104,7 @@ impl CheckpointFallback { /// Build the checkpoint fallback service from the community-maintained list by [ethPandaOps](https://github.com/ethpandaops). /// /// The list is defined in [ethPandaOps/checkpoint-fallback-service](https://github.com/ethpandaops/checkpoint-sync-health-checks/blob/master/_data/endpoints.yaml). - pub async fn build(mut self) -> eyre::Result { + pub async fn build(mut self) -> anyhow::Result { // Fetch the services let res = get(CHECKPOINT_SYNC_SERVICES_LIST).await?; let yaml = res.text().await?; @@ -119,7 +119,7 @@ impl CheckpointFallback { let service_list = list .get(network.to_string().to_lowercase()) .ok_or_else(|| { - eyre::eyre!(format!("missing {network} fallback checkpoint services")) + anyhow::anyhow!(format!("missing {network} fallback checkpoint services")) })?; let parsed: Vec = serde_yaml::from_value(service_list.clone())?; @@ -134,7 +134,7 @@ impl CheckpointFallback { pub async fn fetch_latest_checkpoint( &self, network: &crate::networks::Network, - ) -> eyre::Result { + ) -> anyhow::Result { let services = &self.get_healthy_fallback_services(network); Self::fetch_latest_checkpoint_from_services(&services[..]).await } @@ -149,7 +149,7 @@ impl CheckpointFallback { /// Fetch the latest checkpoint from a list of checkpoint fallback services. pub async fn fetch_latest_checkpoint_from_services( services: &[CheckpointFallbackService], - ) -> eyre::Result { + ) -> anyhow::Result { // Iterate over all mainnet checkpoint sync services and get the latest checkpoint slot for each. let tasks: Vec<_> = services .iter() @@ -158,7 +158,7 @@ impl CheckpointFallback { match Self::query_service(&service.endpoint).await { Some(raw) => { if raw.data.slots.is_empty() { - return Err(eyre::eyre!("no slots")); + return Err(anyhow::anyhow!("no slots")); } let slot = raw @@ -166,11 +166,11 @@ impl CheckpointFallback { .slots .iter() .find(|s| s.block_root.is_some()) - .ok_or(eyre::eyre!("no valid slots"))?; + .ok_or(anyhow::anyhow!("no valid slots"))?; Ok(slot.clone()) } - None => Err(eyre::eyre!("failed to query service")), + None => Err(anyhow::anyhow!("failed to query service")), } }) .collect(); @@ -186,7 +186,7 @@ impl CheckpointFallback { .collect::>(); // Get the max epoch - let max_epoch_slot = slots.iter().max_by_key(|x| x.epoch).ok_or(eyre::eyre!( + let max_epoch_slot = slots.iter().max_by_key(|x| x.epoch).ok_or(anyhow::anyhow!( "Failed to find max epoch from checkpoint slots" ))?; let max_epoch = max_epoch_slot.epoch; @@ -209,19 +209,19 @@ impl CheckpointFallback { let most_common = m.into_iter().max_by_key(|(_, v)| *v).map(|(k, _)| k); // Return the most commonly verified checkpoint for the latest epoch. - most_common.ok_or_else(|| eyre::eyre!("No checkpoint found")) + most_common.ok_or_else(|| anyhow::anyhow!("No checkpoint found")) } /// Associated function to fetch the latest checkpoint from a specific checkpoint sync fallback /// service api url. - pub async fn fetch_checkpoint_from_api(url: &str) -> eyre::Result { + pub async fn fetch_checkpoint_from_api(url: &str) -> anyhow::Result { // Fetch the url let constructed_url = Self::construct_url(url); let res = get(&constructed_url).await?; let raw: RawSlotResponse = res.json().await?; let slot = raw.data.slots[0].clone(); slot.block_root - .ok_or_else(|| eyre::eyre!("Checkpoint not in returned slot")) + .ok_or_else(|| anyhow::anyhow!("Checkpoint not in returned slot")) } /// Constructs the checkpoint fallback service url for fetching a slot. diff --git a/config/src/networks.rs b/config/src/networks.rs index e103e032..f9af7f7d 100644 --- a/config/src/networks.rs +++ b/config/src/networks.rs @@ -4,9 +4,9 @@ use std::path::PathBuf; use std::str::FromStr; use alloy::primitives::{b256, fixed_bytes}; +use anyhow::Result; #[cfg(not(target_arch = "wasm32"))] use dirs::home_dir; -use eyre::Result; use serde::{Deserialize, Serialize}; use strum::EnumIter; @@ -26,7 +26,7 @@ pub enum Network { } impl FromStr for Network { - type Err = eyre::Report; + type Err = anyhow::Error; fn from_str(s: &str) -> Result { match s { @@ -34,7 +34,7 @@ impl FromStr for Network { "goerli" => Ok(Self::GOERLI), "sepolia" => Ok(Self::SEPOLIA), "holesky" => Ok(Self::HOLESKY), - _ => Err(eyre::eyre!("network not recognized")), + _ => Err(anyhow::anyhow!("network not recognized")), } } } @@ -68,7 +68,7 @@ impl Network { 5 => Ok(Network::GOERLI), 11155111 => Ok(Network::SEPOLIA), 17000 => Ok(Network::HOLESKY), - _ => Err(eyre::eyre!("chain id not known")), + _ => Err(anyhow::anyhow!("chain id not known")), } } } diff --git a/consensus-core/Cargo.toml b/consensus-core/Cargo.toml index 1273b86b..99782060 100644 --- a/consensus-core/Cargo.toml +++ b/consensus-core/Cargo.toml @@ -4,7 +4,7 @@ name = "consensus-core" edition = "2021" [dependencies] -alloy = { version = "0.2.1", features = ["consensus", "rpc-types", "ssz", "rlp", "k256"] } +alloy-primitives = { version = "0.7.7", default-features = false } bls12_381.workspace = true ssz_types.workspace = true ethereum_ssz_derive.workspace = true @@ -13,9 +13,10 @@ tree_hash_derive.workspace = true tree_hash.workspace = true typenum.workspace = true sha2.workspace = true -eyre.workspace = true +anyhow.workspace = true serde.workspace = true superstruct.workspace = true -thiserror.workspace = true +thiserror-no-std.workspace = true tracing.workspace = true zduny-wasm-timer.workspace = true +getrandom = { version = "0.2", features = ["js"] } diff --git a/consensus-core/src/consensus_core.rs b/consensus-core/src/consensus_core.rs index ed88a19b..b4de7891 100644 --- a/consensus-core/src/consensus_core.rs +++ b/consensus-core/src/consensus_core.rs @@ -1,7 +1,7 @@ -use std::cmp; +use core::cmp; -use alloy::primitives::B256; -use eyre::Result; +use alloy_primitives::B256; +use anyhow::Result; use ssz_types::BitVector; use tracing::{info, warn}; use tree_hash::TreeHash; @@ -283,7 +283,7 @@ fn verify_generic_update( pub fn expected_current_slot(now: SystemTime, genesis_time: u64) -> u64 { let now = now.duration_since(UNIX_EPOCH).unwrap(); - let since_genesis = now - std::time::Duration::from_secs(genesis_time); + let since_genesis = now - core::time::Duration::from_secs(genesis_time); since_genesis.as_secs() / 12 } diff --git a/consensus-core/src/errors.rs b/consensus-core/src/errors.rs index a99f96e1..e0bb9ab3 100644 --- a/consensus-core/src/errors.rs +++ b/consensus-core/src/errors.rs @@ -1,5 +1,12 @@ -use alloy::primitives::B256; -use thiserror::Error; +use alloc::string::ToString; +use alloy_primitives::B256; +use thiserror_no_std::Error; + +impl From for anyhow::Error { + fn from(error: ConsensusError) -> Self { + anyhow::Error::msg(error.to_string()) + } +} #[derive(Debug, Error)] pub enum ConsensusError { diff --git a/consensus-core/src/lib.rs b/consensus-core/src/lib.rs index 83e334a6..4da4aa99 100644 --- a/consensus-core/src/lib.rs +++ b/consensus-core/src/lib.rs @@ -1,3 +1,7 @@ +#![no_std] + +extern crate alloc; + pub mod errors; pub mod types; diff --git a/consensus-core/src/proof.rs b/consensus-core/src/proof.rs index a132cf2e..2745b659 100644 --- a/consensus-core/src/proof.rs +++ b/consensus-core/src/proof.rs @@ -1,4 +1,4 @@ -use alloy::primitives::B256; +use alloy_primitives::B256; use sha2::{Digest, Sha256}; use tree_hash::TreeHash; diff --git a/consensus-core/src/types/bls.rs b/consensus-core/src/types/bls.rs index de9e689f..b08ca658 100644 --- a/consensus-core/src/types/bls.rs +++ b/consensus-core/src/types/bls.rs @@ -1,22 +1,23 @@ +use alloc::vec::Vec; +use anyhow::{anyhow, Context, Result}; use bls12_381::{ hash_to_curve::{ExpandMsgXmd, HashToCurve}, multi_miller_loop, G1Affine, G1Projective, G2Affine, G2Prepared, G2Projective, Gt, Scalar, }; -use eyre::{eyre, Result}; use serde::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use tree_hash_derive::TreeHash; use super::bytes::ByteVector; -#[derive(Debug, Clone, Default, Serialize, Deserialize, Encode, Decode, TreeHash)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, Encode, TreeHash)] #[ssz(struct_behaviour = "transparent")] #[serde(transparent)] pub struct PublicKey { inner: ByteVector, } -#[derive(Debug, Clone, Default, Serialize, Deserialize, Encode, Decode, TreeHash)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, Encode, TreeHash)] #[ssz(struct_behaviour = "transparent")] #[serde(transparent)] pub struct Signature { @@ -26,12 +27,15 @@ pub struct Signature { impl PublicKey { fn point(&self) -> Result { let bytes = self.inner.inner.to_vec(); - let bytes = bytes.as_slice().try_into()?; + let bytes = bytes + .as_slice() + .try_into() + .map_err(|_| anyhow!("Invalid byte length"))?; let point_opt = G1Affine::from_compressed(bytes); if point_opt.is_some().into() { Ok(point_opt.unwrap()) } else { - Err(eyre!("invalid point")) + Err(anyhow!("invalid point")) } } } @@ -78,12 +82,16 @@ impl Signature { fn point(&self) -> Result { let bytes = self.inner.inner.to_vec(); - let bytes = bytes.as_slice().try_into()?; + let bytes = bytes + .as_slice() + .try_into() + .map_err(|_| anyhow!("Invalid byte length"))?; + let point_opt = G2Affine::from_compressed(bytes); if point_opt.is_some().into() { Ok(point_opt.unwrap()) } else { - Err(eyre!("invalid point")) + Err(anyhow!("invalid point")) } } } @@ -91,7 +99,7 @@ impl Signature { /// Aggregates multiple keys into one aggragate key fn aggregate(pks: &[PublicKey]) -> Result { if pks.is_empty() { - return Err(eyre!("no keys to aggregate")); + return Err(anyhow!("no keys to aggregate")); } let mut agg_key = G1Projective::identity(); diff --git a/consensus-core/src/types/bytes.rs b/consensus-core/src/types/bytes.rs index 13bf69ee..7d523aeb 100644 --- a/consensus-core/src/types/bytes.rs +++ b/consensus-core/src/types/bytes.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use serde::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use ssz_types::{ @@ -6,20 +7,20 @@ use ssz_types::{ }; use tree_hash_derive::TreeHash; -#[derive(Debug, Clone, Default, Encode, Decode, TreeHash)] +#[derive(Debug, Clone, Default, Encode, TreeHash)] #[ssz(struct_behaviour = "transparent")] pub struct ByteVector { pub inner: FixedVector, } -#[derive(Debug, Clone, Default, Encode, Decode, TreeHash)] +#[derive(Debug, Clone, Default, Encode, TreeHash)] #[ssz(struct_behaviour = "transparent")] pub struct ByteList { pub inner: VariableList, } impl<'de, N: typenum::Unsigned> serde::Deserialize<'de> for ByteVector { - fn deserialize(deserializer: D) -> std::result::Result + fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { @@ -38,7 +39,7 @@ impl Serialize for ByteVector { } impl<'de, N: typenum::Unsigned> Deserialize<'de> for ByteList { - fn deserialize(deserializer: D) -> std::result::Result + fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { diff --git a/consensus-core/src/types/mod.rs b/consensus-core/src/types/mod.rs index cef165cf..a1ecaf69 100644 --- a/consensus-core/src/types/mod.rs +++ b/consensus-core/src/types/mod.rs @@ -1,5 +1,6 @@ -use alloy::primitives::{Address, FixedBytes, B256, U256}; -use eyre::Result; +use alloc::vec::Vec; +use alloy_primitives::{Address, FixedBytes, B256, U256}; +use anyhow::Result; use serde::{Deserialize, Serialize}; use ssz_derive::Encode; use ssz_types::{serde_utils::quoted_u64_var_list, BitList, BitVector, FixedVector, VariableList}; diff --git a/consensus-core/src/types/serde_utils.rs b/consensus-core/src/types/serde_utils.rs index 2cdb8c2a..c10cefd5 100644 --- a/consensus-core/src/types/serde_utils.rs +++ b/consensus-core/src/types/serde_utils.rs @@ -1,4 +1,5 @@ pub mod u64 { + use alloc::string::{String, ToString}; use serde::{de::Error, Deserializer, Serializer}; pub fn serialize(value: &u64, serializer: S) -> Result @@ -18,7 +19,8 @@ pub mod u64 { } pub mod u256 { - use alloy::primitives::U256; + use alloc::string::String; + use alloy_primitives::U256; use serde::{de::Error, Deserializer}; pub fn deserialize<'de, D>(deserializer: D) -> Result diff --git a/consensus-core/src/utils.rs b/consensus-core/src/utils.rs index 08a4cd43..e7c426b9 100644 --- a/consensus-core/src/utils.rs +++ b/consensus-core/src/utils.rs @@ -1,5 +1,6 @@ -use alloy::primitives::B256; -use eyre::Result; +use alloc::vec::Vec; +use alloy_primitives::B256; +use anyhow::Result; use ssz_types::{BitVector, FixedVector}; use tree_hash::TreeHash; use tree_hash_derive::TreeHash; diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index ecae3fd7..7ad07830 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -19,7 +19,7 @@ serde_json.workspace = true #misc alloy.workspace = true -eyre.workspace = true +anyhow.workspace = true hex.workspace = true tracing.workspace = true chrono.workspace = true diff --git a/consensus/src/consensus.rs b/consensus/src/consensus.rs index 1afef8be..f2b93194 100644 --- a/consensus/src/consensus.rs +++ b/consensus/src/consensus.rs @@ -6,9 +6,9 @@ use alloy::consensus::{Transaction as TxTrait, TxEnvelope}; use alloy::primitives::{b256, B256, U256, U64}; use alloy::rlp::Decodable; use alloy::rpc::types::{Parity, Signature, Transaction}; +use anyhow::anyhow; +use anyhow::Result; use chrono::Duration; -use eyre::eyre; -use eyre::Result; use futures::future::join_all; use tracing::{debug, error, info, warn}; use tree_hash::TreeHash; @@ -361,7 +361,7 @@ impl Inner { .rpc .get_bootstrap(checkpoint) .await - .map_err(|err| eyre!("could not fetch bootstrap: {}", err))?; + .map_err(|err| anyhow!("could not fetch bootstrap: {}", err))?; let is_valid = self.is_valid_checkpoint(bootstrap.header.slot); diff --git a/consensus/src/database.rs b/consensus/src/database.rs index c0dd50d1..5451cb24 100644 --- a/consensus/src/database.rs +++ b/consensus/src/database.rs @@ -6,8 +6,8 @@ use std::{ }; use alloy::primitives::B256; +use anyhow::Result; use config::Config; -use eyre::Result; pub trait Database: Clone + Sync + Send + 'static { fn new(config: &Config) -> Result @@ -35,7 +35,7 @@ impl Database for FileDB { }); } - eyre::bail!("data dir not in config") + anyhow::bail!("data dir not in config") } fn save_checkpoint(&self, checkpoint: B256) -> Result<()> { diff --git a/consensus/src/rpc/mock_rpc.rs b/consensus/src/rpc/mock_rpc.rs index b0a56ff7..fe56c345 100644 --- a/consensus/src/rpc/mock_rpc.rs +++ b/consensus/src/rpc/mock_rpc.rs @@ -2,7 +2,7 @@ use std::{fs::read_to_string, path::PathBuf}; use alloy::primitives::B256; use async_trait::async_trait; -use eyre::Result; +use anyhow::Result; use consensus_core::types::{BeaconBlock, Bootstrap, FinalityUpdate, OptimisticUpdate, Update}; @@ -53,7 +53,7 @@ impl ConsensusRpc for MockRpc { } async fn chain_id(&self) -> Result { - eyre::bail!("not implemented") + anyhow::bail!("not implemented") } } diff --git a/consensus/src/rpc/mod.rs b/consensus/src/rpc/mod.rs index 6e8aa08d..01a3f96f 100644 --- a/consensus/src/rpc/mod.rs +++ b/consensus/src/rpc/mod.rs @@ -3,7 +3,7 @@ pub mod nimbus_rpc; use alloy::primitives::B256; use async_trait::async_trait; -use eyre::Result; +use anyhow::Result; use consensus_core::types::{BeaconBlock, Bootstrap, FinalityUpdate, OptimisticUpdate, Update}; diff --git a/consensus/src/rpc/nimbus_rpc.rs b/consensus/src/rpc/nimbus_rpc.rs index 7ecfad81..19022021 100644 --- a/consensus/src/rpc/nimbus_rpc.rs +++ b/consensus/src/rpc/nimbus_rpc.rs @@ -1,8 +1,8 @@ use std::cmp; use alloy::primitives::B256; +use anyhow::Result; use async_trait::async_trait; -use eyre::Result; use retri::{retry, BackoffSettings}; use serde::de::DeserializeOwned; @@ -18,7 +18,7 @@ pub struct NimbusRpc { async fn get(req: &str) -> Result { let bytes = retry( - || async { Ok::<_, eyre::Report>(reqwest::get(req).await?.bytes().await?) }, + || async { Ok::<_, anyhow::Error>(reqwest::get(req).await?.bytes().await?) }, BackoffSettings::default(), ) .await?; diff --git a/examples/basic.rs b/examples/basic.rs index 6d2cbf7c..1f1d67dc 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,7 +1,7 @@ use std::{path::PathBuf, str::FromStr}; use alloy::primitives::{utils::format_ether, Address}; -use eyre::Result; +use anyhow::Result; use tracing::info; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; use tracing_subscriber::FmtSubscriber; diff --git a/examples/call.rs b/examples/call.rs index 9e0023b7..30dc73ac 100644 --- a/examples/call.rs +++ b/examples/call.rs @@ -16,7 +16,7 @@ use helios::{ }; #[tokio::main] -async fn main() -> eyre::Result<()> { +async fn main() -> anyhow::Result<()> { let env_filter = EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) .from_env() diff --git a/examples/checkpoints.rs b/examples/checkpoints.rs index 84146ba5..7f6636cd 100644 --- a/examples/checkpoints.rs +++ b/examples/checkpoints.rs @@ -1,4 +1,4 @@ -use eyre::Result; +use anyhow::Result; // From helios::config use config::{checkpoints, networks}; diff --git a/examples/client.rs b/examples/client.rs index 61e194e3..bc630a81 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use alloy::primitives::b256; -use eyre::Result; +use anyhow::Result; use helios::prelude::*; diff --git a/examples/config.rs b/examples/config.rs index 2a9245ad..1db6defc 100644 --- a/examples/config.rs +++ b/examples/config.rs @@ -1,5 +1,5 @@ use dirs::home_dir; -use eyre::Result; +use anyhow::Result; use config::CliConfig; use helios::prelude::*; diff --git a/execution/Cargo.toml b/execution/Cargo.toml index a5f5ad4a..da62c68c 100644 --- a/execution/Cargo.toml +++ b/execution/Cargo.toml @@ -20,7 +20,7 @@ serde.workspace = true serde_json.workspace = true # misc -eyre.workspace = true +anyhow.workspace = true hex.workspace = true tracing.workspace = true thiserror.workspace = true diff --git a/execution/src/errors.rs b/execution/src/errors.rs index a1dbbeb6..63f39e19 100644 --- a/execution/src/errors.rs +++ b/execution/src/errors.rs @@ -1,6 +1,5 @@ use alloy::primitives::{Address, Bytes, B256, U256}; use alloy::sol_types::decode_revert_reason; -use eyre::Report; use thiserror::Error; #[derive(Debug, Error)] @@ -45,7 +44,7 @@ pub enum EvmError { Generic(String), #[error("rpc error: {0:?}")] - RpcError(Report), + RpcError(anyhow::Error), } impl EvmError { diff --git a/execution/src/evm.rs b/execution/src/evm.rs index 7c4c3d72..c7f63a5c 100644 --- a/execution/src/evm.rs +++ b/execution/src/evm.rs @@ -1,7 +1,7 @@ use std::{borrow::BorrowMut, collections::HashMap, sync::Arc}; use alloy::{network::TransactionBuilder, rpc::types::TransactionRequest}; -use eyre::{Report, Result}; +use anyhow::Result; use futures::future::join_all; use revm::{ primitives::{ @@ -216,7 +216,7 @@ impl EvmState { Ok(account.clone()) } else { self.access = Some(StateAccess::Basic(address)); - eyre::bail!("state missing"); + anyhow::bail!("state missing"); } } @@ -226,7 +226,7 @@ impl EvmState { Ok(*slot) } else { self.access = Some(StateAccess::Storage(address, slot)); - eyre::bail!("state missing"); + anyhow::bail!("state missing"); } } @@ -235,7 +235,7 @@ impl EvmState { Ok(*hash) } else { self.access = Some(StateAccess::BlockHash(block)); - eyre::bail!("state missing"); + anyhow::bail!("state missing"); } } @@ -323,9 +323,9 @@ impl EvmState { } impl Database for ProofDB { - type Error = Report; + type Error = anyhow::Error; - fn basic(&mut self, address: Address) -> Result, Report> { + fn basic(&mut self, address: Address) -> Result, anyhow::Error> { if is_precompile(&address) { return Ok(Some(AccountInfo::default())); } @@ -339,18 +339,18 @@ impl Database for ProofDB { Ok(Some(self.state.get_basic(address)?)) } - fn block_hash(&mut self, number: u64) -> Result { + fn block_hash(&mut self, number: u64) -> Result { trace!(target: "helios::evm", "fetch block hash for block={:?}", number); self.state.get_block_hash(number) } - fn storage(&mut self, address: Address, slot: U256) -> Result { + fn storage(&mut self, address: Address, slot: U256) -> Result { trace!(target: "helios::evm", "fetch evm state for address={:?}, slot={}", address, slot); self.state.get_storage(address, slot) } - fn code_by_hash(&mut self, _code_hash: B256) -> Result { - Err(eyre::eyre!("should never be called")) + fn code_by_hash(&mut self, _code_hash: B256) -> Result { + Err(anyhow::anyhow!("should never be called")) } } diff --git a/execution/src/execution.rs b/execution/src/execution.rs index e566a019..f49c4971 100644 --- a/execution/src/execution.rs +++ b/execution/src/execution.rs @@ -4,7 +4,7 @@ use alloy::consensus::{Receipt, ReceiptWithBloom, TxReceipt, TxType}; use alloy::primitives::{keccak256, Address, B256, U256}; use alloy::rlp::encode; use alloy::rpc::types::{Filter, Log, Transaction, TransactionReceipt}; -use eyre::Result; +use anyhow::Result; use futures::future::join_all; use revm::primitives::KECCAK_EMPTY; use triehash_ethereum::ordered_trie_root; @@ -51,7 +51,8 @@ impl ExecutionClient { .state .get_block(tag) .await - .ok_or(BlockNotFoundError::new(tag))?; + .ok_or(BlockNotFoundError::new(tag)) + .map_err(|e| anyhow::anyhow!(e))?; let proof = self .rpc @@ -127,7 +128,8 @@ impl ExecutionClient { .state .get_block(tag) .await - .ok_or(BlockNotFoundError::new(tag))?; + .ok_or(BlockNotFoundError::new(tag)) + .map_err(|e| anyhow::anyhow!(e))?; if !full_tx { block.transactions = Transactions::Hashes(block.transactions.hashes()); @@ -141,7 +143,7 @@ impl ExecutionClient { .state .get_block_by_hash(hash) .await - .ok_or(eyre::eyre!("block not found"))?; + .ok_or(anyhow::anyhow!("block not found"))?; if !full_tx { block.transactions = Transactions::Hashes(block.transactions.hashes()); @@ -183,7 +185,7 @@ impl ExecutionClient { let receipts_fut = tx_hashes.iter().map(|hash| async move { let receipt = self.rpc.get_transaction_receipt(*hash).await; - receipt?.ok_or(eyre::eyre!("not reachable")) + receipt?.ok_or(anyhow::anyhow!("not reachable")) }); let receipts = join_all(receipts_fut).await; @@ -278,7 +280,7 @@ impl ExecutionClient { // Get the hash of the tx that generated it let tx_hash = log .transaction_hash - .ok_or(eyre::eyre!("tx hash not found in log"))?; + .ok_or(anyhow::anyhow!("tx hash not found in log"))?; // Get its proven receipt let receipt = self diff --git a/execution/src/rpc/http_rpc.rs b/execution/src/rpc/http_rpc.rs index 4af4b8a4..ddb39540 100644 --- a/execution/src/rpc/http_rpc.rs +++ b/execution/src/rpc/http_rpc.rs @@ -8,7 +8,7 @@ use alloy::rpc::types::{ use alloy::transports::http::Http; use alloy::transports::layers::{RetryBackoffLayer, RetryBackoffService}; use async_trait::async_trait; -use eyre::Result; +use anyhow::Result; use reqwest::Client; use revm::primitives::AccessList; diff --git a/execution/src/rpc/mock_rpc.rs b/execution/src/rpc/mock_rpc.rs index 20a4f9cd..13389c13 100644 --- a/execution/src/rpc/mock_rpc.rs +++ b/execution/src/rpc/mock_rpc.rs @@ -5,8 +5,8 @@ use alloy::rpc::types::{ AccessList, EIP1186AccountProofResponse, FeeHistory, Filter, Log, Transaction, TransactionReceipt, TransactionRequest, }; +use anyhow::{anyhow, Result}; use async_trait::async_trait; -use eyre::{eyre, Result}; use super::ExecutionRpc; use common::types::BlockTag; @@ -39,7 +39,7 @@ impl ExecutionRpc for MockRpc { _opts: &TransactionRequest, _block: BlockTag, ) -> Result { - Err(eyre!("not implemented")) + Err(anyhow!("not implemented")) } async fn get_code(&self, _address: Address, _block: u64) -> Result> { @@ -48,7 +48,7 @@ impl ExecutionRpc for MockRpc { } async fn send_raw_transaction(&self, _bytes: &[u8]) -> Result { - Err(eyre!("not implemented")) + Err(anyhow!("not implemented")) } async fn get_transaction_receipt(&self, _tx_hash: B256) -> Result> { @@ -72,23 +72,23 @@ impl ExecutionRpc for MockRpc { } async fn uninstall_filter(&self, _filter_id: U256) -> Result { - Err(eyre!("not implemented")) + Err(anyhow!("not implemented")) } async fn get_new_filter(&self, _filter: &Filter) -> Result { - Err(eyre!("not implemented")) + Err(anyhow!("not implemented")) } async fn get_new_block_filter(&self) -> Result { - Err(eyre!("not implemented")) + Err(anyhow!("not implemented")) } async fn get_new_pending_transaction_filter(&self) -> Result { - Err(eyre!("not implemented")) + Err(anyhow!("not implemented")) } async fn chain_id(&self) -> Result { - Err(eyre!("not implemented")) + Err(anyhow!("not implemented")) } async fn get_fee_history( diff --git a/execution/src/rpc/mod.rs b/execution/src/rpc/mod.rs index 4e31fe77..b78d27eb 100644 --- a/execution/src/rpc/mod.rs +++ b/execution/src/rpc/mod.rs @@ -5,7 +5,7 @@ use alloy::rpc::types::{ AccessList, EIP1186AccountProofResponse, FeeHistory, Filter, Log, Transaction, TransactionReceipt, TransactionRequest, }; -use eyre::Result; +use anyhow::Result; use common::types::BlockTag; diff --git a/helios-ts/Cargo.toml b/helios-ts/Cargo.toml index bc8d356c..4b8e032f 100644 --- a/helios-ts/Cargo.toml +++ b/helios-ts/Cargo.toml @@ -15,7 +15,7 @@ wasm-bindgen-test = "0.3.0" serde-wasm-bindgen = "0.6.5" console_error_panic_hook = "0.1.7" -eyre.workspace = true +anyhow.workspace = true alloy.workspace = true hex = "0.4.3" diff --git a/helios-ts/src/lib.rs b/helios-ts/src/lib.rs index 472d7d45..8b538c6d 100644 --- a/helios-ts/src/lib.rs +++ b/helios-ts/src/lib.rs @@ -6,7 +6,7 @@ use std::str::FromStr; use alloy::hex::FromHex; use alloy::primitives::{Address, B256}; use alloy::rpc::types::{Filter, TransactionRequest}; -use eyre::Result; +use anyhow::Result; use wasm_bindgen::prelude::*; use common::types::BlockTag; diff --git a/helios-ts/src/storage.rs b/helios-ts/src/storage.rs index 6d5094ed..d22ec75a 100644 --- a/helios-ts/src/storage.rs +++ b/helios-ts/src/storage.rs @@ -2,7 +2,7 @@ extern crate console_error_panic_hook; extern crate web_sys; use alloy::{hex::FromHex, primitives::B256}; -use eyre::Result; +use anyhow::Result; use wasm_bindgen::prelude::*; use config::Config; @@ -19,7 +19,7 @@ impl Database for LocalStorageDB { return Ok(Self {}); } - eyre::bail!("local_storage not available") + anyhow::bail!("local_storage not available") } fn load_checkpoint(&self) -> Result { @@ -29,12 +29,12 @@ impl Database for LocalStorageDB { if let Ok(Some(checkpoint)) = checkpoint { let checkpoint = checkpoint.strip_prefix("0x").unwrap_or(&checkpoint); return B256::from_hex(checkpoint) - .map_err(|_| eyre::eyre!("Failed to decode checkpoint")); + .map_err(|_| anyhow::anyhow!("Failed to decode checkpoint")); } - eyre::bail!("checkpoint not found") + anyhow::bail!("checkpoint not found") } - eyre::bail!("local_storage not available") + anyhow::bail!("local_storage not available") } fn save_checkpoint(&self, checkpoint: B256) -> Result<()> { @@ -46,6 +46,6 @@ impl Database for LocalStorageDB { return Ok(()); } - eyre::bail!("local_storage not available") + anyhow::bail!("local_storage not available") } }