Skip to content
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

feat: add migration to remove bad blocks #6803

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading