From 7f151ff133a1bfbfb7b3b909bcc8c062a6e4cdec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BA=E9=B9=8F=E9=A3=9E?= Date: Wed, 6 Mar 2019 22:31:41 +0800 Subject: [PATCH] refactor(tx_pool.go): caching signature check result before holding lock significantly improve concurrency --- core/tx_pool.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/tx_pool.go b/core/tx_pool.go index fc35d1f243..d4b7e68f0c 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -798,6 +798,9 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error { // addTx enqueues a single transaction into the pool if it is valid. func (pool *TxPool) addTx(tx *types.Transaction, local bool) error { + // caching signature check result before holding lock significantly improve concurrency + types.Sender(pool.signer, tx) + pool.mu.Lock() defer pool.mu.Unlock() @@ -816,6 +819,11 @@ func (pool *TxPool) addTx(tx *types.Transaction, local bool) error { // addTxs attempts to queue a batch of transactions if they are valid. func (pool *TxPool) addTxs(txs []*types.Transaction, local bool) []error { + // caching signature check result before holding lock significantly improve concurrency + for _, tx := range txs { + types.Sender(pool.signer, tx) + } + pool.mu.Lock() defer pool.mu.Unlock()