mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 05:14:35 +00:00
Use schema v12
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//! Utilities for managing database schema changes.
|
||||
mod migration_schema_v11;
|
||||
mod migration_schema_v12;
|
||||
mod migration_schema_v6;
|
||||
mod migration_schema_v7;
|
||||
mod migration_schema_v8;
|
||||
@@ -133,14 +133,14 @@ pub fn migrate_schema<T: BeaconChainTypes>(
|
||||
}
|
||||
// FIXME(sproul): stub for Sean's v10 migration
|
||||
(SchemaVersion(9), SchemaVersion(10)) => db.store_schema_version(to),
|
||||
// Upgrade from v10 to v11 to store richer metadata in the attestation op pool.
|
||||
(SchemaVersion(10), SchemaVersion(11)) => {
|
||||
let ops = migration_schema_v11::upgrade_to_v11::<T>(db.clone(), log)?;
|
||||
// Upgrade from v11 to v12 to store richer metadata in the attestation op pool.
|
||||
(SchemaVersion(10), SchemaVersion(12)) => {
|
||||
let ops = migration_schema_v12::upgrade_to_v12::<T>(db.clone(), log)?;
|
||||
db.store_schema_version_atomically(to, ops)
|
||||
}
|
||||
// Downgrade from v11 to v9 to drop richer metadata from the attestation op pool.
|
||||
(SchemaVersion(11), SchemaVersion(9)) => {
|
||||
let ops = migration_schema_v11::downgrade_from_v11::<T>(db.clone(), log)?;
|
||||
// Downgrade from v12 to v9 to drop richer metadata from the attestation op pool.
|
||||
(SchemaVersion(12), SchemaVersion(11)) => {
|
||||
let ops = migration_schema_v12::downgrade_from_v12::<T>(db.clone(), log)?;
|
||||
db.store_schema_version_atomically(to, ops)
|
||||
}
|
||||
// Anything else is an error.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::beacon_chain::{BeaconChainTypes, OP_POOL_DB_KEY};
|
||||
use operation_pool::{PersistedOperationPool, PersistedOperationPoolV11, PersistedOperationPoolV5};
|
||||
use operation_pool::{PersistedOperationPool, PersistedOperationPoolV12, PersistedOperationPoolV5};
|
||||
use slog::{debug, info, Logger};
|
||||
use std::sync::Arc;
|
||||
use store::{Error, HotColdDB, KeyValueStoreOp, StoreItem};
|
||||
|
||||
pub fn upgrade_to_v11<T: BeaconChainTypes>(
|
||||
pub fn upgrade_to_v12<T: BeaconChainTypes>(
|
||||
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
|
||||
log: Logger,
|
||||
) -> Result<Vec<KeyValueStoreOp>, Error> {
|
||||
// Load a V5 op pool and transform it to V11.
|
||||
// Load a V5 op pool and transform it to V12.
|
||||
let v5 = if let Some(op_pool) =
|
||||
db.get_item::<PersistedOperationPoolV5<T::EthSpec>>(&OP_POOL_DB_KEY)?
|
||||
{
|
||||
@@ -24,22 +24,22 @@ pub fn upgrade_to_v11<T: BeaconChainTypes>(
|
||||
);
|
||||
|
||||
// FIXME(sproul): work out whether it's worth trying to carry across the attestations
|
||||
let v11 = PersistedOperationPool::V11(PersistedOperationPoolV11 {
|
||||
let v12 = PersistedOperationPool::V12(PersistedOperationPoolV12 {
|
||||
attestations: vec![],
|
||||
sync_contributions: v5.sync_contributions,
|
||||
attester_slashings: v5.attester_slashings,
|
||||
proposer_slashings: v5.proposer_slashings,
|
||||
voluntary_exits: v5.voluntary_exits,
|
||||
});
|
||||
Ok(vec![v11.as_kv_store_op(OP_POOL_DB_KEY)])
|
||||
Ok(vec![v12.as_kv_store_op(OP_POOL_DB_KEY)])
|
||||
}
|
||||
|
||||
pub fn downgrade_from_v11<T: BeaconChainTypes>(
|
||||
pub fn downgrade_from_v12<T: BeaconChainTypes>(
|
||||
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
|
||||
log: Logger,
|
||||
) -> Result<Vec<KeyValueStoreOp>, Error> {
|
||||
// Load a V11 op pool and transform it to V5.
|
||||
let v11 = if let Some(PersistedOperationPool::V11(op_pool)) =
|
||||
// Load a V12 op pool and transform it to V5.
|
||||
let v12 = if let Some(PersistedOperationPool::V12(op_pool)) =
|
||||
db.get_item::<PersistedOperationPool<T::EthSpec>>(&OP_POOL_DB_KEY)?
|
||||
{
|
||||
op_pool
|
||||
@@ -50,15 +50,15 @@ pub fn downgrade_from_v11<T: BeaconChainTypes>(
|
||||
info!(
|
||||
log,
|
||||
"Dropping attestations from pool";
|
||||
"count" => v11.attestations.len(),
|
||||
"count" => v12.attestations.len(),
|
||||
);
|
||||
|
||||
let v5 = PersistedOperationPoolV5 {
|
||||
attestations_v5: vec![],
|
||||
sync_contributions: v11.sync_contributions,
|
||||
attester_slashings: v11.attester_slashings,
|
||||
proposer_slashings: v11.proposer_slashings,
|
||||
voluntary_exits: v11.voluntary_exits,
|
||||
sync_contributions: v12.sync_contributions,
|
||||
attester_slashings: v12.attester_slashings,
|
||||
proposer_slashings: v12.proposer_slashings,
|
||||
voluntary_exits: v12.voluntary_exits,
|
||||
};
|
||||
Ok(vec![v5.as_kv_store_op(OP_POOL_DB_KEY)])
|
||||
}
|
||||
@@ -12,7 +12,7 @@ pub use attestation::AttMaxCover;
|
||||
pub use attestation_storage::{AttestationRef, SplitAttestation};
|
||||
pub use max_cover::MaxCover;
|
||||
pub use persistence::{
|
||||
PersistedOperationPool, PersistedOperationPoolV11, PersistedOperationPoolV5,
|
||||
PersistedOperationPool, PersistedOperationPoolV12, PersistedOperationPoolV5,
|
||||
};
|
||||
pub use reward_cache::RewardCache;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ type PersistedSyncContributions<T> = Vec<(SyncAggregateId, Vec<SyncCommitteeCont
|
||||
/// Operations are stored in arbitrary order, so it's not a good idea to compare instances
|
||||
/// of this type (or its encoded form) for equality. Convert back to an `OperationPool` first.
|
||||
#[superstruct(
|
||||
variants(V5, V11),
|
||||
variants(V5, V12),
|
||||
variant_attributes(
|
||||
derive(Derivative, PartialEq, Debug, Serialize, Deserialize, Encode, Decode),
|
||||
serde(bound = "T: EthSpec", deny_unknown_fields),
|
||||
@@ -35,7 +35,7 @@ pub struct PersistedOperationPool<T: EthSpec> {
|
||||
#[superstruct(only(V5))]
|
||||
pub attestations_v5: Vec<(AttestationId, Vec<Attestation<T>>)>,
|
||||
/// Attestations and their attesting indices.
|
||||
#[superstruct(only(V11))]
|
||||
#[superstruct(only(V12))]
|
||||
pub attestations: Vec<(Attestation<T>, Vec<u64>)>,
|
||||
/// Mapping from sync contribution ID to sync contributions and aggregate.
|
||||
pub sync_contributions: PersistedSyncContributions<T>,
|
||||
@@ -90,7 +90,7 @@ impl<T: EthSpec> PersistedOperationPool<T> {
|
||||
.map(|(_, exit)| exit.clone())
|
||||
.collect();
|
||||
|
||||
PersistedOperationPool::V11(PersistedOperationPoolV11 {
|
||||
PersistedOperationPool::V12(PersistedOperationPoolV12 {
|
||||
attestations,
|
||||
sync_contributions,
|
||||
attester_slashings,
|
||||
@@ -119,7 +119,7 @@ impl<T: EthSpec> PersistedOperationPool<T> {
|
||||
let sync_contributions = RwLock::new(self.sync_contributions().iter().cloned().collect());
|
||||
let attestations = match self {
|
||||
PersistedOperationPool::V5(_) => return Err(OpPoolError::IncorrectOpPoolVariant),
|
||||
PersistedOperationPool::V11(pool) => {
|
||||
PersistedOperationPool::V12(pool) => {
|
||||
let mut map = AttestationMap::default();
|
||||
for (att, attesting_indices) in pool.attestations {
|
||||
map.insert(att, attesting_indices);
|
||||
@@ -154,7 +154,7 @@ impl<T: EthSpec> StoreItem for PersistedOperationPoolV5<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Deserialization for `PersistedOperationPool` defaults to `PersistedOperationPool::V11`.
|
||||
/// Deserialization for `PersistedOperationPool` defaults to `PersistedOperationPool::V12`.
|
||||
impl<T: EthSpec> StoreItem for PersistedOperationPool<T> {
|
||||
fn db_column() -> DBColumn {
|
||||
DBColumn::OpPool
|
||||
@@ -166,8 +166,8 @@ impl<T: EthSpec> StoreItem for PersistedOperationPool<T> {
|
||||
|
||||
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
|
||||
// Default deserialization to the latest variant.
|
||||
PersistedOperationPoolV11::from_ssz_bytes(bytes)
|
||||
.map(Self::V11)
|
||||
PersistedOperationPoolV12::from_ssz_bytes(bytes)
|
||||
.map(Self::V12)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user