Unverified Commit fbe7caf1 authored by 贺鹏飞's avatar 贺鹏飞 Committed by Péter Szilágyi

core: cache tx signature before obtaining lock

parent 5b0d3fa3
...@@ -833,6 +833,9 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error { ...@@ -833,6 +833,9 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error {
// addTx enqueues a single transaction into the pool if it is valid. // addTx enqueues a single transaction into the pool if it is valid.
func (pool *TxPool) addTx(tx *types.Transaction, local bool) error { func (pool *TxPool) addTx(tx *types.Transaction, local bool) error {
// Cache sender in transaction before obtaining lock (pool.signer is immutable)
types.Sender(pool.signer, tx)
pool.mu.Lock() pool.mu.Lock()
defer pool.mu.Unlock() defer pool.mu.Unlock()
...@@ -851,6 +854,10 @@ func (pool *TxPool) addTx(tx *types.Transaction, local bool) error { ...@@ -851,6 +854,10 @@ func (pool *TxPool) addTx(tx *types.Transaction, local bool) error {
// addTxs attempts to queue a batch of transactions if they are valid. // addTxs attempts to queue a batch of transactions if they are valid.
func (pool *TxPool) addTxs(txs []*types.Transaction, local bool) []error { 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() pool.mu.Lock()
defer pool.mu.Unlock() defer pool.mu.Unlock()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment