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 == shard.ErrValidNotInCommittee {
consensus.getLogger().Info().
Hex("senderKey", msg.GetConsensus().SenderPubkey).Msgf(
Hex("senderKey", msg.GetViewchange().SenderPubkey).Msgf(
"[%s] sender key not in this slot's subcommittee",
msg.GetType().String(),
)

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

Loading…
Cancel
Save