Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

banking_stage: calculate stake by vote account instead of node pubkey #3049

Merged
merged 4 commits into from
Oct 4, 2024

Conversation

AshwinSekar
Copy link

Problem

latest_unprocessed_votes uses the bank's staked_nodes in order to calculate the voter's stake. This structure is based off of the node_pubkey to account for validators with multiple vote accounts.

Fork choice and other consensus stake operations use EpochStakes instead, which calculates stake per vote account.

Summary of Changes

Use the vote_pubkey instead, and calculate stake based on the vote_account.

votes.filter(move |vote| {
let stake = staked_nodes.get(&vote.pubkey()).copied().unwrap_or(0);
let stake = epoch_stakes.vote_account_stake(&vote.vote_pubkey());
Copy link
Author

Choose a reason for hiding this comment

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

This now matches fork choice:

.map(|epoch_stakes| epoch_stakes.vote_account_stake(pubkey))

@@ -87,10 +87,16 @@ impl LatestValidatorVotePacket {
Ok(vote_state_update_instruction)
if instruction_filter(&vote_state_update_instruction) =>
{
let &pubkey = message
Copy link
Author

@AshwinSekar AshwinSekar Oct 1, 2024

Choose a reason for hiding this comment

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

Starry pointed out that this method of identifying the voter is brittle, as it relies on the node id being the first signer.
Grabbing the vote pubkey instead should be safe, as it is required to be the first account on the instruction:

/// # Account references
/// 0. `[Write]` Vote account to vote with

cached_staked_nodes: RwLock::new(bank.current_epoch_staked_nodes().clone()),
latest_votes_per_pubkey: RwLock::new(HashMap::default()),
num_unprocessed_votes: AtomicUsize::new(0),
cached_epoch_stakes: RwLock::new(bank.current_epoch_stakes().clone()),
Copy link

Choose a reason for hiding this comment

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

just a note here; cloning is "cheap" since EpochStakes holds 3 Arcs and a u64 internally.
this won't clone the relatively large underlying data

apfitzge
apfitzge previously approved these changes Oct 3, 2024
jstarry
jstarry previously approved these changes Oct 3, 2024
Copy link

@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.

nice, this looks much better!

core/src/banking_stage/latest_unprocessed_votes.rs Outdated Show resolved Hide resolved
core/src/banking_stage/latest_unprocessed_votes.rs Outdated Show resolved Hide resolved
jstarry
jstarry previously approved these changes Oct 3, 2024
Copy link

@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.

still some places where latest_votes_per_pubkey is used but I was more concerned about the field being named explicitly so I'm happy

@AshwinSekar
Copy link
Author

still some places where latest_votes_per_pubkey is used but I was more concerned about the field being named explicitly so I'm happy

I can't unsee it now 😅 , renamed the remaining occurrences

@AshwinSekar AshwinSekar merged commit c05caa2 into anza-xyz:master Oct 4, 2024
38 checks passed
@AshwinSekar AshwinSekar deleted the luv-vote-pubkey branch October 4, 2024 02:19
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