Skip to content

Commit

Permalink
Merge PR: optimize precommit long time consuming (#1945)
Browse files Browse the repository at this point in the history
* broadcast vote at once

* update msg format

* add debug info

* remove log

* add debug info

* add debug info

* remove log

* reuse Broadcast

Co-authored-by: xiangjianmeng <[email protected]>
  • Loading branch information
lisuxiaoqi and xiangjianmeng authored Apr 28, 2022
1 parent b16c5f0 commit 4926092
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libs/tendermint/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,8 @@ func (cs *State) signAddVote(msgType types.SignedMsgType, hash []byte, header ty
// TODO: pass pubKey to signVote
vote, err := cs.signVote(msgType, hash, header)
if err == nil {
//broadcast vote immediately
cs.evsw.FireEvent(types.EventSignVote, vote)
cs.sendInternalMessage(msgInfo{&VoteMessage{vote}, ""})
cs.Logger.Info("Signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote, "err", err)
return vote
Expand Down
10 changes: 9 additions & 1 deletion libs/tendermint/consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ func (conR *Reactor) subscribeToBroadcastEvents() {
func(data tmevents.EventData) {
conR.broadcastHasVoteMessage(data.(*types.Vote))
})

conR.conS.evsw.AddListenerForEvent(subscriber, types.EventSignVote,
func(data tmevents.EventData) {
conR.broadcastSignVoteMessage(data.(*types.Vote))
})
}

func (conR *Reactor) unsubscribeFromBroadcastEvents() {
Expand Down Expand Up @@ -527,7 +532,10 @@ func (conR *Reactor) broadcastHasVoteMessage(vote *types.Vote) {
}
*/
}

func (conR *Reactor) broadcastSignVoteMessage(vote *types.Vote) {
msg := &VoteMessage{vote}
conR.Switch.Broadcast(VoteChannel, cdc.MustMarshalBinaryBare(msg))
}
func makeRoundStepMessage(rs *cstypes.RoundState) (nrsMsg *NewRoundStepMessage) {
nrsMsg = &NewRoundStepMessage{
Height: rs.Height,
Expand Down
1 change: 1 addition & 0 deletions libs/tendermint/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
EventUnlock = "Unlock"
EventValidBlock = "ValidBlock"
EventVote = "Vote"
EventSignVote = "SignVote"
)

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4926092

Please sign in to comment.