[#446] innerring: Add alphabet index getter in global state

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-03-23 17:58:25 +03:00 committed by Alex Vanin
parent cd21641dfc
commit 1332db883e
3 changed files with 49 additions and 0 deletions

View file

@ -24,6 +24,11 @@ func (s *Server) IsActive() bool {
return s.InnerRingIndex() >= 0
}
// IsAlphabet is a getter for a global alphabet flag state.
func (s *Server) IsAlphabet() bool {
return s.AlphabetIndex() >= 0
}
// InnerRingIndex is a getter for a global index of node in inner ring list. Negative
// index means that node is not in the inner ring list.
func (s *Server) InnerRingIndex() int {
@ -48,6 +53,18 @@ func (s *Server) InnerRingSize() int {
return int(size)
}
// AlphabetIndex is a getter for a global index of node in alphabet list.
// Negative index means that node is not in the alphabet list.
func (s *Server) AlphabetIndex() int {
index, err := s.statusIndex.AlphabetIndex()
if err != nil {
s.log.Error("can't get alphabet index", zap.String("error", err.Error()))
return -1
}
return int(index)
}
func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error {
index := s.InnerRingIndex()
if s.contracts.alphabet.indexOutOfRange(index) {