Fix VoteTracker decoding

This commit is contained in:
Michael Sproul
2026-04-01 12:48:34 +11:00
parent 9ef73d0af0
commit afb1f0ae2d
2 changed files with 45 additions and 3 deletions

View File

@@ -33,6 +33,45 @@ pub struct VoteTracker {
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 slot: Slot,
pub root: Hash256,

View File

@@ -2,7 +2,7 @@ use crate::proto_array::ProposerBoost;
use crate::{
Error, JustifiedBalances,
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_derive::{Decode, Encode};
@@ -22,6 +22,9 @@ pub type SszContainer = SszContainerV29;
no_enum
)]
pub struct SszContainer {
#[superstruct(only(V28))]
pub votes_v28: Vec<VoteTrackerV28>,
#[superstruct(only(V29))]
pub votes: Vec<VoteTracker>,
pub prune_threshold: usize,
// Deprecated, remove in a future schema migration
@@ -75,7 +78,7 @@ impl TryFrom<(SszContainerV29, JustifiedBalances)> for ProtoArrayForkChoice {
impl From<SszContainerV28> for SszContainerV29 {
fn from(v28: SszContainerV28) -> Self {
Self {
votes: v28.votes,
votes: v28.votes_v28.into_iter().map(Into::into).collect(),
prune_threshold: v28.prune_threshold,
nodes: v28
.nodes
@@ -98,7 +101,7 @@ impl From<SszContainerV28> for SszContainerV29 {
impl From<SszContainerV29> for SszContainerV28 {
fn from(v29: SszContainerV29) -> Self {
Self {
votes: v29.votes,
votes_v28: v29.votes.into_iter().map(Into::into).collect(),
prune_threshold: v29.prune_threshold,
// These checkpoints are not consumed in v28 paths since the upgrade from v17,
// we can safely default the values.