mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-01 03:33:47 +00:00
Tweak slasher DB schema and pruning (#1948)
## Issue Addressed Resolves #1890 ## Proposed Changes Change the slasher database schema to key indexed attestations by `(target_epoch, indexed_attestation_root)` instead of just `indexed_attestation_root`. This allows more straight-forward pruning (linear scan), that is also "re-entrant". By re-entrant, we mean that a pruning pass that gets stuck because of a `MapFull` error can attempt to commit midway, and be resumed later without issue. The previous pruning strategy for indexed attestations did not have this property. There was also a flaw in the previous pruning that could leave "zombie" indexed attestations in the database (ones not referenced by any attester record), which could build up and contribute to bloat (although in practice I think they occur quite infrequently). ## Additional Info During testing I noticed that a `MapFull` error can still occur during the commit of the transaction itself, which is irritating, but not unbearable. This PR should at least reduce the frequency with which users need to manually resize their DB, and if the `MapFull` on commit rears its ugly head too often we could use a dynamic strategy (temporarily increase the size of the map until the transaction commits). The extra bytes for the epoch make the database a bit heavier, so the size estimate docs have been updated to reflect this. This is also a breaking schema change, so anyone using a v0 database from a few hours ago will need to drop it and update 😅
This commit is contained in:
@@ -7,7 +7,7 @@ pub const DEFAULT_CHUNK_SIZE: usize = 16;
|
||||
pub const DEFAULT_VALIDATOR_CHUNK_SIZE: usize = 256;
|
||||
pub const DEFAULT_HISTORY_LENGTH: usize = 4096;
|
||||
pub const DEFAULT_UPDATE_PERIOD: u64 = 12;
|
||||
pub const DEFAULT_MAX_DB_SIZE: usize = 256;
|
||||
pub const DEFAULT_MAX_DB_SIZE: usize = 256 * 1024; // 256 GiB
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
@@ -18,8 +18,8 @@ pub struct Config {
|
||||
pub history_length: usize,
|
||||
/// Update frequency in seconds.
|
||||
pub update_period: u64,
|
||||
/// Maximum size of the LMDB database in gigabytes.
|
||||
pub max_db_size_gbs: usize,
|
||||
/// Maximum size of the LMDB database in megabytes.
|
||||
pub max_db_size_mbs: usize,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -30,7 +30,7 @@ impl Config {
|
||||
validator_chunk_size: DEFAULT_VALIDATOR_CHUNK_SIZE,
|
||||
history_length: DEFAULT_HISTORY_LENGTH,
|
||||
update_period: DEFAULT_UPDATE_PERIOD,
|
||||
max_db_size_gbs: DEFAULT_MAX_DB_SIZE,
|
||||
max_db_size_mbs: DEFAULT_MAX_DB_SIZE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl Config {
|
||||
if self.chunk_size == 0
|
||||
|| self.validator_chunk_size == 0
|
||||
|| self.history_length == 0
|
||||
|| self.max_db_size_gbs == 0
|
||||
|| self.max_db_size_mbs == 0
|
||||
{
|
||||
Err(Error::ConfigInvalidZeroParameter {
|
||||
config: self.clone(),
|
||||
|
||||
Reference in New Issue
Block a user