revert unnecessary change

This commit is contained in:
maskpp 2025-08-17 16:40:06 +08:00
parent 22e0abd3a5
commit 076d8c78fe

View file

@ -946,8 +946,8 @@ func (pool *LegacyPool) addRemoteSync(tx *types.Transaction) error {
func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error { func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error {
// Filter out known ones without obtaining the pool lock or recovering signatures // Filter out known ones without obtaining the pool lock or recovering signatures
var ( var (
errs = make([]error, len(txs)) errs = make([]error, len(txs))
verifiedTxs int news = make([]*types.Transaction, 0, len(txs))
) )
for i, tx := range txs { for i, tx := range txs {
// If the transaction is known, pre-set the error slot // If the transaction is known, pre-set the error slot
@ -965,18 +965,26 @@ func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error {
invalidTxMeter.Mark(1) invalidTxMeter.Mark(1)
continue continue
} }
verifiedTxs++ // Accumulate all unknown transactions for deeper processing
news = append(news, tx)
} }
if verifiedTxs == 0 { if len(news) == 0 {
return errs return errs
} }
// Process all the new transaction and merge any errors into the original slice // Process all the new transaction and merge any errors into the original slice
var dirtyAddrs *accountSet
pool.mu.Lock() pool.mu.Lock()
errs, dirtyAddrs = pool.addTxsLocked(txs, errs) newErrs, dirtyAddrs := pool.addTxsLocked(news)
pool.mu.Unlock() pool.mu.Unlock()
var nilSlot = 0
for _, err := range newErrs {
for errs[nilSlot] != nil {
nilSlot++
}
errs[nilSlot] = err
nilSlot++
}
// Reorg the pool internals if needed and return // Reorg the pool internals if needed and return
done := pool.requestPromoteExecutables(dirtyAddrs) done := pool.requestPromoteExecutables(dirtyAddrs)
if sync { if sync {
@ -987,15 +995,10 @@ func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error {
// addTxsLocked attempts to queue a batch of transactions if they are valid. // addTxsLocked attempts to queue a batch of transactions if they are valid.
// The transaction pool lock must be held. // The transaction pool lock must be held.
func (pool *LegacyPool) addTxsLocked(txs []*types.Transaction, errs []error) ([]error, *accountSet) { func (pool *LegacyPool) addTxsLocked(txs []*types.Transaction) ([]error, *accountSet) {
dirty := newAccountSet(pool.signer) dirty := newAccountSet(pool.signer)
if errs == nil { errs := make([]error, len(txs))
errs = make([]error, len(txs))
}
for i, tx := range txs { for i, tx := range txs {
if errs[i] != nil {
continue
}
replaced, err := pool.add(tx) replaced, err := pool.add(tx)
errs[i] = err errs[i] = err
if err == nil && !replaced { if err == nil && !replaced {
@ -1436,7 +1439,7 @@ func (pool *LegacyPool) reset(oldHead, newHead *types.Header) {
// Inject any transactions discarded due to reorgs // Inject any transactions discarded due to reorgs
log.Debug("Reinjecting stale transactions", "count", len(reinject)) log.Debug("Reinjecting stale transactions", "count", len(reinject))
core.SenderCacher().Recover(pool.signer, reinject) core.SenderCacher().Recover(pool.signer, reinject)
pool.addTxsLocked(reinject, nil) pool.addTxsLocked(reinject)
} }
// promoteExecutables moves transactions that have become processable from the // promoteExecutables moves transactions that have become processable from the