multi: Reuse CurrentVoteVersion helper.
Moving CurrentVoteVersion to the config package allows it to be reused in vote-validator.
This commit is contained in:
parent
d5d1c3239c
commit
a33bcbcbfd
@ -69,12 +69,7 @@ func run() int {
|
||||
|
||||
// Get the latest vote version. Any votes which don't match this version
|
||||
// will be ignored.
|
||||
var latestVoteVersion uint32
|
||||
for version := range network.Deployments {
|
||||
if version > latestVoteVersion {
|
||||
latestVoteVersion = version
|
||||
}
|
||||
}
|
||||
latestVoteVersion := network.CurrentVoteVersion()
|
||||
|
||||
// Open database.
|
||||
log := slog.NewBackend(os.Stdout).Logger("")
|
||||
|
||||
@ -59,3 +59,15 @@ var SimNet = Network{
|
||||
func (n *Network) DCP5Active(height int64) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/decred/dcrd/blockchain/stake/v5"
|
||||
"github.com/decred/dcrd/chaincfg/chainhash"
|
||||
"github.com/decred/dcrd/chaincfg/v3"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/decred/dcrd/dcrutil/v4"
|
||||
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v4"
|
||||
@ -20,16 +19,6 @@ import (
|
||||
"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
|
||||
// valid for the most recent consensus agendas.
|
||||
func validConsensusVoteChoices(network *config.Network, voteVersion uint32, voteChoices map[string]string) error {
|
||||
|
||||
@ -103,7 +103,7 @@ func (s *server) payFee(c *gin.Context) {
|
||||
// the ticket should still be registered.
|
||||
|
||||
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 {
|
||||
validVoteChoices = false
|
||||
s.log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v",
|
||||
|
||||
@ -95,7 +95,7 @@ func (s *server) setVoteChoices(c *gin.Context) {
|
||||
|
||||
// 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 {
|
||||
s.log.Warnf("%s: Invalid consensus vote choices (clientIP=%s, ticketHash=%s): %v",
|
||||
funcName, c.ClientIP(), ticket.Hash, err)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user