Skip to content

Commit

Permalink
ir: Do not vote for the same validators list twice
Browse files Browse the repository at this point in the history
Closes #2365.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Jul 24, 2023
1 parent d6c6c31 commit e77a8d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog for NeoFS Node
### Fixed
- `neo-go` RPC connection loss handling (#1337)
- Concurrent morph cache misses (#1248)
- Double voting for validators on IR startup (#2365)

### Removed
- Deprecated `morph.rpc_endpoint` SN and `morph.endpoint.client` IR config sections (#2400)
Expand Down
36 changes: 35 additions & 1 deletion pkg/innerring/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"sort"

"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/governance"
auditClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit"
Expand Down Expand Up @@ -108,13 +109,21 @@ func (s *Server) voteForSidechainValidator(prm governance.VoteValidatorPrm) erro
return nil
}

voted, err := s.alreadyVoted(validators)
if err != nil {
return fmt.Errorf("could not check validators state: %w", err)
}

if voted {
return nil
}

epoch := s.EpochCounter()

var (
nonce uint32 = 1
vub uint32
vubP *uint32
err error
)

if prm.Hash != nil {
Expand All @@ -138,6 +147,31 @@ func (s *Server) voteForSidechainValidator(prm governance.VoteValidatorPrm) erro
return nil
}

func (s *Server) alreadyVoted(validatorsToVote keys.PublicKeys) (bool, error) {
currentValidator := make(map[keys.PublicKey]struct{}, len(s.contracts.alphabet))
for letter, contract := range s.contracts.alphabet {
validator, err := s.morphClient.VotesFor(contract)
if err != nil {
return false, fmt.Errorf("receiving %s's vote: %w", letter, err)
}

if validator == nil {
continue
}

currentValidator[*validator] = struct{}{}
}

for _, v := range validatorsToVote {
_, voted := currentValidator[*v]
if !voted {
return false, nil
}
}

return true, nil
}

// VoteForSidechainValidator calls vote method on alphabet contracts with
// the provided list of keys.
func (s *Server) VoteForSidechainValidator(prm governance.VoteValidatorPrm) error {
Expand Down

0 comments on commit e77a8d1

Please sign in to comment.