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 3c1a9d5 commit 8c492c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelog/4638.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/txpool: Fix crash on early access
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 8c492c2

Please sign in to comment.