Skip to content

Commit d9f15f5

Browse files
authored
More error metrics (#635)
## 📝 Summary Adds 2 metrics: * coinbase balance * rpc errors counters ## 💡 Motivation and Context <!--- (Optional) Why is this change required? What problem does it solve? Remove this section if not applicable. --> --- ## ✅ I have completed the following steps: * [ ] Run `make lint` * [ ] Run `make test` * [ ] Added tests (if applicable)
1 parent 59ffc5a commit d9f15f5

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

crates/rbuilder/src/live_builder/block_output/bidding/wallet_balance_watcher.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing::{error, info, warn};
77

88
use super::interfaces::LandedBlockInfo;
99
use crate::provider::StateProviderFactory;
10-
use crate::telemetry::{add_subsidy_value, inc_subsidized_blocks};
10+
use crate::telemetry::{add_subsidy_value, inc_subsidized_blocks, set_builder_balance};
1111

1212
/// Allows to monitor the evolution of our wallet for the landed blocks.
1313
/// It's useful for bidders to detect profit and subsidies.
@@ -169,6 +169,7 @@ where
169169
}
170170
self.balance = landed_block_info.builder_balance;
171171
self.block_number = landed_block_info.block_number;
172+
set_builder_balance(self.balance);
172173
}
173174
Ok(res)
174175
}

crates/rbuilder/src/live_builder/order_input/rpc_server.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};
1215
use alloy_primitives::{Address, Bytes};
1316
use jsonrpsee::{
@@ -31,6 +34,11 @@ use tokio_util::sync::CancellationToken;
3134
use tracing::{info, trace, warn};
3235
use 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.
3543
pub 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
};

crates/rbuilder/src/telemetry/metrics/mod.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ use crate::{
1212
primitives::mev_boost::MevBoostRelayID,
1313
utils::{build_info::Version, duration_ms},
1414
};
15+
use alloy_consensus::constants::GWEI_TO_WEI;
1516
use alloy_primitives::{utils::Unit, U256};
1617
use bigdecimal::num_traits::Pow;
1718
use ctor::ctor;
1819
use lazy_static::lazy_static;
1920
use metrics_macros::register_metrics;
2021
use parking_lot::Mutex;
2122
use prometheus::{
22-
Counter, HistogramOpts, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Opts,
23-
Registry,
23+
Counter, Gauge, HistogramOpts, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec,
24+
Opts, Registry,
2425
};
2526
use std::{
2627
sync::Arc,
@@ -126,6 +127,11 @@ register_metrics! {
126127
)
127128
.unwrap();
128129

130+
pub static ORDER_INPUT_RPC_ERROR: IntCounterVec = IntCounterVec::new(
131+
Opts::new("rbuilder_order_input_rpc_errors", "counter of errors when receiving orders on RPC"),
132+
&["kind"],
133+
).unwrap();
134+
129135
pub static RELAY_ERRORS: IntCounterVec = IntCounterVec::new(
130136
Opts::new("relay_errors", "counter of relay errors"),
131137
&["relay", "kind"]
@@ -227,6 +233,8 @@ register_metrics! {
227233
// SUBSIDY
228234
/////////////////////////////////
229235

236+
pub static BUILDER_BALANCE: Gauge = Gauge::new("rbuilder_coinbase_balance", "balance of builder coinbase").unwrap();
237+
230238
/// We decide this at the end of the submission to relays
231239
pub static SUBSIDIZED_BLOCK_COUNT: IntCounterVec = IntCounterVec::new(
232240
Opts::new(
@@ -424,6 +432,10 @@ pub fn set_ordepool_count(txs: usize, bundles: usize) {
424432
ORDERPOOL_BUNDLES.set(bundles as i64);
425433
}
426434

435+
pub fn inc_order_input_rpc_errors(method: &str) {
436+
ORDER_INPUT_RPC_ERROR.with_label_values(&[method]).inc();
437+
}
438+
427439
#[allow(clippy::too_many_arguments)]
428440
pub fn add_finalized_block_metrics(
429441
built_block_trace: &BuiltBlockTrace,
@@ -593,6 +605,13 @@ pub fn add_subsidy_value(value: U256, landed: bool) {
593605
}
594606
}
595607

608+
pub fn set_builder_balance(balance: U256) {
609+
let gwei_balance = balance / U256::from(GWEI_TO_WEI);
610+
let u64_gwei_balance: u64 = gwei_balance.try_into().unwrap_or(0);
611+
let f64_eth_balance = u64_gwei_balance as f64 / 1_000_000_000.0;
612+
BUILDER_BALANCE.set(f64_eth_balance);
613+
}
614+
596615
fn sim_status(success: bool) -> &'static str {
597616
if success {
598617
SIM_STATUS_OK

0 commit comments

Comments
 (0)