Skip to content

Commit

Permalink
fix panic issue when calculating txpool.Add() latency of per transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhang2023 committed Sep 11, 2024
1 parent a61bef1 commit f6b8c55
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,9 @@ func (pool *LegacyPool) addRemoteSync(tx *types.Transaction) error {
// to the add is finished. Only use this during tests for determinism!
func (pool *LegacyPool) Add(txs []*types.Transaction, local, sync bool) []error {
defer func(t0 time.Time) {
addTimer.Update(time.Since(t0) / time.Duration(len(txs)))
if len(txs) > 0 {
addTimer.Update(time.Since(t0) / time.Duration(len(txs)))
}
}(time.Now())
// Do not treat as local if local transactions have been disabled
local = local && !pool.config.NoLocals
Expand Down Expand Up @@ -1147,7 +1149,9 @@ func (pool *LegacyPool) Add(txs []*types.Transaction, local, sync bool) []error
pool.mu.Lock()
t0 := time.Now()
newErrs, dirtyAddrs := pool.addTxsLocked(news, local)
addWithLockTimer.Update(time.Since(t0) / time.Duration(len(news)))
if len(news) > 0 {
addWithLockTimer.Update(time.Since(t0) / time.Duration(len(news)))
}
pool.mu.Unlock()

var nilSlot = 0
Expand Down

0 comments on commit f6b8c55

Please sign in to comment.