From b0dbd4389e91a5ea96b6eaef8c06a48bb3863856 Mon Sep 17 00:00:00 2001 From: clabby Date: Tue, 2 Jul 2024 16:25:05 -0400 Subject: [PATCH] lint --- Cargo.lock | 1 - crates/rpc/rpc-api/src/debug.rs | 3 +- crates/rpc/rpc/Cargo.toml | 1 - crates/rpc/rpc/src/debug.rs | 53 +++++++++---------- crates/storage/errors/src/provider.rs | 3 -- .../src/providers/bundle_state_provider.rs | 6 +-- .../src/providers/state/historical.rs | 2 +- 7 files changed, 29 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c677e018bfc3..962e60497108b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8060,7 +8060,6 @@ dependencies = [ "reth-tasks", "reth-testing-utils", "reth-transaction-pool", - "reth-trie", "revm", "revm-inspectors", "revm-primitives", diff --git a/crates/rpc/rpc-api/src/debug.rs b/crates/rpc/rpc-api/src/debug.rs index f073cc4348175..0364b2c3e6cdd 100644 --- a/crates/rpc/rpc-api/src/debug.rs +++ b/crates/rpc/rpc-api/src/debug.rs @@ -1,5 +1,3 @@ -use std::collections::HashMap; - use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{Address, BlockId, BlockNumberOrTag, Bytes, B256}; use reth_rpc_types::{ @@ -9,6 +7,7 @@ use reth_rpc_types::{ }, Bundle, RichBlock, StateContext, TransactionRequest, }; +use std::collections::HashMap; /// Debug rpc interface. #[cfg_attr(not(feature = "client"), rpc(server, namespace = "debug"))] diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index fe3605e03be4e..118a9a82190d1 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -32,7 +32,6 @@ reth-network-peers.workspace = true reth-evm.workspace = true reth-rpc-eth-types.workspace = true reth-rpc-server-types.workspace = true -reth-trie.workspace = true reth-evm-optimism = { workspace = true, optional = true } # eth diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 5333a8bf873a1..d20f15a9fd295 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use alloy_rlp::{Decodable, Encodable}; use async_trait::async_trait; use jsonrpsee::core::RpcResult; @@ -11,9 +9,8 @@ use reth_primitives::{ B256, U256, }; use reth_provider::{ - BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider, - HistoricalStateProviderRef, StateProvider, StateProviderFactory, StateRootProvider, - TransactionVariant, + BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider, StateProvider, + StateProviderFactory, TransactionVariant, }; use reth_revm::database::StateProviderDatabase; use reth_rpc_api::DebugApiServer; @@ -29,9 +26,8 @@ use reth_rpc_types::{ BlockError, Bundle, RichBlock, StateContext, TransactionRequest, }; use reth_tasks::pool::BlockingTaskGuard; -use reth_trie::{proof::Proof, HashedPostState}; use revm::{ - db::{states::bundle_state::BundleRetention, CacheDB, State}, + db::CacheDB, primitives::{db::DatabaseCommit, BlockEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg}, }; use revm_inspectors::tracing::{ @@ -39,6 +35,7 @@ use revm_inspectors::tracing::{ FourByteInspector, MuxInspector, TracingInspector, TracingInspectorConfig, }; use revm_primitives::{keccak256, HashMap}; +use std::sync::Arc; use tokio::sync::{AcquireError, OwnedSemaphorePermit}; /// `debug` API implementation. @@ -91,7 +88,7 @@ where ) -> EthResult> { if transactions.is_empty() { // nothing to trace - return Ok(Vec::new()) + return Ok(Vec::new()); } // replay all transactions of the block @@ -303,7 +300,7 @@ where Ok(inspector) }) .await?; - return Ok(FourByteFrame::from(inspector).into()) + return Ok(FourByteFrame::from(inspector).into()); } GethDebugBuiltInTracerType::CallTracer => { let call_config = tracer_config @@ -325,7 +322,7 @@ where Ok(frame.into()) }) .await?; - return Ok(frame) + return Ok(frame); } GethDebugBuiltInTracerType::PreStateTracer => { let prestate_config = tracer_config @@ -351,7 +348,7 @@ where Ok(frame) }) .await?; - return Ok(frame.into()) + return Ok(frame.into()); } GethDebugBuiltInTracerType::NoopTracer => Ok(NoopFrame::default().into()), GethDebugBuiltInTracerType::MuxTracer => { @@ -375,7 +372,7 @@ where Ok(frame.into()) }) .await?; - return Ok(frame) + return Ok(frame); } }, GethDebugTracerType::JsTracer(code) => { @@ -400,7 +397,7 @@ where Ok(GethTrace::JS(res)) } - } + }; } // default structlog tracer @@ -433,7 +430,7 @@ where opts: Option, ) -> EthResult>> { if bundles.is_empty() { - return Err(EthApiError::InvalidParams(String::from("bundles are empty."))) + return Err(EthApiError::InvalidParams(String::from("bundles are empty."))); } let StateContext { transaction_index, block_number } = state_context.unwrap_or_default(); @@ -584,11 +581,8 @@ where .accounts .into_iter() .map(|(addr, db_acc)| { - let storage_keys = db_acc - .storage - .into_iter() - .map(|(storage_key, _)| storage_key.into()) - .collect::>(); + let storage_keys = + db_acc.storage.keys().copied().map(Into::into).collect::>(); let account_proof = state.proof(addr, &storage_keys)?; Ok(account_proof) @@ -607,22 +601,23 @@ where let mut witness = HashMap::with_capacity(total_nodes); for proof in account_proofs { // First, add all account proof nodes. - for node in proof.proof.into_iter() { + for node in proof.proof { let hash = keccak256(node.as_ref()); witness.insert(hash, node); } // Next, add all storage proof nodes. - for storage_proof in proof.storage_proofs.into_iter() { - for node in storage_proof.proof.into_iter() { + for storage_proof in proof.storage_proofs { + for node in storage_proof.proof { let hash = keccak256(node.as_ref()); witness.insert(hash, node); } } } - // TODO: Also need blinded sibling nodes accessed during deletion, to allow for state root - // recomputation. As is, this is only sufficient for executing the block. + // TODO: Also need blinded sibling nodes accessed during deletion, to allow for + // state root recomputation. As is, this is only sufficient for + // executing the block. Ok(witness) }) .await @@ -650,7 +645,7 @@ where GethDebugBuiltInTracerType::FourByteTracer => { let mut inspector = FourByteInspector::default(); let (res, _) = self.eth_api().inspect(db, env, &mut inspector)?; - return Ok((FourByteFrame::from(inspector).into(), res.state)) + return Ok((FourByteFrame::from(inspector).into(), res.state)); } GethDebugBuiltInTracerType::CallTracer => { let call_config = tracer_config @@ -667,7 +662,7 @@ where .into_geth_builder() .geth_call_traces(call_config, res.result.gas_used()); - return Ok((frame.into(), res.state)) + return Ok((frame.into(), res.state)); } GethDebugBuiltInTracerType::PreStateTracer => { let prestate_config = tracer_config @@ -685,7 +680,7 @@ where db, )?; - return Ok((frame.into(), res.state)) + return Ok((frame.into(), res.state)); } GethDebugBuiltInTracerType::NoopTracer => { Ok((NoopFrame::default().into(), Default::default())) @@ -699,7 +694,7 @@ where let (res, _) = self.eth_api().inspect(&mut *db, env, &mut inspector)?; let frame = inspector.try_into_mux_frame(&res, db)?; - return Ok((frame.into(), res.state)) + return Ok((frame.into(), res.state)); } }, GethDebugTracerType::JsTracer(code) => { @@ -715,7 +710,7 @@ where let result = inspector.json_result(res, &env, db)?; Ok((GethTrace::JS(result), state)) } - } + }; } // default structlog tracer diff --git a/crates/storage/errors/src/provider.rs b/crates/storage/errors/src/provider.rs index 52a010474f963..db59d671fef7a 100644 --- a/crates/storage/errors/src/provider.rs +++ b/crates/storage/errors/src/provider.rs @@ -96,9 +96,6 @@ pub enum ProviderError { /// Thrown when we were unable to find a state for a block hash. #[error("no state found for block {0}")] StateForHashNotFound(B256), - /// Unable to compute state root on top of historical block. - #[error("unable to compute state root on top of historical block")] - StateRootNotAvailableForHistoricalBlock, /// Unable to find the block number for a given transaction index. #[error("unable to find the block number for a given transaction index")] BlockNumberForTransactionIndexNotFound, diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 49fb196ffb18b..61a654fb15a6e 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -2,7 +2,7 @@ use crate::{ AccountReader, BlockHashReader, ExecutionDataProvider, StateProvider, StateRootProvider, }; use reth_primitives::{Account, Address, BlockNumber, Bytecode, B256}; -use reth_storage_errors::provider::{ProviderError, ProviderResult}; +use reth_storage_errors::provider::ProviderResult; use reth_trie::{updates::TrieUpdates, AccountProof}; use revm::db::BundleState; @@ -108,7 +108,7 @@ impl StateProvider for BundleStat self.state_provider.bytecode_by_hash(code_hash) } - fn proof(&self, _address: Address, _keys: &[B256]) -> ProviderResult { - Err(ProviderError::StateRootNotAvailableForHistoricalBlock) + fn proof(&self, address: Address, keys: &[B256]) -> ProviderResult { + self.state_provider.proof(address, keys) } } diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index d7527f97573ed..931bde3272b81 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -14,7 +14,7 @@ use reth_primitives::{ StorageValue, B256, }; use reth_storage_errors::provider::ProviderResult; -use reth_trie::{updates::TrieUpdates, AccountProof, HashedPostState}; +use reth_trie::{proof::Proof, updates::TrieUpdates, AccountProof, HashedPostState}; use revm::db::BundleState; use std::fmt::Debug;