aboutsummaryrefslogtreecommitdiffstats
path: root/core/types
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-14 15:32:27 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:53 +0800
commit2cbbadc739c79b2fb488a6e7e0ac7593ac469737 (patch)
tree391e27c766a75e545e36315dea54d5bfbf508fbf /core/types
parent129b9f9f5c5c8b8c6581d1ebd68c3e31157ea570 (diff)
downloaddexon-2cbbadc739c79b2fb488a6e7e0ac7593ac469737.tar
dexon-2cbbadc739c79b2fb488a6e7e0ac7593ac469737.tar.gz
dexon-2cbbadc739c79b2fb488a6e7e0ac7593ac469737.tar.bz2
dexon-2cbbadc739c79b2fb488a6e7e0ac7593ac469737.tar.lz
dexon-2cbbadc739c79b2fb488a6e7e0ac7593ac469737.tar.xz
dexon-2cbbadc739c79b2fb488a6e7e0ac7593ac469737.tar.zst
dexon-2cbbadc739c79b2fb488a6e7e0ac7593ac469737.zip
core, dex: Optimize sender calculation in block transactions. (#22)
* Add Transactions.TouchSenders that calculates sender and update cache * Use TouchSenders to fill the caches
Diffstat (limited to 'core/types')
-rw-r--r--core/types/transaction.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 857ac2137..46c24bd81 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -21,6 +21,7 @@ import (
"errors"
"io"
"math/big"
+ "sync"
"sync/atomic"
"github.com/dexon-foundation/dexon/common"
@@ -271,6 +272,35 @@ func (s Transactions) GetRlp(i int) []byte {
return enc
}
+// TouchSenders calculates the sender of each transaction and update the cache.
+func (s Transactions) TouchSenders(signer Signer) (errorTx *Transaction, err error) {
+ wg := sync.WaitGroup{}
+ wg.Add(len(s))
+ txError := make(chan error, 1)
+ for _, tx := range s {
+ go func(tx *Transaction) {
+ defer wg.Done()
+ if len(txError) > 0 {
+ return
+ }
+ _, err := Sender(signer, tx)
+ if err != nil {
+ select {
+ case txError <- err:
+ errorTx = tx
+ default:
+ }
+ }
+ }(tx)
+ }
+ wg.Wait()
+ select {
+ case err = <-txError:
+ default:
+ }
+ return
+}
+
// TxDifference returns a new set which is the difference between a and b.
func TxDifference(a, b Transactions) Transactions {
keep := make(Transactions, 0, len(a))