Skip to content

Switching to VoteStateV4.#456

Merged
wen-coding merged 14 commits into
anza-xyz:masterfrom
wen-coding:try_out_vote_state_v4
Sep 23, 2025
Merged

Switching to VoteStateV4.#456
wen-coding merged 14 commits into
anza-xyz:masterfrom
wen-coding:try_out_vote_state_v4

Conversation

@wen-coding
Copy link
Copy Markdown
Contributor

@wen-coding wen-coding commented Sep 18, 2025

  • Adding create_v4_account_with_authorized which is actually submitted in Agave #8103, we are just replicating the work here because we need it
  • Use create_v4_account_with_authorized in genesis_utils and a few other tests
  • As a result we do need to deserialize v4 account data instead of AlpenglowVoteState deserialize or VoteStateV3 deserialize in a few tests
  • Also replaced new_random_from_alpenglow_vote_state with new_random_alpenglow() which creates v4 account
  • Replace AlpenglowVoteState with normal vote_state_view in voting_utils.rs, we don't use AlpenglowVoteState any more
  • Add bls_pubkey_to_compressed_bytes in genesis_util to simplify bls pubkey conversion

@wen-coding wen-coding marked this pull request as draft September 18, 2025 05:19
@wen-coding wen-coding marked this pull request as ready for review September 18, 2025 14:11
@wen-coding wen-coding marked this pull request as draft September 19, 2025 02:28
@wen-coding wen-coding marked this pull request as ready for review September 19, 2025 21:20
@wen-coding wen-coding changed the title Try switching to VoteStateV4. Switching to VoteStateV4. Sep 19, 2025
Copy link
Copy Markdown
Contributor

@bw-solana bw-solana left a comment

Choose a reason for hiding this comment

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

Can we add a PR description?

Also, it would be nice to create multiple, smaller PRs for things that can be separated. For example dropping solana_bls_signatures::signature::Signature as BlsSignature and just using Signature directly is unrelated cosmetic change and could be forked out

Comment thread votor/src/voting_utils.rs Outdated
Comment on lines +118 to +121
pub(crate) struct BLSKeypairWithCompressedPubkey {
pub keypair: Arc<BLSKeypair>,
pub compressed_pubkey: [u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE],
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

feels a little funky having this since the compressed_pubkey can be derived from the keypair. Should we have separate APIs and let callers decide how they want to access and mix/match things?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moving this to another PR later.

@wen-coding
Copy link
Copy Markdown
Contributor Author

Can we add a PR description?

Also, it would be nice to create multiple, smaller PRs for things that can be separated. For example dropping solana_bls_signatures::signature::Signature as BlsSignature and just using Signature directly is unrelated cosmetic change and could be forked out

That's fair. We don't strictly need anything after a24e3ca, I was just bored and started fixing small inefficiencies. I'll remove that from this PR.

@wen-coding wen-coding force-pushed the try_out_vote_state_v4 branch from dbdc7ed to a24e3ca Compare September 22, 2025 16:19
Comment thread runtime/src/bank/tests.rs Outdated
vote_state.set_epoch_credits(epoch_credits);
vote_state.serialize_into(vote_account.data_as_mut_slice());
let current_credits = vote_state.epoch_credits.last_mut().unwrap();
current_credits.1 += 16;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than doing current_credits.1, could we do let (x, y, ...) = vote_state.epoch_credits.last_mut().unwrap()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

account
.bls_pubkey()
.map(|bls_pubkey| (*pubkey, *bls_pubkey, *stake))
account.vote_state_view().and_then(|vote_state| {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a bit hard to read - could we unnest / clean this a bit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed

Comment thread vote/src/vote_account.rs
}

pub fn bls_pubkey(&self) -> Option<&BLSPubkey> {
pub fn bls_pubkey(&self) -> Option<BLSPubkey> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't seem right - shouldn't invoking bls_pubkey() return None for TowerBFT and Some(...) for Alpenglow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This part is a mess and will go away in the next PR, we will no longer have TowerBFT or Alpenglow option.

Comment thread votor/src/voting_utils.rs Outdated
let vote_account_pubkey = context.vote_account_pubkey;
let authorized_voter_keypair;
let bls_pubkey_in_vote_account;
let bls_pubkey_in_vote_account: BLSPubkey;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need to forward declare this variable - could we move it to the site of initialization and remove the annotated type, unless really needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is mainly done to release context.authorized_voter_keypairs read lock asap

carllin
carllin previously approved these changes Sep 22, 2025
Comment thread vote/src/vote_account.rs
VoteAccountState::TowerBFT(vote_state) => vote_state.bls_pubkey_compressed().map(|b| {
let bls_pubkey_compressed =
bincode::deserialize::<BLSPubkeyCompressed>(&b).unwrap();
BLSPubkeyCompressed::try_as_affine(&bls_pubkey_compressed).unwrap()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@samkim-crypto just double checking this is the right transformation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's pretty ugly, but should be correct because all local-cluster tests are passing :) We've turned on BLS verification now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So VoteStateV4 only says "give me a 48 byte buffer as bls pubkey", it doesn't care what's in it or whether it decodes properly for now. This PR (and anza-xyz/agave#8122 on Agave side) decides we serialize the compressed pubkey into the 48 byte buffer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, I confirm that this is the right transformation.

Comment thread runtime/src/stakes.rs
AlpenglowVoteState::create_account_with_authorized(
&vote_pubkey,
vote_state::create_v4_account_with_authorized(
&solana_pubkey::new_rand(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

out of curiosity why does this need to change?

Copy link
Copy Markdown
Contributor Author

@wen-coding wen-coding Sep 22, 2025

Choose a reason for hiding this comment

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

AlpenglowVoteState::create_account_with_authorized will create a vote state belonging to our new vote program, we are ditching our new vote program everywhere and replacing it with VoteStateV4 accounts.

ksn6
ksn6 previously approved these changes Sep 22, 2025
Copy link
Copy Markdown
Contributor

@AshwinSekar AshwinSekar left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Can we remove the vote state related stuff from votor-messages now?

@wen-coding
Copy link
Copy Markdown
Contributor Author

Thanks for doing this! Can we remove the vote state related stuff from votor-messages now?

Not yet, we need to remove the vote-account hack first. I'll get to that today.

@wen-coding wen-coding merged commit a240b70 into anza-xyz:master Sep 23, 2025
7 checks passed
@wen-coding wen-coding deleted the try_out_vote_state_v4 branch September 23, 2025 15: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.

6 participants