Skip to content

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

Merged
AshwinSekar merged 4 commits intoanza-xyz:masterfrom
AshwinSekar:luv-vote-pubkey
Oct 4, 2024
Merged

banking_stage: calculate stake by vote account instead of node pubkey#3049
AshwinSekar merged 4 commits intoanza-xyz:masterfrom
AshwinSekar:luv-vote-pubkey

Conversation

@AshwinSekar
Copy link
Copy Markdown

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.

let epoch_stakes = self.cached_epoch_stakes.read().unwrap();
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
Copy Markdown
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))

Ok(vote_state_update_instruction)
if instruction_filter(&vote_state_update_instruction) =>
{
let &pubkey = message
Copy link
Copy Markdown
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
Copy Markdown

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

Comment thread core/src/banking_stage/latest_unprocessed_votes.rs Outdated
apfitzge
apfitzge previously approved these changes Oct 3, 2024
jstarry
jstarry previously approved these changes Oct 3, 2024
Copy link
Copy Markdown

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

Comment thread core/src/banking_stage/latest_unprocessed_votes.rs Outdated
Comment thread core/src/banking_stage/latest_unprocessed_votes.rs Outdated
@AshwinSekar AshwinSekar dismissed stale reviews from jstarry and apfitzge via 8171af5 October 3, 2024 19:18
jstarry
jstarry previously approved these changes Oct 3, 2024
Copy link
Copy Markdown

@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
Copy Markdown
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
@AshwinSekar AshwinSekar deleted the luv-vote-pubkey branch October 4, 2024 02:19
ray-kast pushed a commit to abklabs/agave that referenced this pull request Nov 27, 2024
…anza-xyz#3049)

* banking_stage: calculate stake by vote account instead of node pubkey

* pr feedback: don't hold epoch stakes write lock for eviction

* pr feedback: pubkey -> vote_pubkey renames

* pr feedback: rename missed pubkey -> vote_pubkey
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