1- use std:: sync:: Arc ;
1+ use std:: { sync:: Arc , time :: Instant } ;
22
33use crate :: {
44 metrics:: OpRBuilderMetrics ,
@@ -17,6 +17,7 @@ use reth_optimism_txpool::{conditional::MaybeConditionalTransaction, OpPooledTra
1717use reth_provider:: StateProviderFactory ;
1818use reth_rpc_eth_types:: { utils:: recover_raw_transaction, EthApiError } ;
1919use reth_transaction_pool:: { PoolTransaction , TransactionOrigin , TransactionPool } ;
20+ use tracing:: error;
2021
2122// We have to split the RPC modules in two sets because we have methods that both
2223// replace an existing method and add a new one.
8889 Provider : StateProviderFactory + Send + Sync + Clone + ' static ,
8990{
9091 async fn send_bundle ( & self , bundle : Bundle ) -> RpcResult < BundleResult > {
92+ let request_start_time = Instant :: now ( ) ;
93+ self . metrics . bundle_requests . increment ( 1 ) ;
94+
95+ let bundle_result = self
96+ . send_bundle_inner ( bundle)
97+ . await
98+ . inspect_err ( |err| error ! ( "eth_sendBundle request failed: {err:?}" ) ) ;
99+
100+ if bundle_result. is_ok ( ) {
101+ self . metrics . valid_bundles . increment ( 1 ) ;
102+ } else {
103+ self . metrics . failed_bundles . increment ( 1 ) ;
104+ }
105+
106+ self . metrics
107+ . bundle_receive_duration
108+ . record ( request_start_time. elapsed ( ) ) ;
109+
110+ bundle_result
111+ }
112+ }
113+
114+ impl < Pool , Provider > RevertProtectionBundleAPI < Pool , Provider >
115+ where
116+ Pool : TransactionPool < Transaction = FBPooledTransaction > + Clone + ' static ,
117+ Provider : StateProviderFactory + Send + Sync + Clone + ' static ,
118+ {
119+ async fn send_bundle_inner ( & self , bundle : Bundle ) -> RpcResult < BundleResult > {
91120 let last_block_number = self
92121 . provider
93122 . best_block_number ( )
@@ -115,20 +144,17 @@ where
115144 . map_err ( EthApiError :: from) ?;
116145
117146 let recovered = recover_raw_transaction ( & bundle_transaction) ?;
118- let mut pool_transaction: FBPooledTransaction =
119- OpPooledTransaction :: from_pooled ( recovered) . into ( ) ;
120-
121- pool_transaction. set_reverted_hashes ( bundle. reverting_hashes . clone ( ) . unwrap_or_default ( ) ) ;
122- pool_transaction. set_conditional ( conditional) ;
147+ let pool_transaction =
148+ FBPooledTransaction :: from ( OpPooledTransaction :: from_pooled ( recovered) )
149+ . with_reverted_hashes ( bundle. reverting_hashes . clone ( ) . unwrap_or_default ( ) )
150+ . with_conditional ( conditional) ;
123151
124152 let hash = self
125153 . pool
126154 . add_transaction ( TransactionOrigin :: Local , pool_transaction)
127155 . await
128156 . map_err ( EthApiError :: from) ?;
129157
130- self . metrics . bundles_received . increment ( 1 ) ;
131-
132158 let result = BundleResult { bundle_hash : hash } ;
133159 Ok ( result)
134160 }
0 commit comments