Files
lighthouse/slasher/src/migrate.rs
realbigsean 9e84779522 Indexed att on disk (#35)
* indexed att on disk

* fix lints

* Update slasher/src/migrate.rs

Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com>

---------

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com>
2024-06-19 11:31:50 +02:00

34 lines
1.4 KiB
Rust

use crate::{database::CURRENT_SCHEMA_VERSION, Error, SlasherDB};
use types::EthSpec;
impl<E: EthSpec> SlasherDB<E> {
/// If the database exists, and has a schema, attempt to migrate it to the current version.
pub fn migrate(self) -> Result<Self, Error> {
let mut txn = self.begin_rw_txn()?;
let schema_version = self.load_schema_version(&mut txn)?;
drop(txn);
if let Some(schema_version) = schema_version {
match (schema_version, CURRENT_SCHEMA_VERSION) {
// Schema v3 changed the underlying database from LMDB to MDBX. Unless the user did
// some manual hacking it should be impossible to read an MDBX schema version < 3.
(from, _) if from < 3 => Err(Error::IncompatibleSchemaVersion {
database_schema_version: schema_version,
software_schema_version: CURRENT_SCHEMA_VERSION,
}),
(x, y) if x == y => Ok(self),
(3, 4) => {
// TODO(electra): db migration due to `IndexedAttestationOnDisk`
Ok(self)
}
(_, _) => Err(Error::IncompatibleSchemaVersion {
database_schema_version: schema_version,
software_schema_version: CURRENT_SCHEMA_VERSION,
}),
}
} else {
Ok(self)
}
}
}