From 49666f87f14ceec4d6f3a314c66b5f4e1a2fb901 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 13 Nov 2020 15:19:33 +0300 Subject: [PATCH] [#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 --- cmd/neofs-ir/main.go | 19 +++++++++++++++++++ pkg/innerring/state.go | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/cmd/neofs-ir/main.go b/cmd/neofs-ir/main.go index 32c1d52b8..33a6031e4 100644 --- a/cmd/neofs-ir/main.go +++ b/cmd/neofs-ir/main.go @@ -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) +} diff --git a/pkg/innerring/state.go b/pkg/innerring/state.go index f4d4cdbbb..94d86c4e7 100644 --- a/pkg/innerring/state.go +++ b/pkg/innerring/state.go @@ -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) +}