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

Skip to content

Conversation

@buffalojoec
Copy link
Contributor

Adds a read-only API that covers VoteStateVersions, VoteStateV4 and VoteStateV3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each method here is used by some component in Agave, such as CLI, RPC, Core, or Stakes, as well as the Stake program.

Comment on lines +30 to +31
/// Returns the inflation rewards commission in basis points.
fn inflation_rewards_commission_bps(&self) -> u16;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with "inflation rewards" instead of "commission", since it's a more accurate name for even the legacy field, and basis points rather than percentage to avoid a future breaking change. It's also easier to test with v4 in Agave if we can get the value in basis points, even though the program floors to the nearest percentage anyway.

Comment on lines 198 to 201
VoteStateVersions::V0_23_5(_state) => {
// V0_23_5 does not have AuthorizedVoters struct.
unimplemented!("V0_23_5 does not support authorized_voters.")
}
Copy link
Contributor Author

@buffalojoec buffalojoec Oct 8, 2025

Choose a reason for hiding this comment

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

Obviously this is a bit problematic. It has an authorized_voter field, but it doesn't allow us to return a reference to an actual AuthorizedVoters type.

We have a few options:

  1. Refactor this method and use a trait-based accessor for querying authorized voters. Many callsites in Agave only care about the length, but a few do actually want an iterator over voters or some way to query an authorized voter by epoch.
  2. Either panic here or make the function fallible (ie. Result<&AuthorizedVoters, InstructionError>.
  3. Remove V0_23_5 from VoteStateVersions.

The last one is probably the best call IMO, since it's not used anywhere in Agave and we know there are no v1 vote accounts on-chain anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

We will still probably want to keep an enum variant in VoteStateVersions for deserializing Uninitialized state. Maybe we add a separate enum for vote state versions which excludes v1 and only includes the versions which have authorized voters

Comment on lines 262 to 275
fn votes(&self) -> &VecDeque<LandedVote> {
match self {
VoteStateVersions::V0_23_5(_state) => {
// V0_23_5 uses VecDeque<Lockout>, not VecDeque<LandedVote>.
unimplemented!("V0_23_5 does not support votes.")
}
VoteStateVersions::V1_14_11(_state) => {
// V1_14_11 uses VecDeque<Lockout>, not VecDeque<LandedVote>.
unimplemented!("V1_14_11 does not support votes.")
}
VoteStateVersions::V3(state) => state.votes(),
VoteStateVersions::V4(state) => state.votes(),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we can probably remedy the variance in votes types between older vote states and newer ones by making this function return an iterator over LandedVote items. However, a generic iterator doesn't guarantee any dequeue behavior. The program would still need access to &VecDequeue<LandedVote>, but that can live under the VoteStateHandle trait if need be.

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 VecDeque in the read api?

@buffalojoec buffalojoec requested a review from jstarry October 8, 2025 05:54
@buffalojoec
Copy link
Contributor Author

@jstarry I actually think - if we're going to go this route - the best move is to just only include the ones that are straightforward for now, and see if we can live without authorized_voters and votes on the Agave side.

Adding new methods is technically breaking, but this change right now isn't.

@buffalojoec buffalojoec marked this pull request as ready for review October 10, 2025 00:56
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