Skip to content

Commit 56ac0b8

Browse files
CoderZhidustinxie
authored andcommitted
address comments
1 parent e01d855 commit 56ac0b8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

actpool/actqueue.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"container/heap"
1010
"context"
1111
"math/big"
12-
"sort"
1312
"sync"
1413
"time"
1514

@@ -315,8 +314,6 @@ func (q *actQueue) AllActs() []action.SealedEnvelope {
315314
if len(q.items) == 0 {
316315
return acts
317316
}
318-
// WARNING: after calling this function, the queue should be destroyed
319-
sort.Sort(q.ascQueue)
320317
for _, nonce := range q.ascQueue {
321318
acts = append(acts, q.items[nonce.nonce])
322319
}
@@ -333,6 +330,7 @@ func (q *actQueue) PopActionWithLargestNonce() *action.SealedEnvelope {
333330
heap.Remove(&q.ascQueue, itemMeta.ascIdx)
334331
item := q.items[itemMeta.nonce]
335332
delete(q.items, itemMeta.nonce)
333+
q.updateFromNonce(itemMeta.nonce)
336334

337335
return &item
338336
}

actpool/queueworker.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/hex"
66
"errors"
77
"math/big"
8+
"sort"
89
"strings"
910
"sync"
1011
"sync/atomic"
@@ -266,7 +267,11 @@ func (worker *queueWorker) AllActions(sender address.Address) ([]action.SealedEn
266267
worker.mu.RLock()
267268
defer worker.mu.RUnlock()
268269
if actQueue := worker.accountActs.Account(sender.String()); actQueue != nil {
269-
return actQueue.AllActs(), true
270+
acts := actQueue.AllActs()
271+
sort.Slice(acts, func(i, j int) bool {
272+
return acts[i].Nonce() < acts[j].Nonce()
273+
})
274+
return acts, true
270275
}
271276
return nil, false
272277
}
@@ -290,9 +295,8 @@ func (worker *queueWorker) ResetAccount(sender address.Address) []action.SealedE
290295
if actQueue != nil {
291296
pendingActs := actQueue.AllActs()
292297
actQueue.Reset()
293-
worker.mu.Lock()
298+
// the following line is thread safe with worker.mu.RLock
294299
worker.emptyAccounts.Set(senderStr, struct{}{})
295-
worker.mu.Unlock()
296300
return pendingActs
297301
}
298302
return nil

0 commit comments

Comments
 (0)