Skip to content

Commit

Permalink
Merge pull request #609 from EspressoSystems/abdul/revert-tx
Browse files Browse the repository at this point in the history
Rollback transaction if failed to store fetched resource
  • Loading branch information
imabdulbasit authored Jun 3, 2024
2 parents 61f318e + 34627f4 commit 5ebafb5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/data_source/fetching/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ where
{
let mut storage = self.fetcher.storage.write().await;
if let Err(err) = store_block(&mut *storage, block).await {
// Rollback the transaction if insert fails
// This prevents subsequent queries from failing, as they would be part of the same transaction block.
storage.revert().await;
// It is unfortunate if this fails, but we can still proceed by returning
// the block that we fetched, keeping it in memory. Simply log the error and
// move on.
Expand Down
3 changes: 3 additions & 0 deletions src/data_source/fetching/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ where
tracing::info!("fetched leaf {height}");
let mut storage = fetcher.storage.write().await;
if let Err(err) = store_leaf(&mut *storage, leaf).await {
// Rollback the transaction if insert fails
// This prevents subsequent queries from failing, as they would be part of the same transaction block.
storage.revert().await;
// It is unfortunate if this fails, but we can still proceed by
// returning the leaf that we fetched, keeping it in memory.
// Simply log the error and move on.
Expand Down
3 changes: 3 additions & 0 deletions src/data_source/fetching/vid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ where
{
let mut storage = self.fetcher.storage.write().await;
if let Err(err) = store_vid_common(&mut *storage, common).await {
// Rollback the transaction if insert fails
// This prevents subsequent queries from failing, as they would be part of the same transaction block.
storage.revert().await;
// It is unfortunate if this fails, but we can still proceed by returning
// the block that we fetched, keeping it in memory. Simply log the error and
// move on.
Expand Down

0 comments on commit 5ebafb5

Please sign in to comment.