Skip to content

Commit 12ea1ce

Browse files
committed
Remove unnessary broadcast target
Don't need to broadcast to peer self. Though a receive from nil channel blocks forever, it's better to reduce a goroutine. Change-Id: I731af8ec9541967e4fa2892ad1df21952ef684b7 Signed-off-by: jiangyaoguo <[email protected]>
1 parent 8ea25a9 commit 12ea1ce

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

consensus/pbft/broadcast.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func newBroadcaster(self uint64, N int, f int, c communicator) *broadcaster {
6363

6464
// We do not start the go routines in the above loop to avoid concurrent map read/writes
6565
for i := 0; i < N; i++ {
66+
if uint64(i) == self {
67+
continue
68+
}
6669
go b.drainer(uint64(i))
6770
}
6871

@@ -108,7 +111,11 @@ func (b *broadcaster) drainerSend(dest uint64, send *sendRequest, successLastTim
108111

109112
func (b *broadcaster) drainer(dest uint64) {
110113
successLastTime := false
111-
destChan := b.msgChans[dest] // Avoid doing the map lookup every send
114+
destChan, exsit := b.msgChans[dest] // Avoid doing the map lookup every send
115+
if !exsit {
116+
logger.Warningf("could not get message channel for replica %d", dest)
117+
return
118+
}
112119

113120
for {
114121
select {

0 commit comments

Comments
 (0)