Pseudo finalization endpoint (#7103)

This is a backport of:
-  https://github.com/sigp/lighthouse/pull/7059
- https://github.com/sigp/lighthouse/pull/7071

For:
- https://github.com/sigp/lighthouse/issues/7039


  Introduce a new lighthouse endpoint that allows a user to force a pseudo finalization. This migrates data to the freezer db and prunes sidechains which may help reduce disk space issues on non finalized networks like Holesky

We also ban peers that send us blocks that conflict with the manually finalized checkpoint.

There were some CI fixes in https://github.com/sigp/lighthouse/pull/7071 that I tried including here

Co-authored with: @jimmygchen  @pawanjay176 @michaelsproul
This commit is contained in:
Eitan Seri-Levi
2025-03-17 23:21:05 -06:00
committed by GitHub
parent 58482586f5
commit 27aabe8159
9 changed files with 353 additions and 23 deletions

View File

@@ -42,7 +42,7 @@ use crate::light_client_optimistic_update_verification::{
Error as LightClientOptimisticUpdateError, VerifiedLightClientOptimisticUpdate,
};
use crate::light_client_server_cache::LightClientServerCache;
use crate::migrate::BackgroundMigrator;
use crate::migrate::{BackgroundMigrator, ManualFinalizationNotification};
use crate::naive_aggregation_pool::{
AggregatedAttestationMap, Error as NaiveAggregationError, NaiveAggregationPool,
SyncContributionAggregateMap,
@@ -118,8 +118,8 @@ use std::sync::Arc;
use std::time::Duration;
use store::iter::{BlockRootsIterator, ParentRootBlockIterator, StateRootsIterator};
use store::{
BlobSidecarListFromRoot, DatabaseBlock, Error as DBError, HotColdDB, KeyValueStore,
KeyValueStoreOp, StoreItem, StoreOp,
BlobSidecarListFromRoot, DatabaseBlock, Error as DBError, HotColdDB, HotStateSummary,
KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
};
use task_executor::{ShutdownReason, TaskExecutor};
use tokio::sync::oneshot;
@@ -1711,6 +1711,41 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
}
pub fn manually_finalize_state(
&self,
state_root: Hash256,
checkpoint: Checkpoint,
) -> Result<(), Error> {
let HotStateSummary {
slot,
latest_block_root,
..
} = self
.store
.load_hot_state_summary(&state_root)
.map_err(BeaconChainError::DBError)?
.ok_or(BeaconChainError::MissingHotStateSummary(state_root))?;
if slot != checkpoint.epoch.start_slot(T::EthSpec::slots_per_epoch())
|| latest_block_root != *checkpoint.root
{
return Err(BeaconChainError::InvalidCheckpoint {
state_root,
checkpoint,
});
}
let notif = ManualFinalizationNotification {
state_root: state_root.into(),
checkpoint,
head_tracker: self.head_tracker.clone(),
genesis_block_root: self.genesis_block_root,
};
self.store_migrator.process_manual_finalization(notif);
Ok(())
}
/// Returns an aggregated `Attestation`, if any, that has a matching `attestation.data`.
///
/// The attestation will be obtained from `self.naive_aggregation_pool`.