Skip to content

Commit

Permalink
fix: roll back ordinals db changes when brc20 db commit fails (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr authored Sep 24, 2024
1 parent ef9725b commit f4e0c79
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use crate::{
blocks::open_blocks_db_with_retry,
cursor::TransactionBytesCursor,
ordinals::{
get_any_entry_in_ordinal_activities, get_latest_indexed_inscription_number,
open_ordinals_db, open_ordinals_db_rw,
delete_inscriptions_in_block_range, get_any_entry_in_ordinal_activities,
get_latest_indexed_inscription_number, open_ordinals_db, open_ordinals_db_rw,
},
},
service::write_brc20_block_operations,
Expand Down Expand Up @@ -248,20 +248,34 @@ pub fn process_blocks(
if let Some(brc20_db_tx) = brc20_db_tx {
match brc20_db_tx.commit() {
Ok(_) => {}
Err(_) => {
// TODO: Synchronize rollbacks and commits between BRC-20 and inscription DBs.
todo!()
Err(e) => {
// We will roll back the ordinals DB changes and panic so we can try the index again on next
// restart.
try_error!(
ctx,
"Unable to write BRC-20 index for block #{}: {}",
block.block_identifier.index,
e.to_string()
);
delete_inscriptions_in_block_range(
block.block_identifier.index as u32,
block.block_identifier.index as u32,
inscriptions_db_conn_rw,
ctx,
);
panic!("BRC-20 DB transaction commit failed");
}
}
}
}
Err(e) => {
try_error!(
ctx,
"Unable to update changes in block #{}: {}",
"Unable to write index for block #{}: {}",
block.block_identifier.index,
e.to_string()
);
panic!("Ordinals DB transaction commit failed");
}
}
}
Expand Down

0 comments on commit f4e0c79

Please sign in to comment.