Skip to content

Conversation

greged93
Copy link
Collaborator

No description provided.

@greged93 greged93 requested a review from frisitano October 13, 2025 16:22
Comment on lines 644 to 645
async fn get_n_l1_messages(
&self,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a stream which captured the lifetime of the TX caused lifetime issues when trying to return the stream from the database call.

Copy link

codspeed-hq bot commented Oct 13, 2025

CodSpeed Performance Report

Merging #358 will degrade performances by 13.34%

Comparing feat/update-retry (060dc10) with main (7bc44a0)

Summary

❌ 1 regression
✅ 1 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
pipeline_derive_in_file_blobs 969 ms 1,118.2 ms -13.34%

@greged93 greged93 requested a review from jonastheis October 14, 2025 16:17
Copy link
Collaborator

@frisitano frisitano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Added some minor comments inline, primiarly about when we should use the raw methods and when to instantiate a transaction.

Comment on lines +297 to +304
self.database
.tx_mut(move |tx| {
let block_info = block_info.clone();
async move {
tx.update_l1_messages_from_l2_blocks(vec![block_info.clone()]).await
}
})
.await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.database
.tx_mut(move |tx| {
let block_info = block_info.clone();
async move {
tx.update_l1_messages_from_l2_blocks(vec![block_info.clone()]).await
}
})
.await?;
self.database
.update_l1_messages_from_l2_blocks(vec![block_info.clone()])
.await?;

let l1_processed = db_tx.get_processed_l1_block_number().await?;
let (l1_latest, l1_finalized, l1_processed) = self
.database
.tx_mut(|tx| async move {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.tx_mut(|tx| async move {
.tx(|tx| async move {

Comment on lines +493 to +499
let consolidation_outcome = batch_consolidation_outcome.clone();
self.database
.tx_mut(move |tx| {
let consolidation_outcome = consolidation_outcome.clone();
async move { tx.insert_batch_consolidation_outcome(consolidation_outcome).await }
})
.await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let consolidation_outcome = batch_consolidation_outcome.clone();
self.database
.tx_mut(move |tx| {
let consolidation_outcome = consolidation_outcome.clone();
async move { tx.insert_batch_consolidation_outcome(consolidation_outcome).await }
})
.await?;
// Insert the batch consolidation outcome into the database.
self.database
.insert_batch_consolidation_outcome(batch_consolidation_outcome.clone())
.await?;

Comment on lines +511 to +516
let block_number = *block_number;
self.database
.tx_mut(move |tx| async move {
tx.set_processed_l1_block_number(block_number).await
})
.await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let block_number = *block_number;
self.database
.tx_mut(move |tx| async move {
tx.set_processed_l1_block_number(block_number).await
})
.await?;
self.database.set_processed_l1_block_number(*block_number).await?;

Comment on lines +551 to +552
self.database
.tx_mut(move |tx| async move { tx.set_latest_l1_block_number(block_number).await })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.database
.tx_mut(move |tx| async move { tx.set_latest_l1_block_number(block_number).await })
self.database.set_latest_l1_block_number(block_number).await?;

Comment on lines +1200 to +1208
let count = l1_message_hashes.len();
let mut database_messages = self
.database
.tx(move |tx| async move {
tx.get_n_l1_messages(Some(L1MessageKey::block_number(first_block_number)), count)
.await
})
.await?
.into_iter();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the method directly.

Ok::<_, ChainOrchestratorError>(input)
let mut input = database
.tx(move |tx| async move {
tx.get_n_l1_messages(Some(L1MessageKey::from_queue_index(index)), 1).await
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the method directly.

Comment on lines +49 to +51
tx.map_err(|_| DatabaseError::CommitFailed)?.commit().await?;
} else {
tx.map_err(|_| DatabaseError::RollbackFailed)?.rollback().await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, should we execute .commit() / .rollback() before we map_err(..)? No particular difference but it's more readable. What do you think?

Comment on lines +264 to +266
db.prepare_on_startup(chain_spec.genesis_hash()).await?;
let l2_head_block_number = db.get_l2_head_block_number().await?;
db.purge_l1_message_to_l2_block_mappings(Some(l2_head_block_number + 1)).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we combine this in a transaction?


// Update the head block info if available and ahead of finalized.
let l2_head_block_number = db.tx().await?.get_l2_head_block_number().await?;
let l2_head_block_number = db.get_l2_head_block_number().await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we combine this with the transaction above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants