Optionally check DB invariants at runtime (#8952)

Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
Lion - dapplion
2026-03-11 01:20:02 -05:00
committed by GitHub
parent 815040dc3c
commit 6350a27031
8 changed files with 918 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ use beacon_chain::store::metadata::CURRENT_SCHEMA_VERSION;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use serde::Serialize;
use std::sync::Arc;
use store::invariants::InvariantCheckResult;
use store::{AnchorInfo, BlobInfo, Split, StoreConfig};
#[derive(Debug, Serialize)]
@@ -30,3 +31,11 @@ pub fn info<T: BeaconChainTypes>(
blob_info,
})
}
pub fn check_invariants<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
) -> Result<InvariantCheckResult, warp::Rejection> {
chain.check_database_invariants().map_err(|e| {
warp_utils::reject::custom_bad_request(format!("error checking database invariants: {e:?}"))
})
}

View File

@@ -3007,6 +3007,19 @@ pub fn serve<T: BeaconChainTypes>(
},
);
// GET lighthouse/database/invariants
let get_lighthouse_database_invariants = database_path
.and(warp::path("invariants"))
.and(warp::path::end())
.and(task_spawner_filter.clone())
.and(chain_filter.clone())
.then(
|task_spawner: TaskSpawner<T::EthSpec>, chain: Arc<BeaconChain<T>>| {
task_spawner
.blocking_json_task(Priority::P1, move || database::check_invariants(chain))
},
);
// POST lighthouse/database/reconstruct
let post_lighthouse_database_reconstruct = database_path
.and(warp::path("reconstruct"))
@@ -3336,6 +3349,7 @@ pub fn serve<T: BeaconChainTypes>(
.uor(get_lighthouse_validator_inclusion)
.uor(get_lighthouse_staking)
.uor(get_lighthouse_database_info)
.uor(get_lighthouse_database_invariants)
.uor(get_lighthouse_custody_info)
.uor(get_lighthouse_attestation_performance)
.uor(get_beacon_light_client_optimistic_update)