[#170] Implement --vote argument in neofs-ir

With this argument neofs-ir will be run as an CLI
application that initialize inner ring server, invokes
`vote` method on corresponding alphabet contract and
exits.

User can provide a comma-separated list of validator
public keys.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-11-13 15:19:33 +03:00 committed by Alex Vanin
parent 0b65c64e98
commit 49666f87f1
2 changed files with 31 additions and 0 deletions

View file

@ -4,7 +4,9 @@ import (
"flag"
"fmt"
"os"
"strings"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-node/misc"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
@ -30,6 +32,7 @@ func exitErr(err error) {
func main() {
configFile := flag.String("config", "", "path to config")
validators := flag.String("vote", "", "hex encoded public keys split with comma")
versionFlag := flag.Bool("version", false, "neofs-ir node version")
flag.Parse()
@ -55,6 +58,16 @@ func main() {
exitErr(err)
}
if len(*validators) != 0 {
validatorKeys, err := parsePublicKeysFromString(*validators)
exitErr(err)
err = innerRing.InitAndVoteForSidechainValidator(validatorKeys)
exitErr(err)
return
}
// start pprof if enabled
if pprof != nil {
pprof.Start(ctx)
@ -86,3 +99,9 @@ func main() {
log.Info("application stopped")
}
func parsePublicKeysFromString(argument string) ([]keys.PublicKey, error) {
publicKeysString := strings.Split(argument, ",")
return innerring.ParsePublicKeysFromStrings(publicKeysString)
}

View file

@ -51,3 +51,15 @@ func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error {
return invoke.AlphabetVote(s.morphClient, s.contracts.alphabet[index], candidate)
}
// InitAndVoteForSidechainValidator is a public function to use outside of
// inner ring daemon execution. It initialize inner ring structure with data
// from blockchain and then calls vote method on corresponding alphabet contract.
func (s *Server) InitAndVoteForSidechainValidator(validators []keys.PublicKey) error {
err := s.initConfigFromBlockchain()
if err != nil {
return err
}
return s.voteForSidechainValidator(validators)
}