From e2547f5bf81f4e44d5770a655aa440e83b5760a5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 4 Dec 2020 14:27:58 +0300 Subject: [PATCH] [#170] Invoke all alphabet contracts for voting Now alphabet contracts use signature collection to make a vote. All inner ring nodes votes for some list of validators the same way as they vote fore new epoch or new container. As soon as list is accepted by alphabet contracts, each of them votes for one candidate from the list. Signed-off-by: Alex Vanin --- pkg/innerring/invoke/alphabet.go | 10 +++++++--- pkg/innerring/state.go | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/innerring/invoke/alphabet.go b/pkg/innerring/invoke/alphabet.go index b1f8e2c4..40094e18 100644 --- a/pkg/innerring/invoke/alphabet.go +++ b/pkg/innerring/invoke/alphabet.go @@ -22,11 +22,15 @@ func AlphabetEmit(cli *client.Client, con util.Uint160) error { } // AlphabetVote invokes vote method on alphabet contract. -func AlphabetVote(cli *client.Client, con util.Uint160, key keys.PublicKey) error { +func AlphabetVote(cli *client.Client, con util.Uint160, epoch uint64, keys []keys.PublicKey) error { if cli == nil { return client.ErrNilClient } - // there is no signature collecting, so we don't need extra fee - return cli.Invoke(con, 0, voteMethod, key.Bytes()) + binaryKeys := make([][]byte, 0, len(keys)) + for i := range keys { + binaryKeys = append(binaryKeys, keys[i].Bytes()) + } + + return cli.Invoke(con, feeOneGas, voteMethod, int64(epoch), binaryKeys) } diff --git a/pkg/innerring/state.go b/pkg/innerring/state.go index 94d86c4e..9e4453bf 100644 --- a/pkg/innerring/state.go +++ b/pkg/innerring/state.go @@ -3,6 +3,7 @@ package innerring import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-node/pkg/innerring/invoke" + "go.uber.org/zap" ) // EpochCounter is a getter for a global epoch counter. @@ -41,15 +42,18 @@ func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error { return nil } - // len(validators) can be less than 7, in this case we split votes by - // using `mod` operations, e.g: with two validators: - // - node[0] vote for validators[0], - // - node[1] vote for validators[1], - // - node[2] vote for validators[0], etc. - // If there are more than 7 validators, this function will ignore the rest. - candidate := validators[int(index)%len(validators)] + epoch := s.EpochCounter() - return invoke.AlphabetVote(s.morphClient, s.contracts.alphabet[index], candidate) + for i := range s.contracts.alphabet { + err := invoke.AlphabetVote(s.morphClient, s.contracts.alphabet[i], epoch, validators) + if err != nil { + s.log.Warn("can't invoke vote method in alphabet contract", + zap.Int("alphabet_index", i), + zap.Uint64("epoch", epoch)) + } + } + + return nil } // InitAndVoteForSidechainValidator is a public function to use outside of