Skip to content

Commit ec50ca3

Browse files
committed
core, eth, trie: use common/prque (ethereum#17508)
1 parent 6c657ef commit ec50ca3

File tree

11 files changed

+51
-62
lines changed

11 files changed

+51
-62
lines changed

XDCx/XDCx.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import (
99

1010
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
1111
"github.com/XinFinOrg/XDPoSChain/XDCxDAO"
12-
"github.com/XinFinOrg/XDPoSChain/consensus"
13-
"github.com/XinFinOrg/XDPoSChain/core/types"
14-
"github.com/XinFinOrg/XDPoSChain/p2p"
15-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
16-
1712
"github.com/XinFinOrg/XDPoSChain/common"
13+
"github.com/XinFinOrg/XDPoSChain/common/prque"
14+
"github.com/XinFinOrg/XDPoSChain/consensus"
1815
"github.com/XinFinOrg/XDPoSChain/core/state"
16+
"github.com/XinFinOrg/XDPoSChain/core/types"
1917
"github.com/XinFinOrg/XDPoSChain/log"
18+
"github.com/XinFinOrg/XDPoSChain/p2p"
2019
"github.com/XinFinOrg/XDPoSChain/rpc"
2120
lru "github.com/hashicorp/golang-lru"
2221
"golang.org/x/sync/syncmap"
@@ -105,7 +104,7 @@ func New(cfg *Config) *XDCX {
105104
}
106105
XDCX := &XDCX{
107106
orderNonce: make(map[common.Address]*big.Int),
108-
Triegc: prque.New(),
107+
Triegc: prque.New(nil),
109108
tokenDecimalCache: tokenDecimalCache,
110109
orderCache: orderCache,
111110
}

XDCxlending/XDCxlending.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import (
1212
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
1313
"github.com/XinFinOrg/XDPoSChain/XDCxDAO"
1414
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
15-
"github.com/XinFinOrg/XDPoSChain/consensus"
16-
"github.com/XinFinOrg/XDPoSChain/core/types"
17-
"github.com/XinFinOrg/XDPoSChain/p2p"
18-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
19-
2015
"github.com/XinFinOrg/XDPoSChain/common"
16+
"github.com/XinFinOrg/XDPoSChain/common/prque"
17+
"github.com/XinFinOrg/XDPoSChain/consensus"
2118
"github.com/XinFinOrg/XDPoSChain/core/state"
19+
"github.com/XinFinOrg/XDPoSChain/core/types"
2220
"github.com/XinFinOrg/XDPoSChain/log"
21+
"github.com/XinFinOrg/XDPoSChain/p2p"
2322
"github.com/XinFinOrg/XDPoSChain/rpc"
2423
lru "github.com/hashicorp/golang-lru"
2524
)
@@ -67,7 +66,7 @@ func New(XDCx *XDCx.XDCX) *Lending {
6766
lendingTradeCache, _ := lru.New(defaultCacheLimit)
6867
lending := &Lending{
6968
orderNonce: make(map[common.Address]*big.Int),
70-
Triegc: prque.New(),
69+
Triegc: prque.New(nil),
7170
lendingItemHistory: itemCache,
7271
lendingTradeHistory: lendingTradeCache,
7372
}

consensus/XDPoS/utils/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
88
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
99
"github.com/XinFinOrg/XDPoSChain/common"
10+
"github.com/XinFinOrg/XDPoSChain/common/prque"
1011
"github.com/XinFinOrg/XDPoSChain/consensus"
1112
"github.com/XinFinOrg/XDPoSChain/consensus/clique"
1213
"github.com/XinFinOrg/XDPoSChain/core/state"
1314
"github.com/XinFinOrg/XDPoSChain/core/types"
14-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
1515
)
1616

1717
type Masternode struct {

core/blockchain.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ import (
2828
"sync/atomic"
2929
"time"
3030

31-
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
32-
3331
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
32+
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
3433
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind"
35-
3634
"github.com/XinFinOrg/XDPoSChain/common"
3735
"github.com/XinFinOrg/XDPoSChain/common/mclock"
36+
"github.com/XinFinOrg/XDPoSChain/common/prque"
3837
"github.com/XinFinOrg/XDPoSChain/common/sort"
3938
"github.com/XinFinOrg/XDPoSChain/consensus"
4039
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
@@ -53,7 +52,6 @@ import (
5352
"github.com/XinFinOrg/XDPoSChain/rlp"
5453
"github.com/XinFinOrg/XDPoSChain/trie"
5554
lru "github.com/hashicorp/golang-lru"
56-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
5755
)
5856

5957
var (
@@ -201,7 +199,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
201199
chainConfig: chainConfig,
202200
cacheConfig: cacheConfig,
203201
db: db,
204-
triegc: prque.New(),
202+
triegc: prque.New(nil),
205203
stateCache: state.NewDatabase(db),
206204
quit: make(chan struct{}),
207205
bodyCache: bodyCache,
@@ -1268,18 +1266,18 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
12681266
} else {
12691267
// Full but not archive node, do proper garbage collection
12701268
triedb.Reference(root, common.Hash{}) // metadata reference to keep trie alive
1271-
bc.triegc.Push(root, -float32(block.NumberU64()))
1269+
bc.triegc.Push(root, -int64(block.NumberU64()))
12721270
if tradingTrieDb != nil {
12731271
tradingTrieDb.Reference(tradingRoot, common.Hash{})
12741272
}
12751273
if tradingService != nil {
1276-
tradingService.GetTriegc().Push(tradingRoot, -float32(block.NumberU64()))
1274+
tradingService.GetTriegc().Push(tradingRoot, -int64(block.NumberU64()))
12771275
}
12781276
if lendingTrieDb != nil {
12791277
lendingTrieDb.Reference(lendingRoot, common.Hash{})
12801278
}
12811279
if lendingService != nil {
1282-
lendingService.GetTriegc().Push(lendingRoot, -float32(block.NumberU64()))
1280+
lendingService.GetTriegc().Push(lendingRoot, -int64(block.NumberU64()))
12831281
}
12841282
if current := block.NumberU64(); current > triesInMemory {
12851283
// Find the next state trie we need to commit

core/lending_pool.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ import (
2424
"sync"
2525
"time"
2626

27-
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
28-
2927
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
30-
"github.com/XinFinOrg/XDPoSChain/consensus"
31-
3228
"github.com/XinFinOrg/XDPoSChain/common"
29+
"github.com/XinFinOrg/XDPoSChain/common/prque"
30+
"github.com/XinFinOrg/XDPoSChain/consensus"
31+
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
3332
"github.com/XinFinOrg/XDPoSChain/core/state"
3433
"github.com/XinFinOrg/XDPoSChain/core/types"
3534
"github.com/XinFinOrg/XDPoSChain/event"
3635
"github.com/XinFinOrg/XDPoSChain/log"
3736
"github.com/XinFinOrg/XDPoSChain/params"
38-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
3937
)
4038

4139
var (
@@ -998,11 +996,11 @@ func (pool *LendingPool) promoteExecutables(accounts []common.Address) {
998996
if pending > pool.config.GlobalSlots {
999997
pendingBeforeCap := pending
1000998
// Assemble a spam order to penalize large transactors first
1001-
spammers := prque.New()
999+
spammers := prque.New(nil)
10021000
for addr, list := range pool.pending {
10031001
// Only evict transactions from high rollers
10041002
if !pool.locals.contains(addr) && uint64(list.Len()) > pool.config.AccountSlots {
1005-
spammers.Push(addr, float32(list.Len()))
1003+
spammers.Push(addr, int64(list.Len()))
10061004
}
10071005
}
10081006
// Gradually drop transactions from offenders

core/order_pool.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ import (
2525
"time"
2626

2727
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
28+
"github.com/XinFinOrg/XDPoSChain/common"
29+
"github.com/XinFinOrg/XDPoSChain/common/prque"
2830
"github.com/XinFinOrg/XDPoSChain/consensus"
2931
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
30-
31-
"github.com/XinFinOrg/XDPoSChain/common"
3232
"github.com/XinFinOrg/XDPoSChain/core/state"
3333
"github.com/XinFinOrg/XDPoSChain/core/types"
3434
"github.com/XinFinOrg/XDPoSChain/event"
3535
"github.com/XinFinOrg/XDPoSChain/log"
3636
"github.com/XinFinOrg/XDPoSChain/params"
37-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
3837
)
3938

4039
var (
@@ -914,11 +913,11 @@ func (pool *OrderPool) promoteExecutables(accounts []common.Address) {
914913
if pending > pool.config.GlobalSlots {
915914
pendingBeforeCap := pending
916915
// Assemble a spam order to penalize large transactors first
917-
spammers := prque.New()
916+
spammers := prque.New(nil)
918917
for addr, list := range pool.pending {
919918
// Only evict transactions from high rollers
920919
if !pool.locals.contains(addr) && uint64(list.Len()) > pool.config.AccountSlots {
921-
spammers.Push(addr, float32(list.Len()))
920+
spammers.Push(addr, int64(list.Len()))
922921
}
923922
}
924923
// Gradually drop transactions from offenders

core/tx_pool.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ import (
2525
"sync"
2626
"time"
2727

28-
"github.com/XinFinOrg/XDPoSChain/consensus"
29-
3028
"github.com/XinFinOrg/XDPoSChain/common"
29+
"github.com/XinFinOrg/XDPoSChain/common/prque"
30+
"github.com/XinFinOrg/XDPoSChain/consensus"
3131
"github.com/XinFinOrg/XDPoSChain/core/state"
3232
"github.com/XinFinOrg/XDPoSChain/core/types"
3333
"github.com/XinFinOrg/XDPoSChain/event"
3434
"github.com/XinFinOrg/XDPoSChain/log"
3535
"github.com/XinFinOrg/XDPoSChain/metrics"
3636
"github.com/XinFinOrg/XDPoSChain/params"
37-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
3837
)
3938

4039
const (
@@ -1135,11 +1134,11 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
11351134
if pending > pool.config.GlobalSlots {
11361135
pendingBeforeCap := pending
11371136
// Assemble a spam order to penalize large transactors first
1138-
spammers := prque.New()
1137+
spammers := prque.New(nil)
11391138
for addr, list := range pool.pending {
11401139
// Only evict transactions from high rollers
11411140
if !pool.locals.contains(addr) && uint64(list.Len()) > pool.config.AccountSlots {
1142-
spammers.Push(addr, float32(list.Len()))
1141+
spammers.Push(addr, int64(list.Len()))
11431142
}
11441143
}
11451144
// Gradually drop transactions from offenders

eth/downloader/queue.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"time"
2727

2828
"github.com/XinFinOrg/XDPoSChain/common"
29+
"github.com/XinFinOrg/XDPoSChain/common/prque"
2930
"github.com/XinFinOrg/XDPoSChain/core/types"
3031
"github.com/XinFinOrg/XDPoSChain/log"
3132
"github.com/XinFinOrg/XDPoSChain/metrics"
32-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
3333
)
3434

3535
var (
@@ -105,11 +105,11 @@ func newQueue() *queue {
105105
headerPendPool: make(map[string]*fetchRequest),
106106
headerContCh: make(chan bool),
107107
blockTaskPool: make(map[common.Hash]*types.Header),
108-
blockTaskQueue: prque.New(),
108+
blockTaskQueue: prque.New(nil),
109109
blockPendPool: make(map[string]*fetchRequest),
110110
blockDonePool: make(map[common.Hash]struct{}),
111111
receiptTaskPool: make(map[common.Hash]*types.Header),
112-
receiptTaskQueue: prque.New(),
112+
receiptTaskQueue: prque.New(nil),
113113
receiptPendPool: make(map[string]*fetchRequest),
114114
receiptDonePool: make(map[common.Hash]struct{}),
115115
resultCache: make([]*fetchResult, blockCacheItems),
@@ -278,7 +278,7 @@ func (q *queue) ScheduleSkeleton(from uint64, skeleton []*types.Header) {
278278
}
279279
// Shedule all the header retrieval tasks for the skeleton assembly
280280
q.headerTaskPool = make(map[uint64]*types.Header)
281-
q.headerTaskQueue = prque.New()
281+
q.headerTaskQueue = prque.New(nil)
282282
q.headerPeerMiss = make(map[string]map[uint64]struct{}) // Reset availability to correct invalid chains
283283
q.headerResults = make([]*types.Header, len(skeleton)*MaxHeaderFetch)
284284
q.headerProced = 0
@@ -289,7 +289,7 @@ func (q *queue) ScheduleSkeleton(from uint64, skeleton []*types.Header) {
289289
index := from + uint64(i*MaxHeaderFetch)
290290

291291
q.headerTaskPool[index] = header
292-
q.headerTaskQueue.Push(index, -float32(index))
292+
q.headerTaskQueue.Push(index, -int64(index))
293293
}
294294
}
295295

@@ -335,11 +335,11 @@ func (q *queue) Schedule(headers []*types.Header, from uint64) []*types.Header {
335335
}
336336
// Queue the header for content retrieval
337337
q.blockTaskPool[hash] = header
338-
q.blockTaskQueue.Push(header, -float32(header.Number.Uint64()))
338+
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
339339

340340
if q.mode == FastSync {
341341
q.receiptTaskPool[hash] = header
342-
q.receiptTaskQueue.Push(header, -float32(header.Number.Uint64()))
342+
q.receiptTaskQueue.Push(header, -int64(header.Number.Uint64()))
343343
}
344344
inserts = append(inserts, header)
345345
q.headerHead = hash
@@ -437,7 +437,7 @@ func (q *queue) ReserveHeaders(p *peerConnection, count int) *fetchRequest {
437437
}
438438
// Merge all the skipped batches back
439439
for _, from := range skip {
440-
q.headerTaskQueue.Push(from, -float32(from))
440+
q.headerTaskQueue.Push(from, -int64(from))
441441
}
442442
// Assemble and return the block download request
443443
if send == 0 {
@@ -544,7 +544,7 @@ func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common
544544
}
545545
// Merge all the skipped headers back
546546
for _, header := range skip {
547-
taskQueue.Push(header, -float32(header.Number.Uint64()))
547+
taskQueue.Push(header, -int64(header.Number.Uint64()))
548548
}
549549
if progress {
550550
// Wake WaitResults, resultCache was modified
@@ -587,10 +587,10 @@ func (q *queue) cancel(request *fetchRequest, taskQueue *prque.Prque, pendPool m
587587
defer q.lock.Unlock()
588588

589589
if request.From > 0 {
590-
taskQueue.Push(request.From, -float32(request.From))
590+
taskQueue.Push(request.From, -int64(request.From))
591591
}
592592
for _, header := range request.Headers {
593-
taskQueue.Push(header, -float32(header.Number.Uint64()))
593+
taskQueue.Push(header, -int64(header.Number.Uint64()))
594594
}
595595
delete(pendPool, request.Peer.id)
596596
}
@@ -604,13 +604,13 @@ func (q *queue) Revoke(peerId string) {
604604

605605
if request, ok := q.blockPendPool[peerId]; ok {
606606
for _, header := range request.Headers {
607-
q.blockTaskQueue.Push(header, -float32(header.Number.Uint64()))
607+
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
608608
}
609609
delete(q.blockPendPool, peerId)
610610
}
611611
if request, ok := q.receiptPendPool[peerId]; ok {
612612
for _, header := range request.Headers {
613-
q.receiptTaskQueue.Push(header, -float32(header.Number.Uint64()))
613+
q.receiptTaskQueue.Push(header, -int64(header.Number.Uint64()))
614614
}
615615
delete(q.receiptPendPool, peerId)
616616
}
@@ -659,10 +659,10 @@ func (q *queue) expire(timeout time.Duration, pendPool map[string]*fetchRequest,
659659

660660
// Return any non satisfied requests to the pool
661661
if request.From > 0 {
662-
taskQueue.Push(request.From, -float32(request.From))
662+
taskQueue.Push(request.From, -int64(request.From))
663663
}
664664
for _, header := range request.Headers {
665-
taskQueue.Push(header, -float32(header.Number.Uint64()))
665+
taskQueue.Push(header, -int64(header.Number.Uint64()))
666666
}
667667
// Add the peer to the expiry report along the the number of failed requests
668668
expiries[id] = len(request.Headers)
@@ -733,7 +733,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
733733
}
734734
miss[request.From] = struct{}{}
735735

736-
q.headerTaskQueue.Push(request.From, -float32(request.From))
736+
q.headerTaskQueue.Push(request.From, -int64(request.From))
737737
return 0, errors.New("delivery not accepted")
738738
}
739739
// Clean up a successful fetch and try to deliver any sub-results
@@ -856,7 +856,7 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header, taskQ
856856
// Return all failed or missing fetches to the queue
857857
for _, header := range request.Headers {
858858
if header != nil {
859-
taskQueue.Push(header, -float32(header.Number.Uint64()))
859+
taskQueue.Push(header, -int64(header.Number.Uint64()))
860860
}
861861
}
862862
// Wake up WaitResults

0 commit comments

Comments
 (0)