aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-21 10:26:36 +0800
committerWei-Ning Huang <w@dexon.org>2018-12-19 20:54:27 +0800
commit2cf60ac04074e08bf5f33d72c763e988ea4db82c (patch)
tree63572759a0ce1a7218b9484514d89a7d32d80bb5 /core
parent527f41661d7fdfa23abe1402847cc8c7da6e8e12 (diff)
downloaddexon-2cf60ac04074e08bf5f33d72c763e988ea4db82c.tar
dexon-2cf60ac04074e08bf5f33d72c763e988ea4db82c.tar.gz
dexon-2cf60ac04074e08bf5f33d72c763e988ea4db82c.tar.bz2
dexon-2cf60ac04074e08bf5f33d72c763e988ea4db82c.tar.lz
dexon-2cf60ac04074e08bf5f33d72c763e988ea4db82c.tar.xz
dexon-2cf60ac04074e08bf5f33d72c763e988ea4db82c.tar.zst
dexon-2cf60ac04074e08bf5f33d72c763e988ea4db82c.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
Diffstat (limited to 'core')
-rw-r--r--core/types/transaction.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 63195f4fd..6ee6e4494 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 {