forked from TrueCloudLab/frostfs-node
[#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:
parent
0b65c64e98
commit
49666f87f1
2 changed files with 31 additions and 0 deletions
|
@ -4,7 +4,9 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neofs-node/misc"
|
"github.com/nspcc-dev/neofs-node/misc"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
|
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
|
||||||
|
@ -30,6 +32,7 @@ func exitErr(err error) {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configFile := flag.String("config", "", "path to config")
|
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")
|
versionFlag := flag.Bool("version", false, "neofs-ir node version")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -55,6 +58,16 @@ func main() {
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(*validators) != 0 {
|
||||||
|
validatorKeys, err := parsePublicKeysFromString(*validators)
|
||||||
|
exitErr(err)
|
||||||
|
|
||||||
|
err = innerRing.InitAndVoteForSidechainValidator(validatorKeys)
|
||||||
|
exitErr(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// start pprof if enabled
|
// start pprof if enabled
|
||||||
if pprof != nil {
|
if pprof != nil {
|
||||||
pprof.Start(ctx)
|
pprof.Start(ctx)
|
||||||
|
@ -86,3 +99,9 @@ func main() {
|
||||||
|
|
||||||
log.Info("application stopped")
|
log.Info("application stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parsePublicKeysFromString(argument string) ([]keys.PublicKey, error) {
|
||||||
|
publicKeysString := strings.Split(argument, ",")
|
||||||
|
|
||||||
|
return innerring.ParsePublicKeysFromStrings(publicKeysString)
|
||||||
|
}
|
||||||
|
|
|
@ -51,3 +51,15 @@ func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error {
|
||||||
|
|
||||||
return invoke.AlphabetVote(s.morphClient, s.contracts.alphabet[index], candidate)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue