Make DAG construction more permissive (#7460)

Workaround/fix for:

- https://github.com/sigp/lighthouse/issues/7323


  - Remove the `StateSummariesNotContiguousError`. This allows us to continue with DAG construction and pruning, even in the case where the DAG is disjointed. We will treat any disjoint summaries as roots of their own tree, and prune them (as they are not descended from finalized). This should be safe, as canonical summaries should not be disjoint (if they are, then the DB is already corrupt).
This commit is contained in:
Michael Sproul
2025-05-15 12:15:35 +10:00
committed by GitHub
parent 851ee2bced
commit c2c7fb87a8
4 changed files with 31 additions and 37 deletions

View File

@@ -41,7 +41,7 @@ pub fn upgrade_to_v22<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
genesis_state_root: Option<Hash256>,
) -> Result<(), Error> {
info!("Upgrading from v21 to v22");
info!("Upgrading DB schema from v21 to v22");
let old_anchor = db.get_anchor_info();

View File

@@ -8,6 +8,7 @@ use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use std::sync::Arc;
use store::{DBColumn, Error, HotColdDB, KeyValueStore, KeyValueStoreOp, StoreItem};
use tracing::{debug, info};
use types::{Hash256, Slot};
/// Dummy value to use for the canonical head block root, see below.
@@ -16,6 +17,8 @@ pub const DUMMY_CANONICAL_HEAD_BLOCK_ROOT: Hash256 = Hash256::repeat_byte(0xff);
pub fn upgrade_to_v23<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
) -> Result<Vec<KeyValueStoreOp>, Error> {
info!("Upgrading DB schema from v22 to v23");
// 1) Set the head-tracker to empty
let Some(persisted_beacon_chain_v22) =
db.get_item::<PersistedBeaconChainV22>(&BEACON_CHAIN_DB_KEY)?
@@ -37,10 +40,24 @@ pub fn upgrade_to_v23<T: BeaconChainTypes>(
.hot_db
.iter_column_keys::<Hash256>(DBColumn::BeaconStateTemporary)
{
let state_root = state_root_result?;
debug!(
?state_root,
"Deleting temporary state flag on v23 schema migration"
);
ops.push(KeyValueStoreOp::DeleteKey(
DBColumn::BeaconStateTemporary,
state_root_result?.as_slice().to_vec(),
state_root.as_slice().to_vec(),
));
// Here we SHOULD delete the items for key `state_root` in columns `BeaconState` and
// `BeaconStateSummary`. However, in the event we have dangling temporary states at the time
// of the migration, the first pruning routine will prune them. They will be a tree branch /
// root not part of the finalized tree and trigger a warning log once.
//
// We believe there may be race conditions concerning temporary flags where a necessary
// canonical state is marked as temporary. In current stable, a restart with that DB will
// corrupt the DB. In the unlikely case this happens we choose to leave the states and
// allow pruning to clean them.
}
Ok(ops)