use normal map for key index

pull/3188/head
Rongjian Lan 4 years ago
parent b403baa35c
commit 3c8cb849af
  1. 2
      consensus/checks.go
  2. 17
      consensus/quorum/quorum.go

@ -208,7 +208,7 @@ func (consensus *Consensus) viewChangeSanityCheck(msg *msg_pb.Message) bool {
if err != nil { if err != nil {
if err == shard.ErrValidNotInCommittee { if err == shard.ErrValidNotInCommittee {
consensus.getLogger().Info(). consensus.getLogger().Info().
Hex("senderKey", msg.GetConsensus().SenderPubkey).Msgf( Hex("senderKey", msg.GetViewchange().SenderPubkey).Msgf(
"[%s] sender key not in this slot's subcommittee", "[%s] sender key not in this slot's subcommittee",
msg.GetType().String(), msg.GetType().String(),
) )

@ -3,7 +3,6 @@ package quorum
import ( import (
"fmt" "fmt"
"math/big" "math/big"
"sync"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/bls/ffi/go/bls"
@ -149,7 +148,7 @@ type cIdentities struct {
// Public keys of the committee including leader and validators // Public keys of the committee including leader and validators
publicKeys []*bls.PublicKey publicKeys []*bls.PublicKey
publicKeysByte []shard.BLSPublicKey publicKeysByte []shard.BLSPublicKey
keyIndexMap sync.Map keyIndexMap map[shard.BLSPublicKey]int
prepare *votepower.Round prepare *votepower.Round
commit *votepower.Round commit *votepower.Round
// viewIDSigs: every validator // viewIDSigs: every validator
@ -177,8 +176,8 @@ func (s *cIdentities) AggregateVotes(p Phase) *bls.Sign {
} }
func (s *cIdentities) IndexOf(pubKey shard.BLSPublicKey) int { func (s *cIdentities) IndexOf(pubKey shard.BLSPublicKey) int {
if index, ok := s.keyIndexMap.Load(pubKey); ok { if index, ok := s.keyIndexMap[pubKey]; ok {
return index.(int) return index
} }
return -1 return -1
} }
@ -215,14 +214,8 @@ func (s *cIdentities) UpdateParticipants(pubKeys []*bls.PublicKey) {
keyIndexMap[k] = i keyIndexMap[k] = i
} }
s.publicKeys = append(pubKeys[:0:0], pubKeys...) s.publicKeys = append(pubKeys[:0:0], pubKeys...)
for _, pubKey := range s.publicKeysByte {
s.keyIndexMap.Delete(pubKey)
}
s.publicKeysByte = keyBytes s.publicKeysByte = keyBytes
for i, pubKey := range s.publicKeysByte { s.keyIndexMap = keyIndexMap
s.keyIndexMap.Store(pubKey, i)
}
} }
func (s *cIdentities) ParticipantsCount() int64 { func (s *cIdentities) ParticipantsCount() int64 {
@ -329,7 +322,7 @@ func newBallotsBackedSignatureReader() *cIdentities {
return &cIdentities{ return &cIdentities{
publicKeys: []*bls.PublicKey{}, publicKeys: []*bls.PublicKey{},
publicKeysByte: []shard.BLSPublicKey{}, publicKeysByte: []shard.BLSPublicKey{},
keyIndexMap: sync.Map{}, keyIndexMap: map[shard.BLSPublicKey]int{},
prepare: votepower.NewRound(), prepare: votepower.NewRound(),
commit: votepower.NewRound(), commit: votepower.NewRound(),
viewChange: votepower.NewRound(), viewChange: votepower.NewRound(),

Loading…
Cancel
Save