Merge pull request #21170 from duanhao0814/fix-dup-ecrecover

core: filter out txs with invalid signatures as soon as possible
This commit is contained in:
Péter Szilágyi 2020-06-16 11:35:16 +03:00 committed by GitHub
commit eb9d7d15ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -781,16 +781,22 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
knownTxMeter.Mark(1)
continue
}
// Exclude transactions with invalid signatures as soon as
// possible and cache senders in transactions before
// obtaining lock
_, err := types.Sender(pool.signer, tx)
if err != nil {
errs[i] = ErrInvalidSender
invalidTxMeter.Mark(1)
continue
}
// Accumulate all unknown transactions for deeper processing
news = append(news, tx)
}
if len(news) == 0 {
return errs
}
// Cache senders in transactions before obtaining lock (pool.signer is immutable)
for _, tx := range news {
types.Sender(pool.signer, tx)
}
// Process all the new transaction and merge any errors into the original slice
pool.mu.Lock()
newErrs, dirtyAddrs := pool.addTxsLocked(news, local)