[#170] Implement validator voting function in inner ring
This function calculates validator key based on inner ring index and invokes `Vote` method of corresponding alphabet contract. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
d02c24db5c
commit
2240cde826
1 changed files with 30 additions and 0 deletions
|
@ -1,5 +1,10 @@
|
||||||
package innerring
|
package innerring
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
|
||||||
|
)
|
||||||
|
|
||||||
// EpochCounter is a getter for a global epoch counter.
|
// EpochCounter is a getter for a global epoch counter.
|
||||||
func (s *Server) EpochCounter() uint64 {
|
func (s *Server) EpochCounter() uint64 {
|
||||||
return s.epochCounter.Load()
|
return s.epochCounter.Load()
|
||||||
|
@ -21,3 +26,28 @@ func (s *Server) IsActive() bool {
|
||||||
func (s *Server) Index() int32 {
|
func (s *Server) Index() int32 {
|
||||||
return s.innerRingIndex.Load()
|
return s.innerRingIndex.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error {
|
||||||
|
index := s.Index()
|
||||||
|
if index < 0 || index >= alphabetContractsN {
|
||||||
|
s.log.Info("ignore validator vote: node not in alphabet range")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(validators) == 0 {
|
||||||
|
s.log.Info("ignore validator vote: empty validators list")
|
||||||
|
|
||||||
|
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)]
|
||||||
|
|
||||||
|
return invoke.AlphabetVote(s.morphClient, s.contracts.alphabet[index], candidate)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue