From 0a48465e804c4a2a7ab81fd381bac3a105a41f01 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Thu, 14 Mar 2019 13:15:03 +0800 Subject: dex: priority for ba vote (#256) * dex: priority select on vote * More aggressive priority for vote * collect all queuedVotes --- dex/peer.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dex/peer.go b/dex/peer.go index 64798aaaf..d0b81a03e 100644 --- a/dex/peer.go +++ b/dex/peer.go @@ -201,7 +201,24 @@ func newPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer { // transaction and notary node records broadcasts into the remote peer. // The goal is to have an async writer that does not lock up node internals. func (p *peer) broadcast() { + queuedVotes := make([]*coreTypes.Vote, 0, maxQueuedVotes) for { + PriorityBroadcastVote: + for { + select { + case votes := <-p.queuedVotes: + queuedVotes = append(queuedVotes, votes...) + default: + break PriorityBroadcastVote + } + } + if len(queuedVotes) != 0 { + if err := p.SendVotes(queuedVotes); err != nil { + return + } + p.Log().Trace("Broadcast votes", "count", len(queuedVotes)) + queuedVotes = queuedVotes[:0] + } select { case records := <-p.queuedRecords: if err := p.SendNodeRecords(records); err != nil { -- cgit v1.2.3