Skip to content

Commit f2ca599

Browse files
authored
feat: add metrics (#163)
* feat: add metrics * chore: cleanup * fix: import * feat: 1 more metric
1 parent f753b88 commit f2ca599

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

src/tasks/block/sim.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::{
66
tasks::env::SimEnv,
77
};
88
use alloy::{eips::BlockId, network::Ethereum};
9-
use init4_bin_base::utils::calc::SlotCalculator;
9+
use init4_bin_base::{
10+
deps::metrics::{counter, histogram},
11+
utils::calc::SlotCalculator,
12+
};
1013
use signet_sim::{BlockBuild, BuiltBlock, SimCache};
1114
use signet_types::constants::SignetSystemConstants;
1215
use std::time::{Duration, Instant};
@@ -17,7 +20,7 @@ use tokio::{
1720
},
1821
task::JoinHandle,
1922
};
20-
use tracing::{Instrument, Span, instrument};
23+
use tracing::{Instrument, Span, debug, instrument};
2124
use trevm::revm::{
2225
context::BlockEnv,
2326
database::{AlloyDB, WrapDatabaseAsync},
@@ -140,11 +143,13 @@ impl Simulator {
140143
);
141144

142145
let built_block = block_build.build().in_current_span().await;
143-
tracing::debug!(
146+
debug!(
144147
tx_count = built_block.tx_count(),
145148
block_number = built_block.block_number(),
146149
"block simulation completed",
147150
);
151+
counter!("signet.builder.built_blocks").increment(1);
152+
histogram!("signet.builder.built_blocks.tx_count").record(built_block.tx_count() as f64);
148153

149154
Ok(built_block)
150155
}
@@ -167,7 +172,7 @@ impl Simulator {
167172
cache: SimCache,
168173
submit_sender: mpsc::UnboundedSender<SimResult>,
169174
) -> JoinHandle<()> {
170-
tracing::debug!("starting simulator task");
175+
debug!("starting simulator task");
171176

172177
tokio::spawn(async move { self.run_simulator(constants, cache, submit_sender).await })
173178
}
@@ -220,7 +225,6 @@ impl Simulator {
220225
continue;
221226
};
222227

223-
let _guard = span.clone().entered();
224228
span_debug!(span, tx_count = block.transactions().len(), "built simulated block");
225229
let _ = submit_sender.send(SimResult { block, sim_env });
226230
}

src/tasks/submit/flashbots.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ use alloy::{
1212
rpc::types::mev::{BundleItem, MevSendBundle, ProtocolVersion},
1313
};
1414
use eyre::OptionExt;
15-
use init4_bin_base::{
16-
deps::tracing::{Instrument, debug},
17-
utils::signer::LocalOrAws,
18-
};
15+
use init4_bin_base::{deps::metrics::counter, utils::signer::LocalOrAws};
1916
use tokio::{sync::mpsc, task::JoinHandle};
17+
use tracing::{Instrument, debug};
2018

2119
/// Handles construction, simulation, and submission of rollup blocks to the
2220
/// Flashbots network.
@@ -120,19 +118,16 @@ impl FlashbotsTask {
120118
break;
121119
};
122120
let span = sim_result.span();
123-
span_debug!(
124-
span,
125-
host_block_number = sim_result.host_block_number(),
126-
"received sim result"
127-
);
121+
span_debug!(span, "received sim result");
128122

129123
// Prepare a MEV bundle with the configured call type from the sim result
130-
let bundle = match self.prepare(&sim_result).instrument(span.clone()).await {
131-
Ok(b) => b,
132-
Err(e) => {
133-
span_error!(span, %e, "failed to prepare MEV bundle");
134-
continue;
135-
}
124+
let Ok(bundle) =
125+
self.prepare(&sim_result).instrument(span.clone()).await.inspect_err(|error| {
126+
counter!("signet.builder.flashbots.bundle_prep_failures").increment(1);
127+
span_debug!(span, %error, "bundle preparation failed");
128+
})
129+
else {
130+
continue;
136131
};
137132

138133
// Send the bundle to Flashbots
@@ -143,17 +138,16 @@ impl FlashbotsTask {
143138
.await;
144139

145140
match response {
146-
Ok(Some(hash)) => {
141+
Ok(resp) => {
142+
counter!("signet.builder.flashbots.bundles_submitted").increment(1);
147143
span_debug!(
148144
span,
149-
hash = hash.bundle_hash.to_string(),
145+
hash = resp.map(|r| r.bundle_hash.to_string()),
150146
"received bundle hash after submitted to flashbots"
151147
);
152148
}
153-
Ok(None) => {
154-
span_debug!(span, "received no bundle hash after submitted to flashbots");
155-
}
156149
Err(err) => {
150+
counter!("signet.builder.flashbots.submission_failures").increment(1);
157151
span_error!(span, %err, "MEV bundle submission failed - error returned");
158152
}
159153
}

src/tasks/submit/prep.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use alloy::{
1111
rpc::types::TransactionRequest,
1212
sol_types::SolCall,
1313
};
14+
use init4_bin_base::deps::metrics::counter;
1415
use signet_sim::BuiltBlock;
1516
use signet_types::{SignRequest, SignResponse};
1617
use signet_zenith::BundleHelper;
@@ -75,7 +76,13 @@ impl<'a> SubmitPrep<'a> {
7576
self.quincey_resp
7677
.get_or_try_init(|| async {
7778
let sig_request = self.sig_request();
78-
self.quincey.get_signature(sig_request).await
79+
self.quincey
80+
.get_signature(sig_request)
81+
.await
82+
.inspect(|_| counter!("signet.builder.quincey_signatures").increment(1))
83+
.inspect_err(|_| {
84+
counter!("signet.builder.quincey_signature_failures").increment(1)
85+
})
7986
})
8087
.await
8188
}

0 commit comments

Comments
 (0)