[multi-bls] validator sign and send message in parallel (#3054)

pull/3061/head
Ganesha Upadhyaya 5 years ago committed by GitHub
parent cc965edba4
commit 3c6b574b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      consensus/validator.go

@ -3,6 +3,7 @@ package consensus
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"sync"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -58,8 +59,12 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
} }
func (consensus *Consensus) prepare() { func (consensus *Consensus) prepare() {
var wg sync.WaitGroup
wg.Add(len(consensus.PubKey.PublicKey))
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 {
go func(i int) {
defer wg.Done()
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).
@ -81,7 +86,9 @@ func (consensus *Consensus) prepare() {
Msg("[OnAnnounce] Sent Prepare Message!!") Msg("[OnAnnounce] Sent Prepare Message!!")
} }
} }
}(i)
} }
wg.Wait()
consensus.getLogger().Debug(). consensus.getLogger().Debug().
Str("From", consensus.phase.String()). Str("From", consensus.phase.String()).
Str("To", FBFTPrepare.String()). Str("To", FBFTPrepare.String()).
@ -207,7 +214,11 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
groupID := []nodeconfig.GroupID{ groupID := []nodeconfig.GroupID{
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)), nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)),
} }
var wg sync.WaitGroup
wg.Add(len(consensus.PubKey.PublicKey))
for i, key := range consensus.PubKey.PublicKey { for i, key := range consensus.PubKey.PublicKey {
go func(i int) {
defer wg.Done()
networkMessage, _ := consensus.construct( networkMessage, _ := consensus.construct(
msg_pb.MessageType_COMMIT, msg_pb.MessageType_COMMIT,
commitPayload, commitPayload,
@ -227,7 +238,9 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
Msg("[OnPrepared] Sent Commit Message!!") Msg("[OnPrepared] Sent Commit Message!!")
} }
} }
}(i)
} }
wg.Wait()
consensus.getLogger().Debug(). consensus.getLogger().Debug().
Str("From", consensus.phase.String()). Str("From", consensus.phase.String()).
Str("To", FBFTCommit.String()). Str("To", FBFTCommit.String()).

Loading…
Cancel
Save