3b61ac9cbf
## Issue Addressed Closes #2286 Closes #2538 Closes #2342 ## Proposed Changes Part II of major slasher optimisations after #2767 These changes will be backwards-incompatible due to the move to MDBX (and the schema change) 😱 * [x] Shrink attester keys from 16 bytes to 7 bytes. * [x] Shrink attester records from 64 bytes to 6 bytes. * [x] Separate `DiskConfig` from regular `Config`. * [x] Add configuration for the LRU cache size. * [x] Add a "migration" that deletes any legacy LMDB database.
30 lines
1.2 KiB
Rust
30 lines
1.2 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),
|
|
(_, _) => Err(Error::IncompatibleSchemaVersion {
|
|
database_schema_version: schema_version,
|
|
software_schema_version: CURRENT_SCHEMA_VERSION,
|
|
}),
|
|
}
|
|
} else {
|
|
Ok(self)
|
|
}
|
|
}
|
|
}
|