Skip to content

Commit 8523ad4

Browse files
committed
core: filter out txs with invalid signatures as soon as possible
Once we detect an invalid transaction during recovering signatures, we should directly exclude this transaction to avoid validating the signatures hereafter. This should optimize the validations times of transactions with invalid signatures to only one time.
1 parent 8b83125 commit 8523ad4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎core/tx_pool.go‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,16 +781,22 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
781781
knownTxMeter.Mark(1)
782782
continue
783783
}
784+
// Exclude transactions with invalid signatures as soon as
785+
// possible and cache senders in transactions before
786+
// obtaining lock
787+
_, err := types.Sender(pool.signer, tx)
788+
if err != nil {
789+
errs[i] = ErrInvalidSender
790+
invalidTxMeter.Mark(1)
791+
continue
792+
}
784793
// Accumulate all unknown transactions for deeper processing
785794
news = append(news, tx)
786795
}
787796
if len(news) == 0 {
788797
return errs
789798
}
790-
// Cache senders in transactions before obtaining lock (pool.signer is immutable)
791-
for _, tx := range news {
792-
types.Sender(pool.signer, tx)
793-
}
799+
794800
// Process all the new transaction and merge any errors into the original slice
795801
pool.mu.Lock()
796802
newErrs, dirtyAddrs := pool.addTxsLocked(news, local)

0 commit comments

Comments
 (0)