multi: Reuse CurrentVoteVersion helper.

Moving CurrentVoteVersion to the config package allows it to be reused
in vote-validator.
This commit is contained in:
jholdstock 2023-09-14 14:08:53 +01:00 committed by Jamie Holdstock
parent d5d1c3239c
commit a33bcbcbfd
5 changed files with 15 additions and 19 deletions

View File

@ -69,12 +69,7 @@ func run() int {
// Get the latest vote version. Any votes which don't match this version // Get the latest vote version. Any votes which don't match this version
// will be ignored. // will be ignored.
var latestVoteVersion uint32 latestVoteVersion := network.CurrentVoteVersion()
for version := range network.Deployments {
if version > latestVoteVersion {
latestVoteVersion = version
}
}
// Open database. // Open database.
log := slog.NewBackend(os.Stdout).Logger("") log := slog.NewBackend(os.Stdout).Logger("")

View File

@ -59,3 +59,15 @@ var SimNet = Network{
func (n *Network) DCP5Active(height int64) bool { func (n *Network) DCP5Active(height int64) bool {
return height >= n.DCP0005Height return height >= n.DCP0005Height
} }
// CurrentVoteVersion returns the most recent version in the current networks
// consensus agenda deployments.
func (n *Network) CurrentVoteVersion() uint32 {
var latestVersion uint32
for version := range n.Deployments {
if latestVersion < version {
latestVersion = version
}
}
return latestVersion
}

View File

@ -11,7 +11,6 @@ import (
"github.com/decred/dcrd/blockchain/stake/v5" "github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrec/secp256k1/v4" "github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/decred/dcrd/dcrutil/v4" "github.com/decred/dcrd/dcrutil/v4"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v4" dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v4"
@ -20,16 +19,6 @@ import (
"github.com/decred/vspd/internal/config" "github.com/decred/vspd/internal/config"
) )
func currentVoteVersion(params *chaincfg.Params) uint32 {
var latestVersion uint32
for version := range params.Deployments {
if latestVersion < version {
latestVersion = version
}
}
return latestVersion
}
// validConsensusVoteChoices returns an error if provided vote choices are not // validConsensusVoteChoices returns an error if provided vote choices are not
// valid for the most recent consensus agendas. // valid for the most recent consensus agendas.
func validConsensusVoteChoices(network *config.Network, voteVersion uint32, voteChoices map[string]string) error { func validConsensusVoteChoices(network *config.Network, voteVersion uint32, voteChoices map[string]string) error {

View File

@ -103,7 +103,7 @@ func (s *server) payFee(c *gin.Context) {
// the ticket should still be registered. // the ticket should still be registered.
validVoteChoices := true validVoteChoices := true
err = validConsensusVoteChoices(s.cfg.Network, currentVoteVersion(s.cfg.Network.Params), request.VoteChoices) err = validConsensusVoteChoices(s.cfg.Network, s.cfg.Network.CurrentVoteVersion(), request.VoteChoices)
if err != nil { if err != nil {
validVoteChoices = false validVoteChoices = false
s.log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v", s.log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v",

View File

@ -95,7 +95,7 @@ func (s *server) setVoteChoices(c *gin.Context) {
// Validate vote choices (consensus, tspend policy and treasury policy). // Validate vote choices (consensus, tspend policy and treasury policy).
err = validConsensusVoteChoices(s.cfg.Network, currentVoteVersion(s.cfg.Network.Params), request.VoteChoices) err = validConsensusVoteChoices(s.cfg.Network, s.cfg.Network.CurrentVoteVersion(), request.VoteChoices)
if err != nil { if err != nil {
s.log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v", s.log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v",
funcName, c.ClientIP(), ticket.Hash, err) funcName, c.ClientIP(), ticket.Hash, err)