diff options
author | Ryan Schneider <ryanleeschneider@gmail.com> | 2018-05-23 20:55:42 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-05-23 20:55:42 +0800 |
commit | 55b579e02ce6f374bf81061269eabde0d82ae567 (patch) | |
tree | bd342772873ac0eb434d49a339850df6a3cf633b /core/tx_list.go | |
parent | be22ee8ddac890044ca66500f4f8b32c635e3d1f (diff) | |
download | go-tangerine-55b579e02ce6f374bf81061269eabde0d82ae567.tar go-tangerine-55b579e02ce6f374bf81061269eabde0d82ae567.tar.gz go-tangerine-55b579e02ce6f374bf81061269eabde0d82ae567.tar.bz2 go-tangerine-55b579e02ce6f374bf81061269eabde0d82ae567.tar.lz go-tangerine-55b579e02ce6f374bf81061269eabde0d82ae567.tar.xz go-tangerine-55b579e02ce6f374bf81061269eabde0d82ae567.tar.zst go-tangerine-55b579e02ce6f374bf81061269eabde0d82ae567.zip |
core: use a wrapped map to remove contention in `TxPool.Get`. (#16670)
* core: use a wrapped `map` and `sync.RWMutex` for `TxPool.all` to remove contention in `TxPool.Get`.
* core: Remove redundant `txLookup.Find` and improve comments on txLookup methods.
Diffstat (limited to 'core/tx_list.go')
-rw-r--r-- | core/tx_list.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/core/tx_list.go b/core/tx_list.go index ea6ee7019..287dda4c3 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -397,13 +397,13 @@ func (h *priceHeap) Pop() interface{} { // txPricedList is a price-sorted heap to allow operating on transactions pool // contents in a price-incrementing way. type txPricedList struct { - all *map[common.Hash]*types.Transaction // Pointer to the map of all transactions - items *priceHeap // Heap of prices of all the stored transactions - stales int // Number of stale price points to (re-heap trigger) + all *txLookup // Pointer to the map of all transactions + items *priceHeap // Heap of prices of all the stored transactions + stales int // Number of stale price points to (re-heap trigger) } // newTxPricedList creates a new price-sorted transaction heap. -func newTxPricedList(all *map[common.Hash]*types.Transaction) *txPricedList { +func newTxPricedList(all *txLookup) *txPricedList { return &txPricedList{ all: all, items: new(priceHeap), @@ -425,12 +425,13 @@ func (l *txPricedList) Removed() { return } // Seems we've reached a critical number of stale transactions, reheap - reheap := make(priceHeap, 0, len(*l.all)) + reheap := make(priceHeap, 0, l.all.Count()) l.stales, l.items = 0, &reheap - for _, tx := range *l.all { + l.all.Range(func(hash common.Hash, tx *types.Transaction) bool { *l.items = append(*l.items, tx) - } + return true + }) heap.Init(l.items) } @@ -443,7 +444,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact for len(*l.items) > 0 { // Discard stale transactions if found during cleanup tx := heap.Pop(l.items).(*types.Transaction) - if _, ok := (*l.all)[tx.Hash()]; !ok { + if l.all.Get(tx.Hash()) == nil { l.stales-- continue } @@ -475,7 +476,7 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo // Discard stale price points if found at the heap start for len(*l.items) > 0 { head := []*types.Transaction(*l.items)[0] - if _, ok := (*l.all)[head.Hash()]; !ok { + if l.all.Get(head.Hash()) == nil { l.stales-- heap.Pop(l.items) continue @@ -500,7 +501,7 @@ func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions for len(*l.items) > 0 && count > 0 { // Discard stale transactions if found during cleanup tx := heap.Pop(l.items).(*types.Transaction) - if _, ok := (*l.all)[tx.Hash()]; !ok { + if l.all.Get(tx.Hash()) == nil { l.stales-- continue } |