mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Modularize beacon node backend (#4718)
#4669 Modularize the beacon node backend to make it easier to add new database implementations
This commit is contained in:
@@ -16,10 +16,12 @@ use slog::{info, warn, Logger};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use store::KeyValueStore;
|
||||
use store::{
|
||||
database::interface::BeaconNodeBackend,
|
||||
errors::Error,
|
||||
metadata::{SchemaVersion, CURRENT_SCHEMA_VERSION},
|
||||
DBColumn, HotColdDB, KeyValueStore, LevelDB,
|
||||
DBColumn, HotColdDB,
|
||||
};
|
||||
use strum::{EnumString, EnumVariantNames};
|
||||
use types::{BeaconState, EthSpec, Slot};
|
||||
@@ -40,7 +42,7 @@ fn parse_client_config<E: EthSpec>(
|
||||
.clone_from(&database_manager_config.blobs_dir);
|
||||
client_config.store.blob_prune_margin_epochs = database_manager_config.blob_prune_margin_epochs;
|
||||
client_config.store.hierarchy_config = database_manager_config.hierarchy_exponents.clone();
|
||||
|
||||
client_config.store.backend = database_manager_config.backend;
|
||||
Ok(client_config)
|
||||
}
|
||||
|
||||
@@ -55,7 +57,7 @@ pub fn display_db_version<E: EthSpec>(
|
||||
let blobs_path = client_config.get_blobs_db_path();
|
||||
|
||||
let mut version = CURRENT_SCHEMA_VERSION;
|
||||
HotColdDB::<E, LevelDB<E>, LevelDB<E>>::open(
|
||||
HotColdDB::<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>>::open(
|
||||
&hot_path,
|
||||
&cold_path,
|
||||
&blobs_path,
|
||||
@@ -145,11 +147,14 @@ pub fn inspect_db<E: EthSpec>(
|
||||
let mut num_keys = 0;
|
||||
|
||||
let sub_db = if inspect_config.freezer {
|
||||
LevelDB::<E>::open(&cold_path).map_err(|e| format!("Unable to open freezer DB: {e:?}"))?
|
||||
BeaconNodeBackend::<E>::open(&client_config.store, &cold_path)
|
||||
.map_err(|e| format!("Unable to open freezer DB: {e:?}"))?
|
||||
} else if inspect_config.blobs_db {
|
||||
LevelDB::<E>::open(&blobs_path).map_err(|e| format!("Unable to open blobs DB: {e:?}"))?
|
||||
BeaconNodeBackend::<E>::open(&client_config.store, &blobs_path)
|
||||
.map_err(|e| format!("Unable to open blobs DB: {e:?}"))?
|
||||
} else {
|
||||
LevelDB::<E>::open(&hot_path).map_err(|e| format!("Unable to open hot DB: {e:?}"))?
|
||||
BeaconNodeBackend::<E>::open(&client_config.store, &hot_path)
|
||||
.map_err(|e| format!("Unable to open hot DB: {e:?}"))?
|
||||
};
|
||||
|
||||
let skip = inspect_config.skip.unwrap_or(0);
|
||||
@@ -263,11 +268,20 @@ pub fn compact_db<E: EthSpec>(
|
||||
let column = compact_config.column;
|
||||
|
||||
let (sub_db, db_name) = if compact_config.freezer {
|
||||
(LevelDB::<E>::open(&cold_path)?, "freezer_db")
|
||||
(
|
||||
BeaconNodeBackend::<E>::open(&client_config.store, &cold_path)?,
|
||||
"freezer_db",
|
||||
)
|
||||
} else if compact_config.blobs_db {
|
||||
(LevelDB::<E>::open(&blobs_path)?, "blobs_db")
|
||||
(
|
||||
BeaconNodeBackend::<E>::open(&client_config.store, &blobs_path)?,
|
||||
"blobs_db",
|
||||
)
|
||||
} else {
|
||||
(LevelDB::<E>::open(&hot_path)?, "hot_db")
|
||||
(
|
||||
BeaconNodeBackend::<E>::open(&client_config.store, &hot_path)?,
|
||||
"hot_db",
|
||||
)
|
||||
};
|
||||
info!(
|
||||
log,
|
||||
@@ -303,7 +317,7 @@ pub fn migrate_db<E: EthSpec>(
|
||||
|
||||
let mut from = CURRENT_SCHEMA_VERSION;
|
||||
let to = migrate_config.to;
|
||||
let db = HotColdDB::<E, LevelDB<E>, LevelDB<E>>::open(
|
||||
let db = HotColdDB::<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>>::open(
|
||||
&hot_path,
|
||||
&cold_path,
|
||||
&blobs_path,
|
||||
@@ -343,7 +357,7 @@ pub fn prune_payloads<E: EthSpec>(
|
||||
let cold_path = client_config.get_freezer_db_path();
|
||||
let blobs_path = client_config.get_blobs_db_path();
|
||||
|
||||
let db = HotColdDB::<E, LevelDB<E>, LevelDB<E>>::open(
|
||||
let db = HotColdDB::<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>>::open(
|
||||
&hot_path,
|
||||
&cold_path,
|
||||
&blobs_path,
|
||||
@@ -369,7 +383,7 @@ pub fn prune_blobs<E: EthSpec>(
|
||||
let cold_path = client_config.get_freezer_db_path();
|
||||
let blobs_path = client_config.get_blobs_db_path();
|
||||
|
||||
let db = HotColdDB::<E, LevelDB<E>, LevelDB<E>>::open(
|
||||
let db = HotColdDB::<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>>::open(
|
||||
&hot_path,
|
||||
&cold_path,
|
||||
&blobs_path,
|
||||
@@ -406,7 +420,7 @@ pub fn prune_states<E: EthSpec>(
|
||||
let cold_path = client_config.get_freezer_db_path();
|
||||
let blobs_path = client_config.get_blobs_db_path();
|
||||
|
||||
let db = HotColdDB::<E, LevelDB<E>, LevelDB<E>>::open(
|
||||
let db = HotColdDB::<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>>::open(
|
||||
&hot_path,
|
||||
&cold_path,
|
||||
&blobs_path,
|
||||
|
||||
Reference in New Issue
Block a user