aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-21 10:26:36 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:53 +0800
commit9ff5a4e83badfa43c78636f06917c1a8f0a25d9f (patch)
treefb76af2716da0b597e0f6c2421daab5145414c30
parent404496ca9ac1974fff5c4e89f4fee146da7bac33 (diff)
downloadgo-tangerine-9ff5a4e83badfa43c78636f06917c1a8f0a25d9f.tar
go-tangerine-9ff5a4e83badfa43c78636f06917c1a8f0a25d9f.tar.gz
go-tangerine-9ff5a4e83badfa43c78636f06917c1a8f0a25d9f.tar.bz2
go-tangerine-9ff5a4e83badfa43c78636f06917c1a8f0a25d9f.tar.lz
go-tangerine-9ff5a4e83badfa43c78636f06917c1a8f0a25d9f.tar.xz
go-tangerine-9ff5a4e83badfa43c78636f06917c1a8f0a25d9f.tar.zst
go-tangerine-9ff5a4e83badfa43c78636f06917c1a8f0a25d9f.zip
core, dex: Batch process touchSender. Lower priority for tx. (#41)
* dex: Add a tx queue in broadcast * Modify queue parameter * Priority select all messages except tx * Batch process TouchSenders
-rw-r--r--core/types/transaction.go32
-rw-r--r--dex/handler.go1
2 files changed, 20 insertions, 13 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 46c24bd81..5e11c0dbc 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -21,6 +21,7 @@ import (
"errors"
"io"
"math/big"
+ "runtime"
"sync"
"sync/atomic"
@@ -274,24 +275,29 @@ func (s Transactions) GetRlp(i int) []byte {
// TouchSenders calculates the sender of each transaction and update the cache.
func (s Transactions) TouchSenders(signer Signer) (errorTx *Transaction, err error) {
+ num := runtime.NumCPU()
+ batchSize := len(s) / num
wg := sync.WaitGroup{}
- wg.Add(len(s))
+ wg.Add(num)
txError := make(chan error, 1)
- for _, tx := range s {
- go func(tx *Transaction) {
+ for i := 0; i < num; i++ {
+ go func(txs Transactions) {
defer wg.Done()
- if len(txError) > 0 {
- return
- }
- _, err := Sender(signer, tx)
- if err != nil {
- select {
- case txError <- err:
- errorTx = tx
- default:
+ for _, tx := range txs {
+ if len(txError) > 0 {
+ return
+ }
+ _, err := Sender(signer, tx)
+ if err != nil {
+ select {
+ case txError <- err:
+ errorTx = tx
+ default:
+ }
+ return
}
}
- }(tx)
+ }(s[i*batchSize : (i+1)*batchSize])
}
wg.Wait()
select {
diff --git a/dex/handler.go b/dex/handler.go
index 3c8d25ea3..a74c78e3b 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -724,6 +724,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
p.MarkTransaction(tx.Hash())
}
+ types.Transactions(txs).TouchSenders(types.MakeSigner(pm.blockchain.Config(), new(big.Int)))
pm.txpool.AddRemotes(txs)
case msg.Code == MetaMsg: