Skip to content

Commit ef0b416

Browse files
committed
fix: add interval for finalization metric
1 parent dded7bc commit ef0b416

File tree

7 files changed

+95
-22
lines changed

7 files changed

+95
-22
lines changed

.sqlx/query-d6ad3af8502339a76d4a880f25b887858f300b7b36d0490c244e05d3fd20ee4c.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/adapters/storage/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use services::{
1515
block_bundler::port::UnbundledBlocks,
1616
types::{
1717
BlockSubmission, BlockSubmissionTx, BundleCost, CompressedFuelBlock, DateTime,
18-
DispersalStatus, EigenDASubmission, Fragment, L1Tx, NonEmpty, NonNegative,
19-
TransactionCostUpdate, TransactionState, Utc, storage::BundleFragment,
18+
DispersalStatus, EigenDARequestId, EigenDASubmission, Fragment, L1Tx, NonEmpty,
19+
NonNegative, TransactionCostUpdate, TransactionState, Utc, storage::BundleFragment,
2020
},
2121
};
2222

@@ -46,6 +46,15 @@ impl services::state_listener::port::Storage for Postgres {
4646
.map_err(Into::into)
4747
}
4848

49+
async fn earliest_eigen_submission_attempt(
50+
&self,
51+
request_id: &EigenDARequestId,
52+
) -> Result<Option<DateTime<Utc>>> {
53+
self._earliest_eigen_submission_attempt(request_id)
54+
.await
55+
.map_err(Into::into)
56+
}
57+
4958
async fn get_non_finalized_eigen_submission(&self) -> services::Result<Vec<EigenDASubmission>> {
5059
self._get_non_finalized_eigen_submission()
5160
.await

packages/adapters/storage/src/postgres.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use services::{
77
block_bundler::port::UnbundledBlocks,
88
types::{
99
BlockSubmission, BlockSubmissionTx, BundleCost, CompressedFuelBlock, DateTime,
10-
DispersalStatus, EigenDASubmission, Fragment, NonEmpty, NonNegative, TransactionCostUpdate,
11-
TransactionState, Utc, storage::SequentialFuelBlocks,
10+
DispersalStatus, EigenDARequestId, EigenDASubmission, Fragment, NonEmpty, NonNegative,
11+
TransactionCostUpdate, TransactionState, Utc, storage::SequentialFuelBlocks,
1212
},
1313
};
1414
use sqlx::{
@@ -1363,6 +1363,27 @@ impl Postgres {
13631363
})
13641364
}
13651365

1366+
pub(crate) async fn _earliest_eigen_submission_attempt(
1367+
&self,
1368+
request_id: &EigenDARequestId,
1369+
) -> Result<Option<DateTime<Utc>>> {
1370+
let response = sqlx::query!(
1371+
r#"SELECT
1372+
MIN(created_at) AS earliest_submission_time
1373+
FROM
1374+
eigen_submission
1375+
WHERE
1376+
request_id = $1;
1377+
"#,
1378+
request_id
1379+
)
1380+
.fetch_optional(&self.connection_pool)
1381+
.await?
1382+
.and_then(|response| response.earliest_submission_time);
1383+
1384+
Ok(response)
1385+
}
1386+
13661387
pub(crate) async fn _record_eigenda_submission(
13671388
&self,
13681389
submission: EigenDASubmission,

packages/adapters/storage/src/test_instance.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use services::{
1010
block_committer, block_importer,
1111
types::{
1212
BlockSubmission, BlockSubmissionTx, BundleCost, CompressedFuelBlock, DateTime,
13-
DispersalStatus, EigenDASubmission, Fragment, L1Tx, NonEmpty, NonNegative,
14-
TransactionCostUpdate, TransactionState, Utc, storage::BundleFragment,
13+
DispersalStatus, EigenDARequestId, EigenDASubmission, Fragment, L1Tx, NonEmpty,
14+
NonNegative, TransactionCostUpdate, TransactionState, Utc, storage::BundleFragment,
1515
},
1616
};
1717
use sqlx::Executor;
@@ -216,6 +216,14 @@ impl services::state_listener::port::Storage for DbWithProcess {
216216
async fn get_non_finalized_eigen_submission(&self) -> services::Result<Vec<EigenDASubmission>> {
217217
unimplemented!();
218218
}
219+
220+
async fn earliest_eigen_submission_attempt(
221+
&self,
222+
_request_id: &EigenDARequestId,
223+
) -> services::Result<Option<DateTime<Utc>>> {
224+
unimplemented!();
225+
}
226+
219227
async fn update_eigen_submissions(
220228
&self,
221229
_changes: Vec<(u32, DispersalStatus)>,

packages/services/src/state_listener/eigen_service.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use metrics::{
22
RegistersMetrics,
3-
prometheus::{IntGauge, Opts, core::Collector},
3+
prometheus::{IntGauge, core::Collector},
44
};
55

66
use crate::{
@@ -42,6 +42,7 @@ where
4242
non_finalized: Vec<EigenDASubmission>,
4343
) -> crate::Result<()> {
4444
let mut changes = Vec::with_capacity(non_finalized.len());
45+
let mut last_finalized_request_id = None;
4546

4647
for submission in non_finalized {
4748
let status = self
@@ -82,8 +83,7 @@ where
8283
changes.push((submission_id, DispersalStatus::Confirmed));
8384
}
8485
DispersalStatus::Finalized => {
85-
let now = self.clock.now();
86-
self.metrics.last_finalization_time.set(now.timestamp());
86+
last_finalized_request_id = Some(submission.request_id.clone());
8787
tracing::info!(
8888
"Finalized submission with request_id: {}",
8989
submission.as_base64(),
@@ -108,6 +108,22 @@ where
108108
}
109109
}
110110

111+
// get the last request that was finalized, and update metrics accordingly -
112+
if let Some(request_id) = last_finalized_request_id {
113+
if let Some(earliest_submission_attempt) = self
114+
.storage
115+
.earliest_eigen_submission_attempt(&request_id)
116+
.await?
117+
{
118+
let now = self.clock.now();
119+
let duration = now.signed_duration_since(earliest_submission_attempt);
120+
self.metrics
121+
.last_finalization_interval
122+
.set(duration.num_seconds());
123+
self.metrics.last_finalization_time.set(now.timestamp());
124+
}
125+
}
126+
111127
self.storage.update_eigen_submissions(changes).await?;
112128

113129
Ok(())
@@ -123,7 +139,7 @@ where
123139
async fn run(&mut self) -> crate::Result<()> {
124140
let non_finalized = self.storage.get_non_finalized_eigen_submission().await?;
125141

126-
tracing::info!(
142+
tracing::debug!(
127143
"Checking non-finalized submissions: {}",
128144
non_finalized.len()
129145
);
@@ -140,15 +156,13 @@ where
140156

141157
#[derive(Clone)]
142158
struct Metrics {
143-
last_eth_block_w_blob: IntGauge,
144159
last_finalization_time: IntGauge,
145160
last_finalization_interval: IntGauge,
146161
}
147162

148163
impl<EigenDA, Db, Clock> RegistersMetrics for StateListener<EigenDA, Db, Clock> {
149164
fn metrics(&self) -> Vec<Box<dyn Collector>> {
150165
vec![
151-
Box::new(self.metrics.last_eth_block_w_blob.clone()),
152166
Box::new(self.metrics.last_finalization_time.clone()),
153167
Box::new(self.metrics.last_finalization_interval.clone()),
154168
]
@@ -157,12 +171,6 @@ impl<EigenDA, Db, Clock> RegistersMetrics for StateListener<EigenDA, Db, Clock>
157171

158172
impl Metrics {
159173
fn new(last_finalization_time: IntGauge) -> Self {
160-
let last_eth_block_w_blob = IntGauge::with_opts(Opts::new(
161-
"last_eth_block_w_blob",
162-
"The height of the latest Ethereum block used for state submission.",
163-
))
164-
.expect("last_eth_block_w_blob metric to be correctly configured");
165-
166174
let last_finalization_interval = IntGauge::new(
167175
"seconds_from_earliest_submission_to_finalization",
168176
"The number of seconds from the earliest submission to finalization",
@@ -172,7 +180,6 @@ impl Metrics {
172180
);
173181

174182
Self {
175-
last_eth_block_w_blob,
176183
last_finalization_time,
177184
last_finalization_interval,
178185
}

packages/services/src/state_listener/port.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
Result,
33
types::{
4-
DateTime, DispersalStatus, EigenDASubmission, L1Tx, TransactionCostUpdate,
5-
TransactionState, Utc,
4+
DateTime, DispersalStatus, EigenDARequestId, EigenDASubmission, L1Tx,
5+
TransactionCostUpdate, TransactionState, Utc,
66
},
77
};
88

@@ -51,6 +51,10 @@ pub trait Storage: Sync {
5151

5252
// EigenDA
5353
async fn get_non_finalized_eigen_submission(&self) -> Result<Vec<EigenDASubmission>>;
54+
async fn earliest_eigen_submission_attempt(
55+
&self,
56+
request_id: &EigenDARequestId,
57+
) -> Result<Option<DateTime<Utc>>>;
5458
async fn update_eigen_submissions(&self, changes: Vec<(u32, DispersalStatus)>) -> Result<()>;
5559
}
5660

packages/services/src/types/eigen_submission.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ pub enum DispersalStatus {
1010
Other(String),
1111
}
1212

13+
pub type EigenDARequestId = Vec<u8>;
14+
1315
#[derive(Debug, Clone, PartialEq, Eq)]
1416
pub struct EigenDASubmission {
1517
pub id: Option<u64>,
16-
pub request_id: Vec<u8>,
18+
pub request_id: EigenDARequestId,
1719
pub created_at: Option<DateTime<Utc>>,
1820
pub status: DispersalStatus,
1921
}

0 commit comments

Comments
 (0)