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

Be more specific about consensus vote choices. #278

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions background/background.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 The Decred developers
// Copyright (c) 2020-2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -212,7 +212,7 @@ func blockConnected() {
continue
}

// Set vote choices on voting wallets.
// Set consensus vote choices on voting wallets.
for agenda, choice := range ticket.VoteChoices {
err = walletClient.SetVoteChoice(agenda, choice, ticket.Hash)
if err != nil {
Expand Down Expand Up @@ -513,7 +513,7 @@ func checkWalletConsistency() {
continue
}

// Check if vote choices match
// Check if consensus vote choices match
for dbAgenda, dbChoice := range dbTicket.VoteChoices {
match := false
for _, walletChoice := range walletTicket.Choices {
Expand All @@ -527,7 +527,7 @@ func checkWalletConsistency() {
continue
}

log.Debugf("%s: Updating incorrect vote choices (wallet=%s, agenda=%s, ticketHash=%s)",
log.Debugf("%s: Updating incorrect consensus vote choices (wallet=%s, agenda=%s, ticketHash=%s)",
funcName, walletClient.String(), dbAgenda, dbTicket.Hash)

// If db and wallet are not matching, update wallet with correct
Expand Down
2 changes: 1 addition & 1 deletion database/ticket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func exampleTicket() Ticket {
FeeAmount: 10000000,
FeeExpiration: 4,
Confirmed: false,
VoteChoices: map[string]string{"AgendaID": "Choice"},
VoteChoices: map[string]string{"AgendaID": "yes"},
VotingWIF: randString(53, addrCharset),
FeeTxHex: randString(504, hexCharset),
FeeTxHash: randString(64, hexCharset),
Expand Down
4 changes: 2 additions & 2 deletions webapi/payfee.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 The Decred developers
// Copyright (c) 2020-2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -103,7 +103,7 @@ func payFee(c *gin.Context) {
err = validConsensusVoteChoices(cfg.NetParams, currentVoteVersion(cfg.NetParams), request.VoteChoices)
if err != nil {
validVoteChoices = false
log.Warnf("%s: Invalid vote choices (clientIP=%s, ticketHash=%s): %v",
log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v",
funcName, c.ClientIP(), ticket.Hash, err)
}

Expand Down
20 changes: 12 additions & 8 deletions webapi/setvotechoices.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 The Decred developers
// Copyright (c) 2020-2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -92,18 +92,18 @@ func setVoteChoices(c *gin.Context) {
}
}

voteChoices := request.VoteChoices
err = validConsensusVoteChoices(cfg.NetParams, currentVoteVersion(cfg.NetParams), voteChoices)
err = validConsensusVoteChoices(cfg.NetParams, currentVoteVersion(cfg.NetParams), request.VoteChoices)
if err != nil {
log.Warnf("%s: Invalid vote choices (clientIP=%s, ticketHash=%s): %v",
log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v",
funcName, c.ClientIP(), ticket.Hash, err)
sendErrorWithMsg(err.Error(), errInvalidVoteChoices, c)
return
}

// Update VoteChoices in the database before updating the wallets. DB is the
// source of truth, and also is less likely to error.
ticket.VoteChoices = voteChoices
ticket.VoteChoices = request.VoteChoices

err = db.UpdateTicket(ticket)
if err != nil {
log.Errorf("%s: db.UpdateTicket error, failed to set vote choices (ticketHash=%s): %v",
Expand All @@ -115,16 +115,20 @@ func setVoteChoices(c *gin.Context) {
// Update vote choices on voting wallets. Tickets are only added to voting
// wallets if their fee is confirmed.
if ticket.FeeTxStatus == database.FeeConfirmed {

// Just log any errors which occur while setting vote choices. We want
// to attempt to update as much as possible regardless of any errors.
for _, walletClient := range walletClients {
for agenda, choice := range voteChoices {

// Consensus vote choices.
Copy link
Member

Choose a reason for hiding this comment

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

s/ Consensus vote choices. / Set consensus vote choices.

for agenda, choice := range request.VoteChoices {
err = walletClient.SetVoteChoice(agenda, choice, ticket.Hash)
if err != nil {
// If this fails, we still want to try the other wallets, so
// don't return an error response, just log an error.
log.Errorf("%s: dcrwallet.SetVoteChoice failed (wallet=%s, ticketHash=%s): %v",
funcName, walletClient.String(), ticket.Hash, err)
}
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions webapi/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ <h1>Fee</h1>
</tr>
</table>

<h1>Voting</h1>
<h1>Vote Choices</h1>

<table id="ticket-table" class="mt-2 mb-4 w-100">
<tr>
<th>Current Vote Choices</th>
<th>Consensus Vote Choices</th>
<td>
{{ range $key, $value := .Ticket.VoteChoices }}
{{ $key }}: {{ $value }} <br />
Expand Down