mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Fix VoteTracker decoding
This commit is contained in:
@@ -33,6 +33,45 @@ pub struct VoteTracker {
|
|||||||
next_payload_present: bool,
|
next_payload_present: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can be deleted once the V28 schema migration is buried.
|
||||||
|
#[derive(Default, PartialEq, Clone, Encode, Decode)]
|
||||||
|
pub struct VoteTrackerV28 {
|
||||||
|
current_root: Hash256,
|
||||||
|
next_root: Hash256,
|
||||||
|
current_slot: Slot,
|
||||||
|
next_slot: Slot,
|
||||||
|
}
|
||||||
|
|
||||||
|
// This impl is only used upon upgrade from pre-Gloas to Gloas with all pre-Gloas nodes.
|
||||||
|
// The payload status is `false` for pre-Gloas nodes.
|
||||||
|
impl From<VoteTrackerV28> for VoteTracker {
|
||||||
|
fn from(v: VoteTrackerV28) -> Self {
|
||||||
|
VoteTracker {
|
||||||
|
current_root: v.current_root,
|
||||||
|
next_root: v.next_root,
|
||||||
|
current_slot: v.current_slot,
|
||||||
|
next_slot: v.next_slot,
|
||||||
|
// TODO(gloas): check that this is correct
|
||||||
|
current_payload_present: false,
|
||||||
|
next_payload_present: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This impl is only used upon downgrade from V29 to V28, with exclusively pre-Gloas nodes.
|
||||||
|
impl From<VoteTracker> for VoteTrackerV28 {
|
||||||
|
fn from(v: VoteTracker) -> Self {
|
||||||
|
// Drop the payload_present, but this is safe because this is only called on pre-Gloas
|
||||||
|
// nodes.
|
||||||
|
VoteTrackerV28 {
|
||||||
|
current_root: v.current_root,
|
||||||
|
next_root: v.next_root,
|
||||||
|
current_slot: v.current_slot,
|
||||||
|
next_slot: v.next_slot,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct LatestMessage {
|
pub struct LatestMessage {
|
||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
pub root: Hash256,
|
pub root: Hash256,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::proto_array::ProposerBoost;
|
|||||||
use crate::{
|
use crate::{
|
||||||
Error, JustifiedBalances,
|
Error, JustifiedBalances,
|
||||||
proto_array::{ProtoArray, ProtoNode, ProtoNodeV17},
|
proto_array::{ProtoArray, ProtoNode, ProtoNodeV17},
|
||||||
proto_array_fork_choice::{ElasticList, ProtoArrayForkChoice, VoteTracker},
|
proto_array_fork_choice::{ElasticList, ProtoArrayForkChoice, VoteTracker, VoteTrackerV28},
|
||||||
};
|
};
|
||||||
use ssz::{Encode, four_byte_option_impl};
|
use ssz::{Encode, four_byte_option_impl};
|
||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
@@ -22,6 +22,9 @@ pub type SszContainer = SszContainerV29;
|
|||||||
no_enum
|
no_enum
|
||||||
)]
|
)]
|
||||||
pub struct SszContainer {
|
pub struct SszContainer {
|
||||||
|
#[superstruct(only(V28))]
|
||||||
|
pub votes_v28: Vec<VoteTrackerV28>,
|
||||||
|
#[superstruct(only(V29))]
|
||||||
pub votes: Vec<VoteTracker>,
|
pub votes: Vec<VoteTracker>,
|
||||||
pub prune_threshold: usize,
|
pub prune_threshold: usize,
|
||||||
// Deprecated, remove in a future schema migration
|
// Deprecated, remove in a future schema migration
|
||||||
@@ -75,7 +78,7 @@ impl TryFrom<(SszContainerV29, JustifiedBalances)> for ProtoArrayForkChoice {
|
|||||||
impl From<SszContainerV28> for SszContainerV29 {
|
impl From<SszContainerV28> for SszContainerV29 {
|
||||||
fn from(v28: SszContainerV28) -> Self {
|
fn from(v28: SszContainerV28) -> Self {
|
||||||
Self {
|
Self {
|
||||||
votes: v28.votes,
|
votes: v28.votes_v28.into_iter().map(Into::into).collect(),
|
||||||
prune_threshold: v28.prune_threshold,
|
prune_threshold: v28.prune_threshold,
|
||||||
nodes: v28
|
nodes: v28
|
||||||
.nodes
|
.nodes
|
||||||
@@ -98,7 +101,7 @@ impl From<SszContainerV28> for SszContainerV29 {
|
|||||||
impl From<SszContainerV29> for SszContainerV28 {
|
impl From<SszContainerV29> for SszContainerV28 {
|
||||||
fn from(v29: SszContainerV29) -> Self {
|
fn from(v29: SszContainerV29) -> Self {
|
||||||
Self {
|
Self {
|
||||||
votes: v29.votes,
|
votes_v28: v29.votes.into_iter().map(Into::into).collect(),
|
||||||
prune_threshold: v29.prune_threshold,
|
prune_threshold: v29.prune_threshold,
|
||||||
// These checkpoints are not consumed in v28 paths since the upgrade from v17,
|
// These checkpoints are not consumed in v28 paths since the upgrade from v17,
|
||||||
// we can safely default the values.
|
// we can safely default the values.
|
||||||
|
|||||||
Reference in New Issue
Block a user