Skip to content

Commit 03fece6

Browse files
committed
Skip migrating pre-split states in downgrade
1 parent f0823fe commit 03fece6

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

beacon_node/beacon_chain/src/schema_change/migration_schema_v24.rs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ pub fn downgrade_from_v24<T: BeaconChainTypes>(
484484
let mut migrate_ops = vec![];
485485
let mut states_written = 0;
486486
let mut summaries_written = 0;
487+
let mut summaries_skipped = 0;
487488
let mut last_log_time = Instant::now();
488489

489490
// Rebuild the PruningCheckpoint from the split.
@@ -502,6 +503,18 @@ pub fn downgrade_from_v24<T: BeaconChainTypes>(
502503
.into_iter()
503504
.flat_map(|(_, summaries)| summaries)
504505
{
506+
// No need to migrate any states prior to the split. The v22 schema does not need them, and
507+
// they would generate warnings about a disjoint DAG when re-upgrading to V24.
508+
if summary.slot < split.slot {
509+
debug!(
510+
slot = %summary.slot,
511+
?state_root,
512+
"Skipping migration of pre-split state"
513+
);
514+
summaries_skipped += 1;
515+
continue;
516+
}
517+
505518
// If boundary state: persist.
506519
// Do not cache these states as they are unlikely to be relevant later.
507520
let update_cache = false;
@@ -538,18 +551,6 @@ pub fn downgrade_from_v24<T: BeaconChainTypes>(
538551
));
539552
summaries_written += 1;
540553

541-
// Delete existing data
542-
for db_column in [
543-
DBColumn::BeaconStateHotSummary,
544-
DBColumn::BeaconStateHotDiff,
545-
DBColumn::BeaconStateHotSnapshot,
546-
] {
547-
migrate_ops.push(KeyValueStoreOp::DeleteKey(
548-
db_column,
549-
state_root.as_slice().to_vec(),
550-
));
551-
}
552-
553554
if last_log_time.elapsed() > Duration::from_secs(5) {
554555
last_log_time = Instant::now();
555556
info!(
@@ -561,9 +562,27 @@ pub fn downgrade_from_v24<T: BeaconChainTypes>(
561562
}
562563
}
563564

565+
// Delete all V24 schema data. We do this outside the loop over summaries to ensure we cover
566+
// every piece of data and to simplify logic around skipping certain summaries that do not get
567+
// migrated.
568+
for db_column in [
569+
DBColumn::BeaconStateHotSummary,
570+
DBColumn::BeaconStateHotDiff,
571+
DBColumn::BeaconStateHotSnapshot,
572+
] {
573+
for key in db.hot_db.iter_column_keys::<Hash256>(db_column) {
574+
let state_root = key?;
575+
migrate_ops.push(KeyValueStoreOp::DeleteKey(
576+
db_column,
577+
state_root.as_slice().to_vec(),
578+
));
579+
}
580+
}
581+
564582
info!(
565583
states_written,
566584
summaries_written,
585+
summaries_skipped,
567586
summaries_count = state_summaries_dag.summaries_count(),
568587
"DB downgrade of v24 state summaries completed"
569588
);

0 commit comments

Comments
 (0)