Files
lighthouse/slasher/src/error.rs
Eitan Seri-Levi 70bcba1e6b Redb slasher backend impl (#4529)
* initial redb impl

* redb impl

* remove phantom data

* fixed table definition

* fighting the borrow checker

* a rough draft that doesnt cause lifetime issues

* refactoring

* refactor

* refactor

* passing unit tests

* refactor

* refactor

* refactor

* commit

* move everything to one database

* remove panics, ready for a review

* merge

* a working redb impl

* passing a ref of txn to cursor

* this tries to create a second write transaction when initializing cursor. breaks everything

* Use 2 lifetimes and subtyping

Also fixes a bug in last_key caused by rev and next_back cancelling out

* Move table into cursor

* Merge remote-tracking branch 'origin/unstable' into redb-slasher-backend-impl

* changes based on feedback

* update lmdb

* fix lifetime issues

* moving everything from Cursor to Transaction

* update

* upgrade to redb 2.0

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into redb-slasher-backend-impl

* bring back cursor

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into redb-slasher-backend-impl

* fix delete while

* linting

* linting

* switch to lmdb

* update redb to v2.1

* build fixes, remove unwrap or default

* another build error

* hopefully this is the last build error

* fmt

* cargo.toml

* fix mdbx

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into redb-slasher-backend-impl

* Remove a collect

* Merge remote-tracking branch 'origin/unstable' into redb-slasher-backend-impl

* Merge branch 'redb-slasher-backend-impl' of https://github.com/eserilev/lighthouse into redb-slasher-backend-impl

* re-enable test

* fix failing slasher test

* Merge remote-tracking branch 'origin/unstable' into redb-slasher-backend-impl

* Rename DB file to `slasher.redb`
2024-07-01 01:36:40 +00:00

159 lines
3.8 KiB
Rust

use crate::config::{Config, DiskConfig};
use std::io;
use types::Epoch;
#[derive(Debug)]
pub enum Error {
#[cfg(feature = "mdbx")]
DatabaseMdbxError(mdbx::Error),
#[cfg(feature = "lmdb")]
DatabaseLmdbError(lmdb::Error),
#[cfg(feature = "redb")]
DatabaseRedbError(redb::Error),
SlasherDatabaseBackendDisabled,
MismatchedDatabaseVariant,
DatabaseIOError(io::Error),
DatabasePermissionsError(filesystem::Error),
SszDecodeError(ssz::DecodeError),
SszTypesError(ssz_types::Error),
BincodeError(bincode::Error),
ArithError(safe_arith::ArithError),
ChunkIndexOutOfBounds(usize),
IncompatibleSchemaVersion {
database_schema_version: u64,
software_schema_version: u64,
},
ConfigInvalidChunkSize {
chunk_size: usize,
history_length: usize,
},
ConfigInvalidHistoryLength {
history_length: usize,
max_history_length: usize,
},
ConfigInvalidZeroParameter {
config: Config,
},
ConfigIncompatible {
on_disk_config: DiskConfig,
config: DiskConfig,
},
ConfigMissing,
DistanceTooLarge,
DistanceCalculationOverflow,
/// Missing an attester record that we expected to exist.
MissingAttesterRecord {
validator_index: u64,
target_epoch: Epoch,
},
AttesterRecordCorrupt {
length: usize,
},
AttesterKeyCorrupt {
length: usize,
},
ProposerKeyCorrupt {
length: usize,
},
IndexedAttestationIdKeyCorrupt {
length: usize,
},
IndexedAttestationIdCorrupt {
length: usize,
},
MissingIndexedAttestation {
id: u64,
},
MissingAttesterKey,
MissingProposerKey,
MissingIndexedAttestationId,
MissingIndexedAttestationIdKey,
InconsistentAttestationDataRoot,
MissingKey,
}
#[cfg(feature = "mdbx")]
impl From<mdbx::Error> for Error {
fn from(e: mdbx::Error) -> Self {
match e {
mdbx::Error::Other(os_error) => Error::from(io::Error::from_raw_os_error(os_error)),
_ => Error::DatabaseMdbxError(e),
}
}
}
#[cfg(feature = "lmdb")]
impl From<lmdb::Error> for Error {
fn from(e: lmdb::Error) -> Self {
match e {
lmdb::Error::Other(os_error) => Error::from(io::Error::from_raw_os_error(os_error)),
_ => Error::DatabaseLmdbError(e),
}
}
}
#[cfg(feature = "redb")]
impl From<redb::TableError> for Error {
fn from(e: redb::TableError) -> Self {
Error::DatabaseRedbError(e.into())
}
}
#[cfg(feature = "redb")]
impl From<redb::TransactionError> for Error {
fn from(e: redb::TransactionError) -> Self {
Error::DatabaseRedbError(e.into())
}
}
#[cfg(feature = "redb")]
impl From<redb::DatabaseError> for Error {
fn from(e: redb::DatabaseError) -> Self {
Error::DatabaseRedbError(e.into())
}
}
#[cfg(feature = "redb")]
impl From<redb::StorageError> for Error {
fn from(e: redb::StorageError) -> Self {
Error::DatabaseRedbError(e.into())
}
}
#[cfg(feature = "redb")]
impl From<redb::CommitError> for Error {
fn from(e: redb::CommitError) -> Self {
Error::DatabaseRedbError(e.into())
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::DatabaseIOError(e)
}
}
impl From<ssz::DecodeError> for Error {
fn from(e: ssz::DecodeError) -> Self {
Error::SszDecodeError(e)
}
}
impl From<ssz_types::Error> for Error {
fn from(e: ssz_types::Error) -> Self {
Error::SszTypesError(e)
}
}
impl From<bincode::Error> for Error {
fn from(e: bincode::Error) -> Self {
Error::BincodeError(e)
}
}
impl From<safe_arith::ArithError> for Error {
fn from(e: safe_arith::ArithError) -> Self {
Error::ArithError(e)
}
}