## Proposed Changes
Enable multiple database backends for the slasher, either MDBX (default) or LMDB. The backend can be selected using `--slasher-backend={lmdb,mdbx}`.
## Additional Info
In order to abstract over the two library's different handling of database lifetimes I've used `Box::leak` to give the `Environment` type a `'static` lifetime. This was the only way I could think of using 100% safe code to construct a self-referential struct `SlasherDB`, where the `OpenDatabases` refers to the `Environment`. I think this is OK, as the `Environment` is expected to live for the life of the program, and both database engines leave the database in a consistent state after each write. The memory claimed for memory-mapping will be freed by the OS and appropriately flushed regardless of whether the `Environment` is actually dropped.
We are depending on two `sigp` forks of `libmdbx-rs` and `lmdb-rs`, to give us greater control over MDBX OS support and LMDB's version.
73 lines
2.2 KiB
Rust
73 lines
2.2 KiB
Rust
#![deny(missing_debug_implementations)]
|
|
#![cfg_attr(
|
|
not(any(feature = "mdbx", feature = "lmdb")),
|
|
allow(unused, clippy::drop_non_drop)
|
|
)]
|
|
|
|
mod array;
|
|
mod attestation_queue;
|
|
mod attester_record;
|
|
mod batch_stats;
|
|
mod block_queue;
|
|
pub mod config;
|
|
mod database;
|
|
mod error;
|
|
pub mod metrics;
|
|
mod migrate;
|
|
mod slasher;
|
|
pub mod test_utils;
|
|
|
|
pub use crate::slasher::Slasher;
|
|
pub use attestation_queue::{AttestationBatch, AttestationQueue, SimpleBatch};
|
|
pub use attester_record::{AttesterRecord, CompactAttesterRecord, IndexedAttesterRecord};
|
|
pub use block_queue::BlockQueue;
|
|
pub use config::{Config, DatabaseBackend};
|
|
pub use database::{
|
|
interface::{Database, Environment, RwTransaction},
|
|
IndexedAttestationId, SlasherDB,
|
|
};
|
|
pub use error::Error;
|
|
|
|
use types::{AttesterSlashing, EthSpec, IndexedAttestation, ProposerSlashing};
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum AttesterSlashingStatus<E: EthSpec> {
|
|
NotSlashable,
|
|
/// A weird outcome that can occur when we go to lookup an attestation by its target
|
|
/// epoch for a surround slashing, but find a different attestation -- indicating that
|
|
/// the validator has already been caught double voting.
|
|
AlreadyDoubleVoted,
|
|
DoubleVote(Box<IndexedAttestation<E>>),
|
|
SurroundsExisting(Box<IndexedAttestation<E>>),
|
|
SurroundedByExisting(Box<IndexedAttestation<E>>),
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum ProposerSlashingStatus {
|
|
NotSlashable,
|
|
DoubleVote(Box<ProposerSlashing>),
|
|
}
|
|
|
|
impl<E: EthSpec> AttesterSlashingStatus<E> {
|
|
pub fn into_slashing(
|
|
self,
|
|
new_attestation: &IndexedAttestation<E>,
|
|
) -> Option<AttesterSlashing<E>> {
|
|
use AttesterSlashingStatus::*;
|
|
|
|
// The surrounding attestation must be in `attestation_1` to be valid.
|
|
match self {
|
|
NotSlashable => None,
|
|
AlreadyDoubleVoted => None,
|
|
DoubleVote(existing) | SurroundedByExisting(existing) => Some(AttesterSlashing {
|
|
attestation_1: *existing,
|
|
attestation_2: new_attestation.clone(),
|
|
}),
|
|
SurroundsExisting(existing) => Some(AttesterSlashing {
|
|
attestation_1: new_attestation.clone(),
|
|
attestation_2: *existing,
|
|
}),
|
|
}
|
|
}
|
|
}
|