-
Notifications
You must be signed in to change notification settings - Fork 477
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -793,26 +793,29 @@ func (v2 *Handlers) GetStatus(ctx echo.Context) error { | |
CatchpointAcquiredBlocks: &stat.CatchpointCatchupAcquiredBlocks, | ||
} | ||
|
||
nextProtocolVoteBefore := uint64(stat.NextProtocolVoteBefore) | ||
var votesToGo int64 = int64(nextProtocolVoteBefore) - int64(stat.LastRound) | ||
if votesToGo < 0 { | ||
votesToGo = 0 | ||
} | ||
if nextProtocolVoteBefore > 0 { | ||
// Make sure a vote is happening | ||
if stat.NextProtocolVoteBefore > 0 { | ||
votesToGo := uint64(0) | ||
// 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
consensus := config.Consensus[protocol.ConsensusCurrentVersion] | ||
upgradeVoteRounds := consensus.UpgradeVoteRounds | ||
upgradeThreshold := consensus.UpgradeThreshold | ||
votes := uint64(consensus.UpgradeVoteRounds) - uint64(votesToGo) | ||
votes := consensus.UpgradeVoteRounds - votesToGo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always nonnegative There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
votesYes := stat.NextProtocolApprovals | ||
votesNo := votes - votesYes | ||
upgradeDelay := uint64(stat.UpgradeDelay) | ||
upgradeDelay := stat.UpgradeDelay | ||
response.UpgradeVotesRequired = &upgradeThreshold | ||
response.UpgradeNodeVote = &stat.UpgradeApprove | ||
response.UpgradeDelay = &upgradeDelay | ||
response.UpgradeVotes = &votes | ||
response.UpgradeYesVotes = &votesYes | ||
response.UpgradeNoVotes = &votesNo | ||
response.UpgradeNextProtocolVoteBefore = &nextProtocolVoteBefore | ||
response.UpgradeNextProtocolVoteBefore = numOrNil(uint64(stat.NextProtocolVoteBefore)) | ||
response.UpgradeVoteRounds = &upgradeVoteRounds | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
There was a problem hiding this comment.
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