mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-22 11:41:28 +00:00
92d597ad23
## 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.
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
#![cfg(any(feature = "mdbx", feature = "lmdb"))]
|
|
|
|
use logging::test_logger;
|
|
use slasher::{test_utils::indexed_att, Config, Slasher};
|
|
use tempfile::tempdir;
|
|
use types::Epoch;
|
|
|
|
#[test]
|
|
fn attestation_pruning_empty_wrap_around() {
|
|
let tempdir = tempdir().unwrap();
|
|
let mut config = Config::new(tempdir.path().into());
|
|
config.validator_chunk_size = 1;
|
|
config.chunk_size = 16;
|
|
config.history_length = 16;
|
|
|
|
let slasher = Slasher::open(config.clone(), test_logger()).unwrap();
|
|
|
|
let v = vec![0];
|
|
let history_length = config.history_length as u64;
|
|
|
|
let mut current_epoch = Epoch::new(history_length - 1);
|
|
|
|
slasher.accept_attestation(indexed_att(v.clone(), 0, history_length - 1, 0));
|
|
slasher.process_queued(current_epoch).unwrap();
|
|
slasher.prune_database(current_epoch).unwrap();
|
|
|
|
// Delete the previous attestation
|
|
current_epoch = Epoch::new(2 * history_length + 2);
|
|
slasher.prune_database(current_epoch).unwrap();
|
|
|
|
// Add an attestation that would be surrounded with the modulo considered
|
|
slasher.accept_attestation(indexed_att(
|
|
v,
|
|
2 * history_length - 3,
|
|
2 * history_length - 2,
|
|
1,
|
|
));
|
|
slasher.process_queued(current_epoch).unwrap();
|
|
}
|