Skip to content

vote-program: plumb target_version through the program#8191

Merged
buffalojoec merged 6 commits intoanza-xyz:masterfrom
buffalojoec:vote-state-target-version-with-unit-tests
Oct 1, 2025
Merged

vote-program: plumb target_version through the program#8191
buffalojoec merged 6 commits intoanza-xyz:masterfrom
buffalojoec:vote-state-target-version-with-unit-tests

Conversation

@buffalojoec
Copy link
Copy Markdown

@buffalojoec buffalojoec commented Sep 25, 2025

Problem

Building on the back of #8178, the next step is to outfit the program to be dynamic over some target vote state version, so we can feed the handler with the desired state version to deserialize to and target for state changes.

Summary of Changes

The main change of this PR is in the first commit, where I plumb the target_version: VoteStateTargetVersion argument through all of the processor functions that operate on vote state.

After that, I update all of the tests (mostly using test_case wherever possible) to test all of the vote_state/mod functions individually with each target version V3 and V4.

In the top-level of the program processor, the target version is fixed to V3, so the Vote program is still functionally unchanged after this PR.

@buffalojoec buffalojoec requested a review from jstarry September 25, 2025 17:56
@mergify
Copy link
Copy Markdown

mergify Bot commented Sep 25, 2025

The Firedancer team maintains a line-for-line reimplementation of the
native programs, and until native programs are moved to BPF, those
implementations must exactly match their Agave counterparts.
If this PR represents a change to a native program implementation (not
tests), please include a reviewer from the Firedancer team. And please
keep refactors to a minimum.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 95.17045% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.2%. Comparing base (2b843ca) to head (75727d5).
⚠️ Report is 39 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #8191    +/-   ##
========================================
  Coverage    83.1%    83.2%            
========================================
  Files         828      828            
  Lines      365080   365167    +87     
========================================
+ Hits       303700   303836   +136     
+ Misses      61380    61331    -49     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@buffalojoec buffalojoec force-pushed the vote-state-target-version-with-unit-tests branch from a9d52b1 to 9b8f3cf Compare September 26, 2025 12:24
Comment on lines -765 to -769
/// Given a proposed new commission, returns true if this would be a commission increase, false otherwise
pub fn is_commission_increase(vote_state: &VoteStateV3, commission: u8) -> bool {
commission > vote_state.commission
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This appears unused across the monorepo.

Comment thread programs/vote/src/vote_state/mod.rs Outdated
let mut borrowed_account = instruction_context
.try_borrow_instruction_account(0)
.unwrap();
let vote_pubkey = *borrowed_account.get_key();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pretty odd that this test sets up the tx context with the vote address set to the node_pubkey. Can you update the test to specify a vote pubkey and use that to setup the context?

Referring to this:

        let mut transaction_context = TransactionContext::new(
            vec![(id(), processor_account), (node_pubkey, vote_account)],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure thing. The goal was to keep the existing tests as close to the same as they were. I also felt like this was a bit strange though. I'll update it.

Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment on lines +1271 to +1273
// V4 has fields that V1_14_11 does not have, so the vote states
// will vary slightly.
check_converted_vote_state_v4_fields(&converted_vote_state);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not have the vote_state_new_for_test helper take a vote_pubkey param which can be used to initialize the inflation collector address? That way we can just do assert!(vote_state == converted_vote_state); no matter the target version.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nice call!

Comment thread programs/vote/src/vote_state/mod.rs Outdated
);
let vote_state_version = borrowed_account.get_state::<VoteStateVersions>().unwrap();
assert_matches!(vote_state_version, VoteStateVersions::V1_14_11(_));
// Again, re-set the vote account state, knowing the account only has
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do this same test twice?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I just left the test as it was! I can remove the redundant step, though. It was already doing this.

@buffalojoec buffalojoec merged commit b5751be into anza-xyz:master Oct 1, 2025
43 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.

3 participants