mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 13:54:44 +00:00
DB migration for fork choice cleanup (#4265)
## Issue Addressed #4233 ## Proposed Changes Remove the `best_justified_checkpoint` from the `PersistedForkChoiceStore` type as it is now unused. Additionally, remove the `Option`'s wrapping the `justified_checkpoint` and `finalized_checkpoint` fields on `ProtoNode` which were only present to facilitate a previous migration. Include the necessary code to facilitate the migration to a new DB schema.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::proto_array::ProposerBoost;
|
||||
use crate::{
|
||||
proto_array::{ProtoArray, ProtoNode},
|
||||
proto_array::{ProtoArray, ProtoNodeV16, ProtoNodeV17},
|
||||
proto_array_fork_choice::{ElasticList, ProtoArrayForkChoice, VoteTracker},
|
||||
Error, JustifiedBalances,
|
||||
};
|
||||
@@ -8,24 +8,71 @@ use ssz::{four_byte_option_impl, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use superstruct::superstruct;
|
||||
use types::{Checkpoint, Hash256};
|
||||
|
||||
// Define a "legacy" implementation of `Option<usize>` which uses four bytes for encoding the union
|
||||
// selector.
|
||||
four_byte_option_impl!(four_byte_option_checkpoint, Checkpoint);
|
||||
|
||||
#[derive(Encode, Decode)]
|
||||
pub type SszContainer = SszContainerV17;
|
||||
|
||||
#[superstruct(
|
||||
variants(V16, V17),
|
||||
variant_attributes(derive(Encode, Decode)),
|
||||
no_enum
|
||||
)]
|
||||
pub struct SszContainer {
|
||||
pub votes: Vec<VoteTracker>,
|
||||
pub balances: Vec<u64>,
|
||||
pub prune_threshold: usize,
|
||||
pub justified_checkpoint: Checkpoint,
|
||||
pub finalized_checkpoint: Checkpoint,
|
||||
pub nodes: Vec<ProtoNode>,
|
||||
#[superstruct(only(V16))]
|
||||
pub nodes: Vec<ProtoNodeV16>,
|
||||
#[superstruct(only(V17))]
|
||||
pub nodes: Vec<ProtoNodeV17>,
|
||||
pub indices: Vec<(Hash256, usize)>,
|
||||
pub previous_proposer_boost: ProposerBoost,
|
||||
}
|
||||
|
||||
impl TryInto<SszContainer> for SszContainerV16 {
|
||||
type Error = Error;
|
||||
|
||||
fn try_into(self) -> Result<SszContainer, Error> {
|
||||
let nodes: Result<Vec<ProtoNodeV17>, Error> =
|
||||
self.nodes.into_iter().map(TryInto::try_into).collect();
|
||||
|
||||
Ok(SszContainer {
|
||||
votes: self.votes,
|
||||
balances: self.balances,
|
||||
prune_threshold: self.prune_threshold,
|
||||
justified_checkpoint: self.justified_checkpoint,
|
||||
finalized_checkpoint: self.finalized_checkpoint,
|
||||
nodes: nodes?,
|
||||
indices: self.indices,
|
||||
previous_proposer_boost: self.previous_proposer_boost,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<SszContainerV16> for SszContainer {
|
||||
fn into(self) -> SszContainerV16 {
|
||||
let nodes = self.nodes.into_iter().map(Into::into).collect();
|
||||
|
||||
SszContainerV16 {
|
||||
votes: self.votes,
|
||||
balances: self.balances,
|
||||
prune_threshold: self.prune_threshold,
|
||||
justified_checkpoint: self.justified_checkpoint,
|
||||
finalized_checkpoint: self.finalized_checkpoint,
|
||||
nodes,
|
||||
indices: self.indices,
|
||||
previous_proposer_boost: self.previous_proposer_boost,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ProtoArrayForkChoice> for SszContainer {
|
||||
fn from(from: &ProtoArrayForkChoice) -> Self {
|
||||
let proto_array = &from.proto_array;
|
||||
|
||||
Reference in New Issue
Block a user