When broadcasting, do not wait for deliveries

If one peer is bogged down, it hinders the entire progress of the
consensus.  Consensus should be allowed to proceed even with a few
outliers still lagging behind, if enough quorum has received the message
and sent replies back.
pull/74/head
Eugene Kim 6 years ago
parent 47d8aba30f
commit d888bc2149
  1. 10
      p2p/peer.go

@ -6,7 +6,6 @@ import (
"io" "io"
"net" "net"
"runtime" "runtime"
"sync"
"time" "time"
"github.com/simple-rules/harmony-benchmark/attack" "github.com/simple-rules/harmony-benchmark/attack"
@ -43,19 +42,12 @@ func BroadcastMessage(peers []Peer, msg []byte) {
// Construct broadcast p2p message // Construct broadcast p2p message
content := ConstructP2pMessage(byte(17), msg) content := ConstructP2pMessage(byte(17), msg)
var wg sync.WaitGroup
wg.Add(len(peers))
log.Info("Start Broadcasting", "gomaxprocs", runtime.GOMAXPROCS(0)) log.Info("Start Broadcasting", "gomaxprocs", runtime.GOMAXPROCS(0))
start := time.Now() start := time.Now()
for _, peer := range peers { for _, peer := range peers {
peerCopy := peer peerCopy := peer
go func() { go send(peerCopy.Ip, peerCopy.Port, content)
defer wg.Done()
send(peerCopy.Ip, peerCopy.Port, content)
}()
} }
wg.Wait()
log.Info("Broadcasting Done", "time spent(s)", time.Now().Sub(start).Seconds()) log.Info("Broadcasting Done", "time spent(s)", time.Now().Sub(start).Seconds())
} }

Loading…
Cancel
Save