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

api: Fix vote status computation. #5228

Merged
merged 1 commit into from Mar 30, 2023

Conversation

winder
Copy link
Contributor

@winder winder commented Mar 23, 2023

Summary

Fix an off by one error which caused a display issue where the number of votes remaining show +1 compared to the true value and the number of no votes show -1 compared to the true value.

Test Plan

New unit test which reproduced an underflow when there were 0 no votes.

Manual test with this code rebased on feature/alphanet:

A consensus upgrade with no votes, Yes + No + Remaining = 10000. Here you can see 1249+116+8635=10000:

Last committed block: 3477498
Time since last block: 0.1s
Sync Time: 74.1s
Last consensus protocol: alpha5
Next consensus protocol: alpha5
Round for next consensus protocol: 3477499
Next consensus protocol supported: true
Last Catchpoint:
Consensus upgrade state: Voting
Yes votes: 1249
No votes: 116
Votes remaining: 8635
Yes votes required: 9000
Vote window close round: 3486134
Genesis ID: alphanet-v1
Genesis hash: OvNEMO+PTU8TDsPLxUGoF/pEqeKayA2a3xmcLTL/Jjo=

A consensus upgrade unanimous yes votes, Yes + No + Remaining = 10000. Again, here you can see 2628 + 0 + 7372 = 10000:

Last committed block: 3498762
Time since last block: 0.3s
Sync Time: 398.7s
Last consensus protocol: alpha6
Next consensus protocol: alpha6
Round for next consensus protocol: 3498763
Next consensus protocol supported: true
Last Catchpoint:
Consensus upgrade state: Voting
Yes votes: 2628
No votes: 0
Votes remaining: 7372
Yes votes required: 9000
Vote window close round: 3506135
Genesis ID: alphanet-v1
Genesis hash: OvNEMO+PTU8TDsPLxUGoF/pEqeKayA2a3xmcLTL/Jjo=

@winder winder self-assigned this Mar 23, 2023
@winder winder added the Bug-Fix label Mar 23, 2023
@codecov
Copy link

codecov bot commented Mar 23, 2023

Codecov Report

Merging #5228 (8c06408) into master (19862ba) will decrease coverage by 6.59%.
The diff coverage is 38.88%.

@@            Coverage Diff             @@
##           master    #5228      +/-   ##
==========================================
- Coverage   53.52%   46.93%   -6.59%     
==========================================
  Files         441      441              
  Lines       55140    55138       -2     
==========================================
- Hits        29511    25880    -3631     
- Misses      23340    26820    +3480     
- Partials     2289     2438     +149     
Impacted Files Coverage Δ
cmd/goal/node.go 9.51% <0.00%> (-2.41%) ⬇️
daemon/algod/api/server/v2/handlers.go 0.00% <0.00%> (-0.83%) ⬇️
daemon/algod/api/server/v2/test/helpers.go 70.27% <100.00%> (-5.39%) ⬇️

... and 190 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@winder winder marked this pull request as ready for review March 23, 2023 16:28
algorandskiy
algorandskiy previously approved these changes Mar 24, 2023
Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

The root cause with missing "-1" appears determined correctly and fixed.

@algorandskiy
Copy link
Contributor

For reference, the original issue looked like this:

Last committed block: 3504948
Time since last block: 0.0s
Sync Time: 165.1s
Last consensus protocol: alpha6
Next consensus protocol: alpha6
Round for next consensus protocol: 3504949
Next consensus protocol supported: true
Last Catchpoint: 
Consensus upgrate state: Voting
Yes votes: 8814
No votes: 18446744073709551615
Votes remaining: 1187
Yes votes required: 9000
Vote window close round: 3506135

@algorandskiy
Copy link
Contributor

algorandskiy commented Mar 29, 2023

@winder please rebase

consensus := config.Consensus[protocol.ConsensusCurrentVersion]
upgradeVoteRounds := consensus.UpgradeVoteRounds
upgradeThreshold := consensus.UpgradeThreshold
votes := uint64(consensus.UpgradeVoteRounds) - uint64(votesToGo)
votes := consensus.UpgradeVoteRounds - votesToGo
Copy link
Contributor

Choose a reason for hiding this comment

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

always nonnegative

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you asking to change these to uint64? I think a negative number and an underflow are both equally wrong, but a negative number would be easier to debug.

Copy link
Contributor

Choose a reason for hiding this comment

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

no I think I meant, "I followed the definitions of these things enough to convince me that this value is always nonnegative" in the normal use case

// Check if the vote window is still open.
if stat.NextProtocolVoteBefore > stat.LastRound {
// subtract 1 because the variables are referring to "Last" round and "VoteBefore"
votesToGo = uint64(stat.NextProtocolVoteBefore - stat.LastRound - 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can't be an underflow because it is inside a check that NextProtocolVoteBefore > LastRound.

statusString = statusString + "\n" + fmt.Sprintf(
infoNodeStatusConsensusUpgradeVoting,
upgradeYesVotes,
upgradeNoVotes,
upgradeNextProtocolVoteBefore-stat.LastRound,
upgradeVoteRounds-upgradeYesVotes-upgradeNoVotes,
Copy link
Contributor

Choose a reason for hiding this comment

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

yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

upgradeVoteRounds was calculated in algod so this more direct formula can be used in the client

@will
Copy link

will commented Mar 29, 2023 via email

@algorandskiy
Copy link
Contributor

algorandskiy commented Mar 29, 2023

I apology I trusted the autocomplete feature and mis-tagged you.

Copy link
Contributor

@bbroder-algo bbroder-algo left a comment

Choose a reason for hiding this comment

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

fenceposts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants