From 3965cc2296d5ba5f5f8a771e85820bb085497edb Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 25 Mar 2021 10:34:27 +0300 Subject: [PATCH] [#447] innerring: Use alias type for slice of public keys Alias type provide sort function so it is better to use it everywhere where list of public keys is presented. Signed-off-by: Alex Vanin --- cmd/neofs-ir/main.go | 2 +- pkg/innerring/innerring.go | 10 +++++----- pkg/innerring/invoke/alphabet.go | 9 ++------- pkg/innerring/state.go | 4 ++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/cmd/neofs-ir/main.go b/cmd/neofs-ir/main.go index 33a6031e42..89ad6b4999 100644 --- a/cmd/neofs-ir/main.go +++ b/cmd/neofs-ir/main.go @@ -100,7 +100,7 @@ func main() { log.Info("application stopped") } -func parsePublicKeysFromString(argument string) ([]keys.PublicKey, error) { +func parsePublicKeysFromString(argument string) (keys.PublicKeys, error) { publicKeysString := strings.Split(argument, ",") return innerring.ParsePublicKeysFromStrings(publicKeysString) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 8a569ddfa9..5f6cb9491f 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -62,7 +62,7 @@ type ( key *ecdsa.PrivateKey pubKey []byte contracts *contracts - predefinedValidators []keys.PublicKey + predefinedValidators keys.PublicKeys workers []func(context.Context) @@ -664,7 +664,7 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) { return result, nil } -func parsePredefinedValidators(cfg *viper.Viper) ([]keys.PublicKey, error) { +func parsePredefinedValidators(cfg *viper.Viper) (keys.PublicKeys, error) { publicKeyStrings := cfg.GetStringSlice("morph.validators") return ParsePublicKeysFromStrings(publicKeyStrings) @@ -672,8 +672,8 @@ func parsePredefinedValidators(cfg *viper.Viper) ([]keys.PublicKey, error) { // ParsePublicKeysFromStrings returns slice of neo public keys from slice // of hex encoded strings. -func ParsePublicKeysFromStrings(pubKeys []string) ([]keys.PublicKey, error) { - publicKeys := make([]keys.PublicKey, 0, len(pubKeys)) +func ParsePublicKeysFromStrings(pubKeys []string) (keys.PublicKeys, error) { + publicKeys := make(keys.PublicKeys, 0, len(pubKeys)) for i := range pubKeys { key, err := keys.NewPublicKeyFromString(pubKeys[i]) @@ -681,7 +681,7 @@ func ParsePublicKeysFromStrings(pubKeys []string) ([]keys.PublicKey, error) { return nil, errors.Wrap(err, "can't decode public key") } - publicKeys = append(publicKeys, *key) + publicKeys = append(publicKeys, key) } return publicKeys, nil diff --git a/pkg/innerring/invoke/alphabet.go b/pkg/innerring/invoke/alphabet.go index 935241a50d..615de3c7ef 100644 --- a/pkg/innerring/invoke/alphabet.go +++ b/pkg/innerring/invoke/alphabet.go @@ -22,15 +22,10 @@ func AlphabetEmit(cli *client.Client, con util.Uint160) error { } // AlphabetVote invokes vote method on alphabet contract. -func AlphabetVote(cli *client.Client, con util.Uint160, epoch uint64, keys []keys.PublicKey) error { +func AlphabetVote(cli *client.Client, con util.Uint160, epoch uint64, keys keys.PublicKeys) error { if cli == nil { return client.ErrNilClient } - binaryKeys := make([][]byte, 0, len(keys)) - for i := range keys { - binaryKeys = append(binaryKeys, keys[i].Bytes()) - } - - return cli.NotaryInvoke(con, voteMethod, int64(epoch), binaryKeys) + return cli.NotaryInvoke(con, voteMethod, int64(epoch), keys) } diff --git a/pkg/innerring/state.go b/pkg/innerring/state.go index 1a7a3a4910..612a958b7c 100644 --- a/pkg/innerring/state.go +++ b/pkg/innerring/state.go @@ -65,7 +65,7 @@ func (s *Server) AlphabetIndex() int { return int(index) } -func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error { +func (s *Server) voteForSidechainValidator(validators keys.PublicKeys) error { index := s.InnerRingIndex() if s.contracts.alphabet.indexOutOfRange(index) { s.log.Info("ignore validator vote: node not in alphabet range") @@ -96,7 +96,7 @@ func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error { // 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 { +func (s *Server) InitAndVoteForSidechainValidator(validators keys.PublicKeys) error { err := s.initConfigFromBlockchain() if err != nil { return err