Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderZhi authored and dustinxie committed Dec 21, 2023
1 parent e01d855 commit 56ac0b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions actpool/actqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"container/heap"
"context"
"math/big"
"sort"
"sync"
"time"

Expand Down Expand Up @@ -315,8 +314,6 @@ func (q *actQueue) AllActs() []action.SealedEnvelope {
if len(q.items) == 0 {
return acts
}
// WARNING: after calling this function, the queue should be destroyed
sort.Sort(q.ascQueue)
for _, nonce := range q.ascQueue {
acts = append(acts, q.items[nonce.nonce])
}
Expand All @@ -333,6 +330,7 @@ func (q *actQueue) PopActionWithLargestNonce() *action.SealedEnvelope {
heap.Remove(&q.ascQueue, itemMeta.ascIdx)
item := q.items[itemMeta.nonce]
delete(q.items, itemMeta.nonce)
q.updateFromNonce(itemMeta.nonce)

return &item
}
10 changes: 7 additions & 3 deletions actpool/queueworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"errors"
"math/big"
"sort"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -266,7 +267,11 @@ func (worker *queueWorker) AllActions(sender address.Address) ([]action.SealedEn
worker.mu.RLock()
defer worker.mu.RUnlock()
if actQueue := worker.accountActs.Account(sender.String()); actQueue != nil {
return actQueue.AllActs(), true
acts := actQueue.AllActs()
sort.Slice(acts, func(i, j int) bool {
return acts[i].Nonce() < acts[j].Nonce()
})
return acts, true
}
return nil, false
}
Expand All @@ -290,9 +295,8 @@ func (worker *queueWorker) ResetAccount(sender address.Address) []action.SealedE
if actQueue != nil {
pendingActs := actQueue.AllActs()
actQueue.Reset()
worker.mu.Lock()
// the following line is thread safe with worker.mu.RLock
worker.emptyAccounts.Set(senderStr, struct{}{})
worker.mu.Unlock()
return pendingActs
}
return nil
Expand Down

0 comments on commit 56ac0b8

Please sign in to comment.