Skip to content

Commit

Permalink
core: cache tx signature before obtaining lock (ethereum#19351)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed May 10, 2024
1 parent c5b22fb commit 65baaaa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down

0 comments on commit 65baaaa

Please sign in to comment.