Skip to content

Commit

Permalink
go/runtime/txpool: Fix crash on early access
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Apr 4, 2022
1 parent 0675805 commit 628d4e4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions go/runtime/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func (t *txPool) RemoveTxBatch(txs []hash.Hash) {
t.schedulerLock.Lock()
defer t.schedulerLock.Unlock()

if t.schedulerQueue == nil {
return
}
t.schedulerQueue.RemoveTxBatch(txs)

pendingScheduleSize.With(t.getMetricLabels()).Set(float64(t.schedulerQueue.Size()))
Expand All @@ -282,20 +285,35 @@ func (t *txPool) GetScheduledBatch(force bool) []*transaction.CheckedTransaction
t.schedulerLock.Lock()
defer t.schedulerLock.Unlock()

if t.schedulerQueue == nil {
return nil
}
return t.schedulerQueue.GetBatch(force)
}

func (t *txPool) GetPrioritizedBatch(offset *hash.Hash, limit uint32) []*transaction.CheckedTransaction {
t.schedulerLock.Lock()
defer t.schedulerLock.Unlock()

if t.schedulerQueue == nil {
return nil
}
return t.schedulerQueue.GetPrioritizedBatch(offset, limit)
}

func (t *txPool) GetKnownBatch(batch []hash.Hash) ([]*transaction.CheckedTransaction, map[hash.Hash]int) {
t.schedulerLock.Lock()
defer t.schedulerLock.Unlock()

if t.schedulerQueue == nil {
result := make([]*transaction.CheckedTransaction, 0, len(batch))
missing := make(map[hash.Hash]int)
for index, txHash := range batch {
result = append(result, nil)
missing[txHash] = index
}
return result, missing
}
return t.schedulerQueue.GetKnownBatch(batch)
}

Expand Down

0 comments on commit 628d4e4

Please sign in to comment.