Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@buffalojoec
Copy link
Contributor

Problem

So far, we've mostly been serializing VoteStateVersions with bincode, or using the optimized path on either recent vote state (VoteStateV3::deserialize or VoteStateV4::deserialize). However, the former is not performant enough and the latter will coerce the underlying type into the target version upon deserialization regardless of its actual serialized version.

The coercion of the underlying type is actually a problem and should be eliminated in future breaking changes to the vote interface. However, in the immediate term, we require an optimized path for deserializing VoteStateVersions in the Vote program without coercing the underlying type at all.

Summary of Changes

Similar to VoteStateV3 and VoteStateV4, adds an optimized deserialization API for VoteStateVersions. Simply includes one more crate-private free function to deserialize into a V1_14_11 vote state pointer and hooks up the deserializers to a new VoteStateVersions::deserialize function that will deserialize into VoteStateVersions as-is with no coercion.

I made the choice to disallow support for V0_23_5, since it's been entirely phased out on all networks, it's not supported by the Vote program, and it has never really had deserialization support in this library. The V0_23_5 variant should be deprecated as well, which we can do in follow-up work.

@buffalojoec buffalojoec requested a review from jstarry October 16, 2025 08:32
Copy link
Contributor

@jstarry jstarry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid, just some small things


let variant = solana_serialize_utils::cursor::read_u32(&mut cursor)?;
match variant {
// V0_23_5 not supported.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return InstructionError::UninitializedAccount for this instead of InvalidAccountData

Comment on lines +216 to +217
let vote_state =
unsafe { Box::from_raw(Box::into_raw(vote_state) as *mut VoteState1_14_11) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you can do this without the into/from

Suggested change
let vote_state =
unsafe { Box::from_raw(Box::into_raw(vote_state) as *mut VoteState1_14_11) };
let vote_state = unsafe { vote_state.assume_init() };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can, but only for Rust 1.82 and above. I would have to reconfigure the MSRV checks on the workspace in order to allow vote-interface to move past everything else, or bump everything to 1.82.

//
// V1_14_11
1 => {
let mut vote_state = Box::new(std::mem::MaybeUninit::uninit());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you import MaybeUninit locally as well?

///
/// This is a convenience wrapper around `bincode::serialize_into`.
#[cfg(feature = "bincode")]
pub fn serialize(&self, output: &mut [u8]) -> Result<(), InstructionError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ride without it for now. If we need it later we can add it.

unsafe { addr_of_mut!((*vote_state).authorized_withdrawer) },
)?;
let commission = read_u8(cursor)?;
let votes = read_votes_as_lockouts(cursor)?; // `Vec<Lockout>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels incredibly pedantic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yeah but it's also not the correct type so it stood out :P

@buffalojoec buffalojoec force-pushed the vote-state-versions-fast-deser branch from 403f4c2 to 66f0045 Compare October 17, 2025 01:49
@buffalojoec buffalojoec merged commit ede6ea6 into anza-xyz:master Oct 17, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants