@@ -7,7 +7,10 @@ use crate::{
77 } ,
88 BundleReplacementData , BundleReplacementKey , MempoolTx , Order , OrderId ,
99 } ,
10- telemetry:: { add_rpc_processing_time, mark_command_received, scope_meter:: ScopeMeter } ,
10+ telemetry:: {
11+ add_rpc_processing_time, inc_order_input_rpc_errors, mark_command_received,
12+ scope_meter:: ScopeMeter ,
13+ } ,
1114} ;
1215use alloy_primitives:: { Address , Bytes } ;
1316use jsonrpsee:: {
@@ -31,6 +34,11 @@ use tokio_util::sync::CancellationToken;
3134use tracing:: { info, trace, warn} ;
3235use uuid:: Uuid ;
3336
37+ const ETH_SEND_BUNDLE : & str = "eth_sendBundle" ;
38+ const MEV_SEND_BUNDLE : & str = "mev_sendBundle" ;
39+ const ETH_CANCEL_BUNDLE : & str = "eth_cancelBundle" ;
40+ const ETH_SEND_RAW_TRANSACTION : & str = "eth_sendRawTransaction" ;
41+
3442/// Adds metrics to the callback and registers via module.register_async_method.
3543pub fn register_metered_async_method < ' a , R , Fun , Fut > (
3644 module : & ' a mut RpcModule < ( ) > ,
@@ -74,22 +82,22 @@ pub async fn start_server_accepting_bundles(
7482 let mut module = RpcModule :: new ( ( ) ) ;
7583
7684 let results_clone = results. clone ( ) ;
77- register_metered_async_method ( & mut module, "eth_sendBundle" , move |params, _| {
85+ register_metered_async_method ( & mut module, ETH_SEND_BUNDLE , move |params, _| {
7886 handle_eth_send_bundle ( results_clone. clone ( ) , timeout, params)
7987 } ) ?;
8088
8189 let results_clone = results. clone ( ) ;
82- register_metered_async_method ( & mut module, "mev_sendBundle" , move |params, _| {
90+ register_metered_async_method ( & mut module, MEV_SEND_BUNDLE , move |params, _| {
8391 handle_mev_send_bundle ( results_clone. clone ( ) , timeout, params)
8492 } ) ?;
8593
8694 let results_clone = results. clone ( ) ;
87- register_metered_async_method ( & mut module, "eth_cancelBundle" , move |params, _| {
95+ register_metered_async_method ( & mut module, ETH_CANCEL_BUNDLE , move |params, _| {
8896 handle_cancel_bundle ( results_clone. clone ( ) , timeout, params)
8997 } ) ?;
9098
9199 let results_clone = results. clone ( ) ;
92- register_metered_async_method ( & mut module, "eth_sendRawTransaction" , move |params, _| {
100+ register_metered_async_method ( & mut module, ETH_SEND_RAW_TRANSACTION , move |params, _| {
93101 let results = results_clone. clone ( ) ;
94102 async move {
95103 let received_at = OffsetDateTime :: now_utc ( ) ;
@@ -98,7 +106,7 @@ pub async fn start_server_accepting_bundles(
98106 Ok ( raw_tx) => raw_tx,
99107 Err ( err) => {
100108 warn ! ( ?err, "Failed to parse raw transaction" ) ;
101- // @Metric
109+ inc_order_input_rpc_errors ( ETH_SEND_RAW_TRANSACTION ) ;
102110 return Err ( err) ;
103111 }
104112 } ;
@@ -108,7 +116,7 @@ pub async fn start_server_accepting_bundles(
108116 Ok ( tx) => tx,
109117 Err ( err) => {
110118 warn ! ( ?err, "Failed to decode raw transaction" ) ;
111- // @Metric
119+ inc_order_input_rpc_errors ( ETH_SEND_RAW_TRANSACTION ) ;
112120 return Err ( ErrorObject :: owned (
113121 -32602 ,
114122 "failed to verify transaction" ,
@@ -157,7 +165,7 @@ async fn handle_eth_send_bundle(
157165 Ok ( raw_bundle) => raw_bundle,
158166 Err ( err) => {
159167 warn ! ( ?err, "Failed to parse raw bundle" ) ;
160- // @Metric
168+ inc_order_input_rpc_errors ( ETH_SEND_BUNDLE ) ;
161169 return ;
162170 }
163171 } ;
@@ -170,7 +178,7 @@ async fn handle_eth_send_bundle(
170178 Ok ( bundle_res) => bundle_res,
171179 Err ( err) => {
172180 warn ! ( ?err, "Failed to decode raw bundle" ) ;
173- // @Metric
181+ inc_order_input_rpc_errors ( ETH_SEND_BUNDLE ) ;
174182 return ;
175183 }
176184 } ;
@@ -185,6 +193,7 @@ async fn handle_eth_send_bundle(
185193 max_timestamp = bundle. max_timestamp,
186194 "Bundle has timestamp 0"
187195 ) ;
196+ inc_order_input_rpc_errors ( ETH_SEND_BUNDLE ) ;
188197 }
189198 let order = Order :: Bundle ( bundle) ;
190199 let parse_duration = start. elapsed ( ) ;
@@ -218,15 +227,15 @@ async fn handle_mev_send_bundle(
218227 Ok ( raw_bundle) => raw_bundle,
219228 Err ( err) => {
220229 warn ! ( ?err, "Failed to parse raw share bundle" ) ;
221- // @Metric
230+ inc_order_input_rpc_errors ( MEV_SEND_BUNDLE ) ;
222231 return ;
223232 }
224233 } ;
225234 let decode_res = match raw_bundle. decode ( TxEncoding :: WithBlobData ) {
226235 Ok ( res) => res,
227236 Err ( err) => {
228237 warn ! ( ?err, "Failed to decode raw share bundle" ) ;
229- // @Metric
238+ inc_order_input_rpc_errors ( MEV_SEND_BUNDLE ) ;
230239 return ;
231240 }
232241 } ;
@@ -282,6 +291,7 @@ async fn send_command(
282291 Ok ( ( ) ) => { }
283292 Err ( SendTimeoutError :: Timeout ( _) ) => {
284293 warn ! ( "Failed to sent order, timeout" ) ;
294+ inc_order_input_rpc_errors ( "other" ) ;
285295 }
286296 Err ( SendTimeoutError :: Closed ( _) ) => { }
287297 } ;
@@ -306,7 +316,7 @@ async fn handle_cancel_bundle(
306316 Ok ( cancel_bundle) => cancel_bundle,
307317 Err ( err) => {
308318 warn ! ( ?err, "Failed to parse cancel bundle" ) ;
309- // @Metric
319+ inc_order_input_rpc_errors ( ETH_CANCEL_BUNDLE ) ;
310320 return ;
311321 }
312322 } ;
0 commit comments