-
Notifications
You must be signed in to change notification settings - Fork 3
feat: update retry mechanism using tower::Service #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
async fn get_n_l1_messages( | ||
&self, |
There was a problem hiding this comment.
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.
CodSpeed Performance ReportMerging #358 will degrade performances by 13.34%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this 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.
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?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.tx_mut(|tx| async move { | |
.tx(|tx| async move { |
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?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?; |
let block_number = *block_number; | ||
self.database | ||
.tx_mut(move |tx| async move { | ||
tx.set_processed_l1_block_number(block_number).await | ||
}) | ||
.await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?; |
self.database | ||
.tx_mut(move |tx| async move { tx.set_latest_l1_block_number(block_number).await }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?; |
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the method directly.
tx.map_err(|_| DatabaseError::CommitFailed)?.commit().await?; | ||
} else { | ||
tx.map_err(|_| DatabaseError::RollbackFailed)?.rollback().await?; |
There was a problem hiding this comment.
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?
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?; |
There was a problem hiding this comment.
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?; |
There was a problem hiding this comment.
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?
No description provided.