Store execution block hash in fork choice (#2643)

* - Update the fork choice `ProtoNode` to include `is_merge_complete`
- Add database migration for the persisted fork choice

* update tests

* Small cleanup

* lints

* store execution block hash in fork choice rather than bool
This commit is contained in:
realbigsean
2021-09-28 05:56:49 -04:00
committed by Paul Hauner
parent 7236dcbdbf
commit e559bd9f59
9 changed files with 148 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
use crate::proto_array::LegacyProtoNode;
use crate::{
proto_array::{ProtoArray, ProtoNode},
proto_array_fork_choice::{ElasticList, ProtoArrayForkChoice, VoteTracker},
@@ -17,6 +18,35 @@ pub struct SszContainer {
indices: Vec<(Hash256, usize)>,
}
/// Only used for SSZ deserialization of the persisted fork choice during the database migration
/// from schema 4 to schema 5.
#[derive(Encode, Decode)]
pub struct LegacySszContainer {
votes: Vec<VoteTracker>,
balances: Vec<u64>,
prune_threshold: usize,
justified_epoch: Epoch,
finalized_epoch: Epoch,
nodes: Vec<LegacyProtoNode>,
indices: Vec<(Hash256, usize)>,
}
impl Into<SszContainer> for LegacySszContainer {
fn into(self) -> SszContainer {
let nodes = self.nodes.into_iter().map(Into::into).collect();
SszContainer {
votes: self.votes,
balances: self.balances,
prune_threshold: self.prune_threshold,
justified_epoch: self.justified_epoch,
finalized_epoch: self.finalized_epoch,
nodes,
indices: self.indices,
}
}
}
impl From<&ProtoArrayForkChoice> for SszContainer {
fn from(from: &ProtoArrayForkChoice) -> Self {
let proto_array = &from.proto_array;