Skip to content

Commit 5d8ddb6

Browse files
committed
Delete temporary states on migration
1 parent a4f442c commit 5d8ddb6

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

beacon_node/beacon_chain/src/schema_change/migration_schema_v23.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,26 @@ pub fn upgrade_to_v23<T: BeaconChainTypes>(
4343
let state_root = state_root_result?;
4444
debug!(
4545
?state_root,
46-
"Deleting temporary state flag on v23 schema migration"
46+
"Deleting temporary state on v23 schema migration"
4747
);
4848
ops.push(KeyValueStoreOp::DeleteKey(
4949
DBColumn::BeaconStateTemporary,
5050
state_root.as_slice().to_vec(),
5151
));
52-
// Here we SHOULD delete the items for key `state_root` in columns `BeaconState` and
53-
// `BeaconStateSummary`. However, in the event we have dangling temporary states at the time
54-
// of the migration, the first pruning routine will prune them. They will be a tree branch /
55-
// root not part of the finalized tree and trigger a warning log once.
56-
//
57-
// We believe there may be race conditions concerning temporary flags where a necessary
58-
// canonical state is marked as temporary. In current stable, a restart with that DB will
59-
// corrupt the DB. In the unlikely case this happens we choose to leave the states and
60-
// allow pruning to clean them.
52+
53+
// We also delete the temporary states themselves. Although there are known issue with
54+
// temporary states and this could lead to DB corruption, we will only corrupt the DB in
55+
// cases where the DB would be corrupted by restarting on v7.0.x. We consider these DBs
56+
// "too far gone". Deleting here has the advantage of not generating warnings about
57+
// disjoint state DAGs in the v24 upgrade, or the first pruning after migration.
58+
ops.push(KeyValueStoreOp::DeleteKey(
59+
DBColumn::BeaconState,
60+
state_root.as_slice().to_vec(),
61+
));
62+
ops.push(KeyValueStoreOp::DeleteKey(
63+
DBColumn::BeaconStateSummary,
64+
state_root.as_slice().to_vec(),
65+
));
6166
}
6267

6368
Ok(ops)

beacon_node/beacon_chain/src/schema_change/migration_schema_v24.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
221221
);
222222

223223
// Upgrade all hot DB state summaries to the new type:
224-
// - Set all summaries of boundary states as `Snapshot` type
225-
// - Set all others are `Replay` pointing to `epoch_boundary_state_root`
224+
// - Set all summaries of boundary states to `Snapshot` type
225+
// - Set all others to `Replay` pointing to `epoch_boundary_state_root`
226226

227227
let mut diffs_written = 0;
228228
let mut summaries_written = 0;

0 commit comments

Comments
 (0)