1- use std:: sync:: Arc ;
2- use std:: time:: Duration ;
1+ use std:: { sync:: Arc , time:: Duration } ;
32
4- use crate :: metrics:: Metrics ;
5- use crate :: pending_blocks:: PendingBlocks ;
63use alloy_eips:: { BlockId , BlockNumberOrTag } ;
7- use alloy_primitives:: map:: foldhash:: { HashSet , HashSetExt } ;
8- use alloy_primitives:: { Address , TxHash , U256 } ;
9- use alloy_rpc_types:: BlockOverrides ;
10- use alloy_rpc_types:: simulate:: { SimBlock , SimulatePayload , SimulatedBlock } ;
11- use alloy_rpc_types:: state:: { EvmOverrides , StateOverride , StateOverridesBuilder } ;
4+ use alloy_primitives:: {
5+ map:: foldhash:: { HashSet , HashSetExt } ,
6+ Address , TxHash , U256 ,
7+ } ;
8+ use alloy_rpc_types:: {
9+ simulate:: { SimBlock , SimulatePayload , SimulatedBlock } ,
10+ state:: { EvmOverrides , StateOverride , StateOverridesBuilder } ,
11+ BlockOverrides ,
12+ } ;
1213use alloy_rpc_types_eth:: { Filter , Log } ;
1314use arc_swap:: Guard ;
1415use jsonrpsee:: {
15- core:: { RpcResult , async_trait } ,
16+ core:: { async_trait , RpcResult } ,
1617 proc_macros:: rpc,
1718} ;
18- use jsonrpsee_types:: ErrorObjectOwned ;
19- use jsonrpsee_types:: error:: INVALID_PARAMS_CODE ;
19+ use jsonrpsee_types:: { error:: INVALID_PARAMS_CODE , ErrorObjectOwned } ;
2020use op_alloy_network:: Optimism ;
2121use op_alloy_rpc_types:: OpTransactionRequest ;
22- use reth:: providers :: CanonStateSubscriptions ;
23- use reth :: rpc :: eth :: EthFilter ;
24- use reth :: rpc :: server_types:: eth:: EthApiError ;
25- use reth_rpc_eth_api :: helpers :: EthState ;
26- use reth_rpc_eth_api:: helpers :: EthTransactions ;
27- use reth_rpc_eth_api :: helpers:: { EthBlocks , EthCall } ;
28- use reth_rpc_eth_api :: { EthApiTypes , EthFilterApiServer , RpcBlock , helpers :: FullEthApi } ;
29- use reth_rpc_eth_api :: { RpcReceipt , RpcTransaction } ;
30- use tokio:: sync :: broadcast ;
31- use tokio :: sync:: broadcast:: error:: RecvError ;
32- use tokio :: time;
33- use tokio_stream :: StreamExt ;
34- use tokio_stream:: wrappers:: BroadcastStream ;
22+ use reth:: {
23+ providers :: CanonStateSubscriptions ,
24+ rpc :: { eth :: EthFilter , server_types:: eth:: EthApiError } ,
25+ } ;
26+ use reth_rpc_eth_api:: {
27+ helpers:: { EthBlocks , EthCall , EthState , EthTransactions , FullEthApi } ,
28+ EthApiTypes , EthFilterApiServer , RpcBlock , RpcReceipt , RpcTransaction ,
29+ } ;
30+ use tokio:: {
31+ sync:: { broadcast, broadcast :: error:: RecvError } ,
32+ time,
33+ } ;
34+ use tokio_stream:: { wrappers:: BroadcastStream , StreamExt } ;
3535use tracing:: { debug, trace, warn} ;
3636
37+ use crate :: { metrics:: Metrics , pending_blocks:: PendingBlocks } ;
38+
3739/// Max configured timeout for `eth_sendRawTransactionSync` in milliseconds.
3840pub const MAX_TIMEOUT_SEND_RAW_TX_SYNC_MS : u64 = 6_000 ;
3941
@@ -89,7 +91,7 @@ pub trait EthApiOverride {
8991
9092 #[ method( name = "getBalance" ) ]
9193 async fn get_balance ( & self , address : Address , block_number : Option < BlockId > )
92- -> RpcResult < U256 > ;
94+ -> RpcResult < U256 > ;
9395
9496 #[ method( name = "getTransactionCount" ) ]
9597 async fn get_transaction_count (
@@ -149,12 +151,7 @@ pub struct EthApiExt<Eth: EthApiTypes, FB> {
149151
150152impl < Eth : EthApiTypes , FB > EthApiExt < Eth , FB > {
151153 pub fn new ( eth_api : Eth , eth_filter : EthFilter < Eth > , flashblocks_state : Arc < FB > ) -> Self {
152- Self {
153- eth_api,
154- eth_filter,
155- flashblocks_state,
156- metrics : Metrics :: default ( ) ,
157- }
154+ Self { eth_api, eth_filter, flashblocks_state, metrics : Metrics :: default ( ) }
158155 }
159156}
160157
@@ -180,9 +177,7 @@ where
180177 let pending_blocks = self . flashblocks_state . get_pending_blocks ( ) ;
181178 Ok ( pending_blocks. get_block ( full) )
182179 } else {
183- EthBlocks :: rpc_block ( & self . eth_api , number. into ( ) , full)
184- . await
185- . map_err ( Into :: into)
180+ EthBlocks :: rpc_block ( & self . eth_api , number. into ( ) , full) . await . map_err ( Into :: into)
186181 }
187182 }
188183
@@ -201,9 +196,7 @@ where
201196 return Ok ( Some ( fb_receipt) ) ;
202197 }
203198
204- EthTransactions :: transaction_receipt ( & self . eth_api , tx_hash)
205- . await
206- . map_err ( Into :: into)
199+ EthTransactions :: transaction_receipt ( & self . eth_api , tx_hash) . await . map_err ( Into :: into)
207200 }
208201
209202 async fn get_balance (
@@ -224,9 +217,7 @@ where
224217 }
225218 }
226219
227- EthState :: balance ( & self . eth_api , address, block_number)
228- . await
229- . map_err ( Into :: into)
220+ EthState :: balance ( & self . eth_api , address, block_number) . await . map_err ( Into :: into)
230221 }
231222
232223 async fn get_transaction_count (
@@ -254,9 +245,7 @@ where
254245 return Ok ( canon_count + fb_count) ;
255246 }
256247
257- EthState :: transaction_count ( & self . eth_api , address, block_number)
258- . await
259- . map_err ( Into :: into)
248+ EthState :: transaction_count ( & self . eth_api , address, block_number) . await . map_err ( Into :: into)
260249 }
261250
262251 async fn transaction_by_hash (
@@ -447,21 +436,13 @@ where
447436 state_overrides_builder. extend ( sim_block. state_overrides . unwrap_or_default ( ) ) ;
448437 let final_overrides = state_overrides_builder. build ( ) ;
449438
450- let block_state_call = SimBlock {
451- state_overrides : Some ( final_overrides) ,
452- ..sim_block
453- } ;
439+ let block_state_call = SimBlock { state_overrides : Some ( final_overrides) , ..sim_block } ;
454440 block_state_calls. push ( block_state_call) ;
455441 }
456442
457- let payload = SimulatePayload {
458- block_state_calls,
459- ..opts
460- } ;
443+ let payload = SimulatePayload { block_state_calls, ..opts } ;
461444
462- EthCall :: simulate_v1 ( & self . eth_api , payload, Some ( block_id) )
463- . await
464- . map_err ( Into :: into)
445+ EthCall :: simulate_v1 ( & self . eth_api , payload, Some ( block_id) ) . await . map_err ( Into :: into)
465446 }
466447
467448 async fn get_logs ( & self , filter : Filter ) -> RpcResult < Vec < Log > > {
@@ -472,10 +453,9 @@ where
472453
473454 // Check if this is a mixed query (toBlock is pending)
474455 let ( from_block, to_block) = match & filter. block_option {
475- alloy_rpc_types_eth:: FilterBlockOption :: Range {
476- from_block,
477- to_block,
478- } => ( * from_block, * to_block) ,
456+ alloy_rpc_types_eth:: FilterBlockOption :: Range { from_block, to_block } => {
457+ ( * from_block, * to_block)
458+ }
479459 _ => {
480460 // Block hash queries or other formats - delegate to eth API
481461 return self . eth_filter . logs ( filter) . await ;
0 commit comments