Be more specific about consensus vote choices. (#278)
* Be more specific about consensus vote choices. Rather than referring to just "Vote choices", refer specifically to "consensus vote choices". This will be useful when treasury and tspend vote choices are added, and the distinction becomes more important. * dnldd suggestion.
This commit is contained in:
parent
844d1a0736
commit
c1ba46347e
@ -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
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ func blockConnected() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set vote choices on voting wallets.
|
// Set consensus vote choices on voting wallets.
|
||||||
for agenda, choice := range ticket.VoteChoices {
|
for agenda, choice := range ticket.VoteChoices {
|
||||||
err = walletClient.SetVoteChoice(agenda, choice, ticket.Hash)
|
err = walletClient.SetVoteChoice(agenda, choice, ticket.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -513,7 +513,7 @@ func checkWalletConsistency() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if vote choices match
|
// Check if consensus vote choices match
|
||||||
for dbAgenda, dbChoice := range dbTicket.VoteChoices {
|
for dbAgenda, dbChoice := range dbTicket.VoteChoices {
|
||||||
match := false
|
match := false
|
||||||
for _, walletChoice := range walletTicket.Choices {
|
for _, walletChoice := range walletTicket.Choices {
|
||||||
@ -527,7 +527,7 @@ func checkWalletConsistency() {
|
|||||||
continue
|
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)
|
funcName, walletClient.String(), dbAgenda, dbTicket.Hash)
|
||||||
|
|
||||||
// If db and wallet are not matching, update wallet with correct
|
// If db and wallet are not matching, update wallet with correct
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func exampleTicket() Ticket {
|
|||||||
FeeAmount: 10000000,
|
FeeAmount: 10000000,
|
||||||
FeeExpiration: 4,
|
FeeExpiration: 4,
|
||||||
Confirmed: false,
|
Confirmed: false,
|
||||||
VoteChoices: map[string]string{"AgendaID": "Choice"},
|
VoteChoices: map[string]string{"AgendaID": "yes"},
|
||||||
VotingWIF: randString(53, addrCharset),
|
VotingWIF: randString(53, addrCharset),
|
||||||
FeeTxHex: randString(504, hexCharset),
|
FeeTxHex: randString(504, hexCharset),
|
||||||
FeeTxHash: randString(64, hexCharset),
|
FeeTxHash: randString(64, hexCharset),
|
||||||
|
|||||||
@ -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
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ func payFee(c *gin.Context) {
|
|||||||
err = validConsensusVoteChoices(cfg.NetParams, currentVoteVersion(cfg.NetParams), request.VoteChoices)
|
err = validConsensusVoteChoices(cfg.NetParams, currentVoteVersion(cfg.NetParams), request.VoteChoices)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
validVoteChoices = false
|
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)
|
funcName, c.ClientIP(), ticket.Hash, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
@ -92,10 +92,9 @@ func setVoteChoices(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
voteChoices := request.VoteChoices
|
err = validConsensusVoteChoices(cfg.NetParams, currentVoteVersion(cfg.NetParams), request.VoteChoices)
|
||||||
err = validConsensusVoteChoices(cfg.NetParams, currentVoteVersion(cfg.NetParams), voteChoices)
|
|
||||||
if err != nil {
|
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)
|
funcName, c.ClientIP(), ticket.Hash, err)
|
||||||
sendErrorWithMsg(err.Error(), errInvalidVoteChoices, c)
|
sendErrorWithMsg(err.Error(), errInvalidVoteChoices, c)
|
||||||
return
|
return
|
||||||
@ -103,7 +102,8 @@ func setVoteChoices(c *gin.Context) {
|
|||||||
|
|
||||||
// Update VoteChoices in the database before updating the wallets. DB is the
|
// Update VoteChoices in the database before updating the wallets. DB is the
|
||||||
// source of truth, and also is less likely to error.
|
// source of truth, and also is less likely to error.
|
||||||
ticket.VoteChoices = voteChoices
|
ticket.VoteChoices = request.VoteChoices
|
||||||
|
|
||||||
err = db.UpdateTicket(ticket)
|
err = db.UpdateTicket(ticket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%s: db.UpdateTicket error, failed to set vote choices (ticketHash=%s): %v",
|
log.Errorf("%s: db.UpdateTicket error, failed to set vote choices (ticketHash=%s): %v",
|
||||||
@ -115,16 +115,20 @@ func setVoteChoices(c *gin.Context) {
|
|||||||
// Update vote choices on voting wallets. Tickets are only added to voting
|
// Update vote choices on voting wallets. Tickets are only added to voting
|
||||||
// wallets if their fee is confirmed.
|
// wallets if their fee is confirmed.
|
||||||
if ticket.FeeTxStatus == database.FeeConfirmed {
|
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 _, walletClient := range walletClients {
|
||||||
for agenda, choice := range voteChoices {
|
|
||||||
|
// Set consensus vote choices.
|
||||||
|
for agenda, choice := range request.VoteChoices {
|
||||||
err = walletClient.SetVoteChoice(agenda, choice, ticket.Hash)
|
err = walletClient.SetVoteChoice(agenda, choice, ticket.Hash)
|
||||||
if err != nil {
|
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",
|
log.Errorf("%s: dcrwallet.SetVoteChoice failed (wallet=%s, ticketHash=%s): %v",
|
||||||
funcName, walletClient.String(), ticket.Hash, err)
|
funcName, walletClient.String(), ticket.Hash, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -223,11 +223,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h1>Voting</h1>
|
<h1>Vote Choices</h1>
|
||||||
|
|
||||||
<table id="ticket-table" class="mt-2 mb-4 w-100">
|
<table id="ticket-table" class="mt-2 mb-4 w-100">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Current Vote Choices</th>
|
<th>Consensus Vote Choices</th>
|
||||||
<td>
|
<td>
|
||||||
{{ range $key, $value := .Ticket.VoteChoices }}
|
{{ range $key, $value := .Ticket.VoteChoices }}
|
||||||
{{ $key }}: {{ $value }} <br />
|
{{ $key }}: {{ $value }} <br />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user