Avoid validator sending msgs if the key is not in committee

pull/3183/head v2.1.8
Rongjian Lan 4 years ago committed by Leo Chen
parent 525a618b81
commit 71e9abdcbf
  1. 7
      consensus/validator.go
  2. 6
      consensus/view_change.go

@ -60,6 +60,9 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
func (consensus *Consensus) prepare() { func (consensus *Consensus) prepare() {
groupID := []nodeconfig.GroupID{nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))} groupID := []nodeconfig.GroupID{nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))}
for i, key := range consensus.PubKey.PublicKey { for i, key := range consensus.PubKey.PublicKey {
if !consensus.IsValidatorInCommittee(key) {
continue
}
networkMessage, err := consensus.construct(msg_pb.MessageType_PREPARE, nil, key, consensus.priKey.PrivateKey[i]) networkMessage, err := consensus.construct(msg_pb.MessageType_PREPARE, nil, key, consensus.priKey.PrivateKey[i])
if err != nil { if err != nil {
consensus.getLogger().Err(err). consensus.getLogger().Err(err).
@ -208,6 +211,10 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)), nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)),
} }
for i, key := range consensus.PubKey.PublicKey { for i, key := range consensus.PubKey.PublicKey {
if !consensus.IsValidatorInCommittee(key) {
continue
}
networkMessage, _ := consensus.construct( networkMessage, _ := consensus.construct(
msg_pb.MessageType_COMMIT, msg_pb.MessageType_COMMIT,
commitPayload, commitPayload,

@ -136,6 +136,9 @@ func (consensus *Consensus) startViewChange(viewID uint64) {
Msg("[startViewChange]") Msg("[startViewChange]")
for i, key := range consensus.PubKey.PublicKey { for i, key := range consensus.PubKey.PublicKey {
if !consensus.IsValidatorInCommittee(key) {
continue
}
msgToSend := consensus.constructViewChangeMessage(key, consensus.priKey.PrivateKey[i]) msgToSend := consensus.constructViewChangeMessage(key, consensus.priKey.PrivateKey[i])
consensus.host.SendMessageToGroups([]nodeconfig.GroupID{ consensus.host.SendMessageToGroups([]nodeconfig.GroupID{
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)), nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)),
@ -624,6 +627,9 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
groupID := []nodeconfig.GroupID{ groupID := []nodeconfig.GroupID{
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))} nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))}
for i, key := range consensus.PubKey.PublicKey { for i, key := range consensus.PubKey.PublicKey {
if !consensus.IsValidatorInCommittee(key) {
continue
}
network, err := consensus.construct( network, err := consensus.construct(
msg_pb.MessageType_COMMIT, msg_pb.MessageType_COMMIT,
commitPayload, commitPayload,

Loading…
Cancel
Save