Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Further expand last_voted_slot terminology#10747

Merged
ryoqun merged 1 commit intosolana-labs:masterfrom
ryoqun:expand-last-voted-slot
Jun 23, 2020
Merged

Further expand last_voted_slot terminology#10747
ryoqun merged 1 commit intosolana-labs:masterfrom
ryoqun:expand-last-voted-slot

Conversation

@ryoqun
Copy link
Copy Markdown
Contributor

@ryoqun ryoqun commented Jun 23, 2020

Problem

There seems to be 4 adjective words + 1 code idiom to mean the identical qualified state: most recent, newest, last, latest and self.votes.back(). I think these are just confusing. Or, I'm lacking requisite delicate nuances of words every developer should be acquainted with. ;)

Summary of Changes

Settle with last. Also, I've ignored core/tests/fork-selection.rs because it's using reversed convention (= newest vote is pushed at front/first (not at back/last) of self.votes). And I noticed this too much late.... And the file is well out of scope.

continuation of #10734

part of #10718 (I'm addressing this as a separate pr because this doesn't require persistent tower per se)

Comment thread core/src/consensus.rs
fn last_voted_slot_in_bank(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option<Slot> {
let vote_account = bank.vote_accounts().get(vote_account_pubkey)?.1.clone();
let bank_vote_state = VoteState::deserialize(&vote_account.data).ok()?;
bank_vote_state.votes.iter().map(|v| v.slot).last()
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.

I don't know how much rustc optimizer is clever. But I simply changed the algorithm from map-then-last to last-then-map, considering this would be more straight-forward in this case: https://github.com/solana-labs/solana/pull/10747/files#diff-3666262446ea129567c6d96960c7e23cR411-R418

New code might eliminate this unneeded iteration here.

Comment thread core/src/consensus.rs
self.lockouts.root_slot
}

// a slot is not recent if it's older than the newest vote we have
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.

Inverted the description for more simpler definition. Also, old description should be older than or equal to...

if self
.votes
.back()
.map_or(false, |old_vote| old_vote.slot >= vote.slots[i])
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.

Reversed the condition operands for readability. Loop variable dependant expression should be first to be like a subject in a sentence.

if self
.votes
.back()
.map_or(false, |old_vote| old_vote.slot >= slot)
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.

Reversed the condition operands for readability. function arguments should be first to be like a subject in a sentence.

@ryoqun ryoqun requested a review from carllin June 23, 2020 04:18
@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Jun 23, 2020

@carllin Thanks for approving my recent prs! Could you also review this at your convenient time?

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 23, 2020

Codecov Report

Merging #10747 into master will increase coverage by 0.0%.
The diff coverage is 100.0%.

@@           Coverage Diff           @@
##           master   #10747   +/-   ##
=======================================
  Coverage    81.8%    81.8%           
=======================================
  Files         302      302           
  Lines       70799    70806    +7     
=======================================
+ Hits        57934    57942    +8     
+ Misses      12865    12864    -1     

@carllin
Copy link
Copy Markdown
Contributor

carllin commented Jun 23, 2020

looks good!

@ryoqun ryoqun merged commit 685beca into solana-labs:master Jun 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants