@@ -11,7 +11,9 @@ use op_alloy_network::Optimism;
1111use reth_rpc_eth_types:: EthApiError ;
1212use std:: time:: { SystemTime , UNIX_EPOCH } ;
1313use tips_audit:: { BundleEvent , BundleEventPublisher } ;
14- use tips_core:: { Bundle , BundleHash , BundleWithMetadata , CancelBundle , MeterBundleResponse } ;
14+ use tips_core:: {
15+ BLOCK_TIME , Bundle , BundleHash , BundleWithMetadata , CancelBundle , MeterBundleResponse ,
16+ } ;
1517use tracing:: { info, warn} ;
1618
1719use crate :: queue:: QueuePublisher ;
6567 Audit : BundleEventPublisher + Sync + Send + ' static ,
6668{
6769 async fn send_bundle ( & self , bundle : Bundle ) -> RpcResult < BundleHash > {
68- let bundle_with_metadata = self . validate_bundle ( & bundle) . await ?;
69- self . meter_bundle ( & bundle) . await ?;
70+ let mut bundle_with_metadata = self . validate_bundle ( & bundle) . await ?;
71+ bundle_with_metadata . set_meter_bundle_response ( self . meter_bundle ( & bundle) . await ?) ;
7072
7173 let bundle_hash = bundle_with_metadata. bundle_hash ( ) ;
7274 if let Err ( e) = self
@@ -118,10 +120,11 @@ where
118120 reverting_tx_hashes : vec ! [ transaction. tx_hash( ) ] ,
119121 ..Default :: default ( )
120122 } ;
121- self . meter_bundle ( & bundle) . await ?;
123+ let meter_bundle_response = self . meter_bundle ( & bundle) . await ?;
122124
123- let bundle_with_metadata = BundleWithMetadata :: load ( bundle)
125+ let mut bundle_with_metadata = BundleWithMetadata :: load ( bundle)
124126 . map_err ( |e| EthApiError :: InvalidParams ( e. to_string ( ) ) . into_rpc_err ( ) ) ?;
127+ bundle_with_metadata. set_meter_bundle_response ( meter_bundle_response) ;
125128 let bundle_hash = bundle_with_metadata. bundle_hash ( ) ;
126129
127130 if let Err ( e) = self
@@ -215,20 +218,24 @@ where
215218 Ok ( bundle_with_metadata)
216219 }
217220
218- async fn meter_bundle ( & self , bundle : & Bundle ) -> RpcResult < ( ) > {
221+ /// `meter_bundle` is used to determine how long a bundle will take to execute. A bundle that
222+ /// is within `BLOCK_TIME` will return the `MeterBundleResponse` that can be passed along
223+ /// to the builder.
224+ async fn meter_bundle ( & self , bundle : & Bundle ) -> RpcResult < MeterBundleResponse > {
219225 let res: MeterBundleResponse = self
220226 . provider
221227 . client ( )
222228 . request ( "base_meterBundle" , ( bundle, ) )
223229 . await
224230 . map_err ( |e| EthApiError :: InvalidParams ( e. to_string ( ) ) . into_rpc_err ( ) ) ?;
225231
226- // if simulation takes longer than 2s, we don't include and just error to user
227- if res. total_execution_time_us > 2000000 {
232+ // we can save some builder payload building computation by not including bundles
233+ // that we know will take longer than the block time to execute
234+ if res. total_execution_time_us > BLOCK_TIME {
228235 return Err (
229236 EthApiError :: InvalidParams ( "Bundle simulation took too long" . into ( ) ) . into_rpc_err ( ) ,
230237 ) ;
231238 }
232- Ok ( ( ) )
239+ Ok ( res )
233240 }
234241}
0 commit comments