Skip to content

Commit 84392d6

Browse files
committed
Delete DB schema migrations for v11 and earlier (sigp#3761)
## Proposed Changes Now that the Gnosis merge is scheduled, all users should have upgraded beyond Lighthouse v3.0.0. Accordingly we can delete schema migrations for versions prior to v3.0.0. ## Additional Info I also deleted the state cache stuff I added in sigp#3714 as it turned out to be useless for the light client proofs due to the one-slot offset.
1 parent 18c9be5 commit 84392d6

14 files changed

+15
-1354
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -997,46 +997,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
997997
Ok(self.store.get_state(state_root, slot)?)
998998
}
999999

1000-
/// Run a function with mutable access to a state for `block_root`.
1001-
///
1002-
/// The primary purpose of this function is to borrow a state with its tree hash cache
1003-
/// from the snapshot cache *without moving it*. This means that calls to this function should
1004-
/// be kept to an absolute minimum, because holding the snapshot cache lock has the ability
1005-
/// to delay block import.
1006-
///
1007-
/// If there is no appropriate state in the snapshot cache then one will be loaded from disk.
1008-
/// If no state is found on disk then `Ok(None)` will be returned.
1009-
///
1010-
/// The 2nd parameter to the closure is a bool indicating whether the snapshot cache was used,
1011-
/// which can inform logging/metrics.
1012-
///
1013-
/// NOTE: the medium-term plan is to delete this function and the snapshot cache in favour
1014-
/// of `tree-states`, where all caches are CoW and everything is good in the world.
1015-
pub fn with_mutable_state_for_block<F, V, Payload: ExecPayload<T::EthSpec>>(
1016-
&self,
1017-
block: &SignedBeaconBlock<T::EthSpec, Payload>,
1018-
block_root: Hash256,
1019-
f: F,
1020-
) -> Result<Option<V>, Error>
1021-
where
1022-
F: FnOnce(&mut BeaconState<T::EthSpec>, bool) -> Result<V, Error>,
1023-
{
1024-
if let Some(state) = self
1025-
.snapshot_cache
1026-
.try_write_for(BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT)
1027-
.ok_or(Error::SnapshotCacheLockTimeout)?
1028-
.borrow_unadvanced_state_mut(block_root)
1029-
{
1030-
let cache_hit = true;
1031-
f(state, cache_hit).map(Some)
1032-
} else if let Some(mut state) = self.get_state(&block.state_root(), Some(block.slot()))? {
1033-
let cache_hit = false;
1034-
f(&mut state, cache_hit).map(Some)
1035-
} else {
1036-
Ok(None)
1037-
}
1038-
}
1039-
10401000
/// Return the sync committee at `slot + 1` from the canonical chain.
10411001
///
10421002
/// This is useful when dealing with sync committee messages, because messages are signed

beacon_node/beacon_chain/src/beacon_fork_choice_store.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn get_effective_balances<T: EthSpec>(state: &BeaconState<T>) -> Vec<u64> {
6161
}
6262

6363
#[superstruct(
64-
variants(V1, V8),
64+
variants(V8),
6565
variant_attributes(derive(PartialEq, Clone, Debug, Encode, Decode)),
6666
no_enum
6767
)]
@@ -75,13 +75,11 @@ pub(crate) struct CacheItem {
7575
pub(crate) type CacheItem = CacheItemV8;
7676

7777
#[superstruct(
78-
variants(V1, V8),
78+
variants(V8),
7979
variant_attributes(derive(PartialEq, Clone, Default, Debug, Encode, Decode)),
8080
no_enum
8181
)]
8282
pub struct BalancesCache {
83-
#[superstruct(only(V1))]
84-
pub(crate) items: Vec<CacheItemV1>,
8583
#[superstruct(only(V8))]
8684
pub(crate) items: Vec<CacheItemV8>,
8785
}
@@ -366,26 +364,20 @@ where
366364
}
367365

368366
/// A container which allows persisting the `BeaconForkChoiceStore` to the on-disk database.
369-
#[superstruct(
370-
variants(V1, V7, V8, V10, V11),
371-
variant_attributes(derive(Encode, Decode)),
372-
no_enum
373-
)]
367+
#[superstruct(variants(V11), variant_attributes(derive(Encode, Decode)), no_enum)]
374368
pub struct PersistedForkChoiceStore {
375-
#[superstruct(only(V1, V7))]
376-
pub balances_cache: BalancesCacheV1,
377-
#[superstruct(only(V8, V10, V11))]
369+
#[superstruct(only(V11))]
378370
pub balances_cache: BalancesCacheV8,
379371
pub time: Slot,
380372
pub finalized_checkpoint: Checkpoint,
381373
pub justified_checkpoint: Checkpoint,
382374
pub justified_balances: Vec<u64>,
383375
pub best_justified_checkpoint: Checkpoint,
384-
#[superstruct(only(V10, V11))]
376+
#[superstruct(only(V11))]
385377
pub unrealized_justified_checkpoint: Checkpoint,
386-
#[superstruct(only(V10, V11))]
378+
#[superstruct(only(V11))]
387379
pub unrealized_finalized_checkpoint: Checkpoint,
388-
#[superstruct(only(V7, V8, V10, V11))]
380+
#[superstruct(only(V11))]
389381
pub proposer_boost_root: Hash256,
390382
#[superstruct(only(V11))]
391383
pub equivocating_indices: BTreeSet<u64>,
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::beacon_fork_choice_store::{
2-
PersistedForkChoiceStoreV1, PersistedForkChoiceStoreV10, PersistedForkChoiceStoreV11,
3-
PersistedForkChoiceStoreV7, PersistedForkChoiceStoreV8,
4-
};
1+
use crate::beacon_fork_choice_store::PersistedForkChoiceStoreV11;
52
use ssz::{Decode, Encode};
63
use ssz_derive::{Decode, Encode};
74
use store::{DBColumn, Error, StoreItem};
@@ -10,21 +7,9 @@ use superstruct::superstruct;
107
// If adding a new version you should update this type alias and fix the breakages.
118
pub type PersistedForkChoice = PersistedForkChoiceV11;
129

13-
#[superstruct(
14-
variants(V1, V7, V8, V10, V11),
15-
variant_attributes(derive(Encode, Decode)),
16-
no_enum
17-
)]
10+
#[superstruct(variants(V11), variant_attributes(derive(Encode, Decode)), no_enum)]
1811
pub struct PersistedForkChoice {
1912
pub fork_choice: fork_choice::PersistedForkChoice,
20-
#[superstruct(only(V1))]
21-
pub fork_choice_store: PersistedForkChoiceStoreV1,
22-
#[superstruct(only(V7))]
23-
pub fork_choice_store: PersistedForkChoiceStoreV7,
24-
#[superstruct(only(V8))]
25-
pub fork_choice_store: PersistedForkChoiceStoreV8,
26-
#[superstruct(only(V10))]
27-
pub fork_choice_store: PersistedForkChoiceStoreV10,
2813
#[superstruct(only(V11))]
2914
pub fork_choice_store: PersistedForkChoiceStoreV11,
3015
}
@@ -47,8 +32,4 @@ macro_rules! impl_store_item {
4732
};
4833
}
4934

50-
impl_store_item!(PersistedForkChoiceV1);
51-
impl_store_item!(PersistedForkChoiceV7);
52-
impl_store_item!(PersistedForkChoiceV8);
53-
impl_store_item!(PersistedForkChoiceV10);
5435
impl_store_item!(PersistedForkChoiceV11);

beacon_node/beacon_chain/src/schema_change.rs

Lines changed: 3 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
//! Utilities for managing database schema changes.
2-
mod migration_schema_v10;
3-
mod migration_schema_v11;
42
mod migration_schema_v12;
53
mod migration_schema_v13;
6-
mod migration_schema_v6;
7-
mod migration_schema_v7;
8-
mod migration_schema_v8;
9-
mod migration_schema_v9;
10-
mod types;
114

12-
use crate::beacon_chain::{BeaconChainTypes, ETH1_CACHE_DB_KEY, FORK_CHOICE_DB_KEY};
5+
use crate::beacon_chain::{BeaconChainTypes, ETH1_CACHE_DB_KEY};
136
use crate::eth1_chain::SszEth1;
14-
use crate::persisted_fork_choice::{
15-
PersistedForkChoiceV1, PersistedForkChoiceV10, PersistedForkChoiceV11, PersistedForkChoiceV7,
16-
PersistedForkChoiceV8,
17-
};
187
use crate::types::ChainSpec;
198
use slog::{warn, Logger};
209
use std::sync::Arc;
@@ -23,6 +12,7 @@ use store::metadata::{SchemaVersion, CURRENT_SCHEMA_VERSION};
2312
use store::{Error as StoreError, StoreItem};
2413

2514
/// Migrate the database from one schema version to another, applying all requisite mutations.
15+
#[allow(clippy::only_used_in_recursion)] // spec is not used but likely to be used in future
2616
pub fn migrate_schema<T: BeaconChainTypes>(
2717
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
2818
deposit_contract_deploy_block: u64,
@@ -62,156 +52,9 @@ pub fn migrate_schema<T: BeaconChainTypes>(
6252
}
6353

6454
//
65-
// Migrations from before SchemaVersion(5) are deprecated.
55+
// Migrations from before SchemaVersion(11) are deprecated.
6656
//
6757

68-
// Migration for adding `execution_status` field to the fork choice store.
69-
(SchemaVersion(5), SchemaVersion(6)) => {
70-
// Database operations to be done atomically
71-
let mut ops = vec![];
72-
73-
// The top-level `PersistedForkChoice` struct is still V1 but will have its internal
74-
// bytes for the fork choice updated to V6.
75-
let fork_choice_opt = db.get_item::<PersistedForkChoiceV1>(&FORK_CHOICE_DB_KEY)?;
76-
if let Some(mut persisted_fork_choice) = fork_choice_opt {
77-
migration_schema_v6::update_execution_statuses::<T>(&mut persisted_fork_choice)
78-
.map_err(StoreError::SchemaMigrationError)?;
79-
80-
// Store the converted fork choice store under the same key.
81-
ops.push(persisted_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
82-
}
83-
84-
db.store_schema_version_atomically(to, ops)?;
85-
86-
Ok(())
87-
}
88-
// 1. Add `proposer_boost_root`.
89-
// 2. Update `justified_epoch` to `justified_checkpoint` and `finalized_epoch` to
90-
// `finalized_checkpoint`.
91-
// 3. This migration also includes a potential update to the justified
92-
// checkpoint in case the fork choice store's justified checkpoint and finalized checkpoint
93-
// combination does not actually exist for any blocks in fork choice. This was possible in
94-
// the consensus spec prior to v1.1.6.
95-
//
96-
// Relevant issues:
97-
//
98-
// https://github.com/sigp/lighthouse/issues/2741
99-
// https://github.com/ethereum/consensus-specs/pull/2727
100-
// https://github.com/ethereum/consensus-specs/pull/2730
101-
(SchemaVersion(6), SchemaVersion(7)) => {
102-
// Database operations to be done atomically
103-
let mut ops = vec![];
104-
105-
let fork_choice_opt = db.get_item::<PersistedForkChoiceV1>(&FORK_CHOICE_DB_KEY)?;
106-
if let Some(persisted_fork_choice_v1) = fork_choice_opt {
107-
// This migrates the `PersistedForkChoiceStore`, adding the `proposer_boost_root` field.
108-
let mut persisted_fork_choice_v7 = persisted_fork_choice_v1.into();
109-
110-
let result = migration_schema_v7::update_fork_choice::<T>(
111-
&mut persisted_fork_choice_v7,
112-
db.clone(),
113-
);
114-
115-
// Fall back to re-initializing fork choice from an anchor state if necessary.
116-
if let Err(e) = result {
117-
warn!(log, "Unable to migrate to database schema 7, re-initializing fork choice"; "error" => ?e);
118-
migration_schema_v7::update_with_reinitialized_fork_choice::<T>(
119-
&mut persisted_fork_choice_v7,
120-
db.clone(),
121-
spec,
122-
)
123-
.map_err(StoreError::SchemaMigrationError)?;
124-
}
125-
126-
// Store the converted fork choice store under the same key.
127-
ops.push(persisted_fork_choice_v7.as_kv_store_op(FORK_CHOICE_DB_KEY));
128-
}
129-
130-
db.store_schema_version_atomically(to, ops)?;
131-
132-
Ok(())
133-
}
134-
// Migration to add an `epoch` key to the fork choice's balances cache.
135-
(SchemaVersion(7), SchemaVersion(8)) => {
136-
let mut ops = vec![];
137-
let fork_choice_opt = db.get_item::<PersistedForkChoiceV7>(&FORK_CHOICE_DB_KEY)?;
138-
if let Some(fork_choice) = fork_choice_opt {
139-
let updated_fork_choice =
140-
migration_schema_v8::update_fork_choice::<T>(fork_choice, db.clone())?;
141-
142-
ops.push(updated_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
143-
}
144-
145-
db.store_schema_version_atomically(to, ops)?;
146-
147-
Ok(())
148-
}
149-
// Upgrade from v8 to v9 to separate the execution payloads into their own column.
150-
(SchemaVersion(8), SchemaVersion(9)) => {
151-
migration_schema_v9::upgrade_to_v9::<T>(db.clone(), log)?;
152-
db.store_schema_version(to)
153-
}
154-
// Downgrade from v9 to v8 to ignore the separation of execution payloads
155-
// NOTE: only works before the Bellatrix fork epoch.
156-
(SchemaVersion(9), SchemaVersion(8)) => {
157-
migration_schema_v9::downgrade_from_v9::<T>(db.clone(), log)?;
158-
db.store_schema_version(to)
159-
}
160-
(SchemaVersion(9), SchemaVersion(10)) => {
161-
let mut ops = vec![];
162-
let fork_choice_opt = db.get_item::<PersistedForkChoiceV8>(&FORK_CHOICE_DB_KEY)?;
163-
if let Some(fork_choice) = fork_choice_opt {
164-
let updated_fork_choice = migration_schema_v10::update_fork_choice(fork_choice)?;
165-
166-
ops.push(updated_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
167-
}
168-
169-
db.store_schema_version_atomically(to, ops)?;
170-
171-
Ok(())
172-
}
173-
(SchemaVersion(10), SchemaVersion(9)) => {
174-
let mut ops = vec![];
175-
let fork_choice_opt = db.get_item::<PersistedForkChoiceV10>(&FORK_CHOICE_DB_KEY)?;
176-
if let Some(fork_choice) = fork_choice_opt {
177-
let updated_fork_choice = migration_schema_v10::downgrade_fork_choice(fork_choice)?;
178-
179-
ops.push(updated_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
180-
}
181-
182-
db.store_schema_version_atomically(to, ops)?;
183-
184-
Ok(())
185-
}
186-
// Upgrade from v10 to v11 adding support for equivocating indices to fork choice.
187-
(SchemaVersion(10), SchemaVersion(11)) => {
188-
let mut ops = vec![];
189-
let fork_choice_opt = db.get_item::<PersistedForkChoiceV10>(&FORK_CHOICE_DB_KEY)?;
190-
if let Some(fork_choice) = fork_choice_opt {
191-
let updated_fork_choice = migration_schema_v11::update_fork_choice(fork_choice);
192-
193-
ops.push(updated_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
194-
}
195-
196-
db.store_schema_version_atomically(to, ops)?;
197-
198-
Ok(())
199-
}
200-
// Downgrade from v11 to v10 removing support for equivocating indices from fork choice.
201-
(SchemaVersion(11), SchemaVersion(10)) => {
202-
let mut ops = vec![];
203-
let fork_choice_opt = db.get_item::<PersistedForkChoiceV11>(&FORK_CHOICE_DB_KEY)?;
204-
if let Some(fork_choice) = fork_choice_opt {
205-
let updated_fork_choice =
206-
migration_schema_v11::downgrade_fork_choice(fork_choice, log);
207-
208-
ops.push(updated_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
209-
}
210-
211-
db.store_schema_version_atomically(to, ops)?;
212-
213-
Ok(())
214-
}
21558
// Upgrade from v11 to v12 to store richer metadata in the attestation op pool.
21659
(SchemaVersion(11), SchemaVersion(12)) => {
21760
let ops = migration_schema_v12::upgrade_to_v12::<T>(db.clone(), log)?;

0 commit comments

Comments
 (0)