mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 21:08:32 +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:
@@ -1,10 +1,11 @@
|
||||
//! Garbage collection process that runs at start-up to clean up the database.
|
||||
use crate::database::interface::BeaconNodeBackend;
|
||||
use crate::hot_cold_store::HotColdDB;
|
||||
use crate::{Error, LevelDB, StoreOp};
|
||||
use crate::{DBColumn, Error};
|
||||
use slog::debug;
|
||||
use types::EthSpec;
|
||||
|
||||
impl<E> HotColdDB<E, LevelDB<E>, LevelDB<E>>
|
||||
impl<E> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>>
|
||||
where
|
||||
E: EthSpec,
|
||||
{
|
||||
@@ -16,21 +17,22 @@ where
|
||||
|
||||
/// Delete the temporary states that were leftover by failed block imports.
|
||||
pub fn delete_temp_states(&self) -> Result<(), Error> {
|
||||
let delete_ops =
|
||||
self.iter_temporary_state_roots()
|
||||
.try_fold(vec![], |mut ops, state_root| {
|
||||
let state_root = state_root?;
|
||||
ops.push(StoreOp::DeleteState(state_root, None));
|
||||
Result::<_, Error>::Ok(ops)
|
||||
})?;
|
||||
|
||||
if !delete_ops.is_empty() {
|
||||
let mut ops = vec![];
|
||||
self.iter_temporary_state_roots().for_each(|state_root| {
|
||||
if let Ok(state_root) = state_root {
|
||||
ops.push(state_root);
|
||||
}
|
||||
});
|
||||
if !ops.is_empty() {
|
||||
debug!(
|
||||
self.log,
|
||||
"Garbage collecting {} temporary states",
|
||||
delete_ops.len()
|
||||
ops.len()
|
||||
);
|
||||
self.do_atomically_with_block_and_blobs_cache(delete_ops)?;
|
||||
|
||||
self.delete_batch(DBColumn::BeaconState, ops.clone())?;
|
||||
self.delete_batch(DBColumn::BeaconStateSummary, ops.clone())?;
|
||||
self.delete_batch(DBColumn::BeaconStateTemporary, ops)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user