[#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 <alexey@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Alex Vanin 2020-12-04 14:27:58 +03:00 committed by Alex Vanin
parent 49666f87f1
commit e2547f5bf8
2 changed files with 19 additions and 11 deletions

View File

@ -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)
}

View File

@ -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