aboutsummaryrefslogtreecommitdiffstats
path: root/dex/peer.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-20 17:46:17 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:18 +0800
commite9532ec6357747676433acfd5f6240dada406f87 (patch)
tree126984ec350944f71a61417a4ef944a3a0e6fc00 /dex/peer.go
parentd577ca5622381f3ecad9383301d003e1519d6aad (diff)
downloadgo-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.gz
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.bz2
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.lz
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.xz
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.zst
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.zip
dex: Tx message optimization (#39)
* dex: Add a tx queue in broadcast * Modify queue parameter * Priority select all messages except tx
Diffstat (limited to 'dex/peer.go')
-rw-r--r--dex/peer.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/dex/peer.go b/dex/peer.go
index 5aa1c1b80..263dc5647 100644
--- a/dex/peer.go
+++ b/dex/peer.go
@@ -1,3 +1,20 @@
+// Copyright 2018 The dexon-consensus Authors
+// This file is part of the dexon-consensus library.
+//
+// The dexon-consensus library is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation, either version 3 of the License,
+// or (at your option) any later version.
+//
+// The dexon-consensus library is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+// General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the dexon-consensus library. If not, see
+// <http://www.gnu.org/licenses/>.
+
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
@@ -188,12 +205,6 @@ func newPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
func (p *peer) broadcast() {
for {
select {
- case txs := <-p.queuedTxs:
- if err := p.SendTransactions(txs); err != nil {
- return
- }
- p.Log().Trace("Broadcast transactions", "count", len(txs))
-
case metas := <-p.queuedMetas:
if err := p.SendNodeMetas(metas); err != nil {
return
@@ -253,6 +264,15 @@ func (p *peer) broadcast() {
p.Log().Trace("Pulling Votes", "position", pos)
case <-p.term:
return
+ case <-time.After(100 * time.Millisecond):
+ }
+ select {
+ case txs := <-p.queuedTxs:
+ if err := p.SendTransactions(txs); err != nil {
+ return
+ }
+ p.Log().Trace("Broadcast transactions", "count", len(txs))
+ default:
}
}
}