Skip to content

Commit

Permalink
api: Fix vote status computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Mar 23, 2023
1 parent b034cb8 commit f8e1b78
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 95 deletions.
2 changes: 1 addition & 1 deletion cmd/goal/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
infoNodeShuttingDown = "Algorand node is shutting down..."
infoNodeSuccessfullyStopped = "The node was successfully stopped."
infoNodeStatus = "Last committed block: %d\nTime since last block: %s\nSync Time: %s\nLast consensus protocol: %s\nNext consensus protocol: %s\nRound for next consensus protocol: %d\nNext consensus protocol supported: %v"
infoNodeStatusConsensusUpgradeVoting = "Consensus upgrate state: Voting\nYes votes: %d\nNo votes: %d\nVotes remaining: %d\nYes votes required: %d\nVote window close round: %d"
infoNodeStatusConsensusUpgradeVoting = "Consensus upgrade state: Voting\nYes votes: %d\nNo votes: %d\nVotes remaining: %d\nYes votes required: %d\nVote window close round: %d"
infoNodeStatusConsensusUpgradeScheduled = "Consensus upgrade state: Scheduled"
catchupStoppedOnUnsupported = "Last supported block (%d) is committed. The next block consensus protocol is not supported. Catchup service is stopped."
infoNodeCatchpointCatchupStatus = "Last committed block: %d\nSync Time: %s\nCatchpoint: %s"
Expand Down
6 changes: 5 additions & 1 deletion cmd/goal/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func makeStatusString(stat model.NodeStatusResponse) string {
upgradeVotesRequired := uint64(0)
upgradeNoVotes := uint64(0)
upgradeYesVotes := uint64(0)
upgradeVoteRounds := uint64(0)
if stat.UpgradeVotesRequired != nil {
upgradeVotesRequired = *stat.UpgradeVotesRequired
}
Expand All @@ -491,11 +492,14 @@ func makeStatusString(stat model.NodeStatusResponse) string {
if stat.UpgradeYesVotes != nil {
upgradeYesVotes = *stat.UpgradeYesVotes
}
if stat.UpgradeVoteRounds != nil {
upgradeVoteRounds = *stat.UpgradeVoteRounds
}
statusString = statusString + "\n" + fmt.Sprintf(
infoNodeStatusConsensusUpgradeVoting,
upgradeYesVotes,
upgradeNoVotes,
upgradeNextProtocolVoteBefore-stat.LastRound,
upgradeVoteRounds-upgradeYesVotes-upgradeNoVotes,
upgradeVotesRequired,
upgradeNextProtocolVoteBefore,
)
Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/api/server/v2/generated/model/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions daemon/algod/api/server/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

consensus := config.Consensus[protocol.ConsensusCurrentVersion]
upgradeVoteRounds := consensus.UpgradeVoteRounds
upgradeThreshold := consensus.UpgradeThreshold
votes := uint64(consensus.UpgradeVoteRounds) - uint64(votesToGo)
votes := consensus.UpgradeVoteRounds - votesToGo
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
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/api/server/v2/test/handlers_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func setupTestForLargeResources(t *testing.T, acctSize, maxResults int, accountM
acctData = accountMaker(acctSize)
ml.accounts[fakeAddr] = acctData

mockNode := makeMockNode(&ml, t.Name(), nil, false)
mockNode := makeMockNode(&ml, t.Name(), nil, cannedStatusReportGolden)
mockNode.config.MaxAPIResourcesPerAccount = uint64(maxResults)
dummyShutdownChan := make(chan struct{})
handlers = v2.Handlers{
Expand Down

0 comments on commit f8e1b78

Please sign in to comment.