1- use alloy_consensus:: Typed2718 ;
2- use alloy_consensus :: constants:: KECCAK_EMPTY ;
3- use alloy_consensus :: { Transaction , transaction :: SignerRecoverable } ;
1+ use alloy_consensus:: {
2+ Transaction , Typed2718 , constants:: KECCAK_EMPTY , transaction :: SignerRecoverable ,
3+ } ;
44use alloy_primitives:: { Address , B256 , Bytes , U256 , address} ;
5- use alloy_provider:: network:: eip2718:: Decodable2718 ;
6- use alloy_provider:: { Provider , RootProvider } ;
5+ use alloy_provider:: { Provider , RootProvider , network:: eip2718:: Decodable2718 } ;
76use alloy_rpc_types_mev:: { EthBundleHash , EthCancelBundle , EthSendBundle } ;
87use anyhow:: Result ;
9- use jsonrpsee:: types:: ErrorObject ;
108use jsonrpsee:: {
119 core:: { RpcResult , async_trait} ,
1210 proc_macros:: rpc,
11+ types:: ErrorObject ,
1312} ;
1413use op_alloy_consensus:: OpTxEnvelope ;
15- use op_alloy_network:: Optimism ;
14+ use op_alloy_network:: { Optimism , eip2718:: Encodable2718 } ;
15+ use op_revm:: { OpSpecId , l1block:: L1BlockInfo } ;
1616use reth_rpc_eth_types:: EthApiError ;
1717use tracing:: { info, warn} ;
1818
@@ -102,7 +102,8 @@ impl<Queue> IngressService<Queue> {
102102 }
103103
104104 // error if tx nonce is not the latest
105- if envelope. nonce ( ) != account. nonce - 1 {
105+ // https://github.com/paradigmxyz/reth/blob/a047a055ab996f85a399f5cfb2fe15e350356546/crates/transaction-pool/src/validate/eth.rs#L611
106+ if envelope. nonce ( ) < account. nonce {
106107 return Err ( anyhow:: anyhow!( "Nonce is not the latest" ) ) ;
107108 }
108109
@@ -111,7 +112,17 @@ impl<Queue> IngressService<Queue> {
111112 return Err ( anyhow:: anyhow!( "Insufficient funds" ) ) ;
112113 }
113114
114- // TODO: op-checks (l1 block info, l1 balance > execution + DA fee)
115+ // op-checks to see if sender can cover L1 gas cost
116+ // from: https://github.com/paradigmxyz/reth/blob/6aa73f14808491aae77fc7c6eb4f0aa63bef7e6e/crates/optimism/txpool/src/validator.rs#L219
117+ let mut l1_block_info = L1BlockInfo :: default ( ) ;
118+ let tx = envelope. clone ( ) . try_into_pooled ( ) ?;
119+ let encoded = tx. encoded_2718 ( ) ;
120+
121+ let cost_addition = l1_block_info. calculate_tx_l1_cost ( & encoded, OpSpecId :: ISTHMUS ) ;
122+ let cost = tx. value ( ) . saturating_add ( cost_addition) ;
123+ if cost > account. balance {
124+ return Err ( anyhow:: anyhow!( "Insufficient funds to cover L1 gas cost" ) ) ;
125+ }
115126 Ok ( ( ) )
116127 }
117128}
0 commit comments