Skip to content

Commit

Permalink
feat: add migration to remove bad blocks (#6803)
Browse files Browse the repository at this point in the history
Adds a migration to clear the bad blocks table. This should be done in
future for any bug fixes that cause bad blocks

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved the update process to manage legacy data more effectively. By
addressing known data inconsistencies, the system now clears problematic
records during updates, enhancing overall reliability and performance.
End-users should experience smoother transitions and improved
consistency, ensuring a more robust experience. This enhancement is part
of our ongoing effort to optimize performance and maintain data
integrity.
- **Improvements**
- Updated migration logic to enhance the handling of bad blocks,
ensuring better data integrity during version updates.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
stringhandler authored Feb 18, 2025
1 parent 11d9926 commit 26a8fec
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2873,12 +2873,12 @@ impl fmt::Display for MetadataValue {
}

fn run_migrations(db: &LMDBDatabase) -> Result<(), ChainStorageError> {
const MIGRATION_VERSION: u64 = 1;
const MIGRATION_VERSION: u64 = 2;
let txn = db.read_transaction()?;

let k = MetadataKey::MigrationVersion;
let val = lmdb_get::<_, MetadataValue>(&txn, &db.metadata_db, &k.as_u32())?;
let n = match val {
let mut n = match val {
Some(MetadataValue::MigrationVersion(n)) => n,
Some(_) | None => 0,
};
Expand All @@ -2890,8 +2890,17 @@ fn run_migrations(db: &LMDBDatabase) -> Result<(), ChainStorageError> {

if n < MIGRATION_VERSION {
// Add migrations here
info!(target: LOG_TARGET, "Migrated database to version {}", MIGRATION_VERSION);
if n < 2 {
let txn = db.write_transaction()?;
info!(target: LOG_TARGET, "Clearing bad blocks list due to median timestamp bug in nextnet");
let rows_affected = lmdb_clear(&txn, &db.bad_blocks)?;
txn.commit()?;
info!(target: LOG_TARGET, "Removed {} rows from bad blocks", rows_affected);
n = 2;
}

let txn = db.write_transaction()?;
info!(target: LOG_TARGET, "Migrated database to version {}", MIGRATION_VERSION);
lmdb_replace(
&txn,
&db.metadata_db,
Expand Down

0 comments on commit 26a8fec

Please sign in to comment.