From 65baaaaf809df08080633349d1f097fa79bcd4c8 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Fri, 10 May 2024 10:46:08 +0800 Subject: [PATCH] core: cache tx signature before obtaining lock (#19351) --- core/tx_pool.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index ac3074ce34..02677fbc2b 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -970,8 +970,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 { - tx.CacheHash() - types.CacheSigner(pool.signer, tx) + // Cache sender in transaction before obtaining lock (pool.signer is immutable) + types.Sender(pool.signer, tx) + pool.mu.Lock() defer pool.mu.Unlock() @@ -990,6 +991,10 @@ 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 { + // Cache senders in transactions before obtaining lock (pool.signer is immutable) + for _, tx := range txs { + types.Sender(pool.signer, tx) + } pool.mu.Lock() defer pool.mu.Unlock()