core: improve locks in txpool (#807)

* added a write lock to the txs.filter method and a read lock to the txs.reheap method - both of which are called by Filter during reorg adjustments to txpool

* txpool reorg locks

* more locks

* locks

* linters

* params, packaging: update version for v0.3.8-beta release

* core: add logs in reheap

---------

Co-authored-by: Alex <dalexwatts@gmail.com>
Co-authored-by: Evgeny Danienko <6655321@bk.ru>
This commit is contained in:
Manav Darji 2023-04-05 00:47:11 +05:30 committed by GitHub
parent 72a222091c
commit 73f3c75aea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 17 deletions

View file

@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
)
// nonceHeap is a heap.Interface implementation over 64bit unsigned integers for
@ -150,19 +151,38 @@ func (m *txSortedMap) Filter(filter func(*types.Transaction) bool) types.Transac
removed := m.filter(filter)
// If transactions were removed, the heap and cache are ruined
if len(removed) > 0 {
m.reheap()
m.reheap(false)
}
return removed
}
func (m *txSortedMap) reheap() {
*m.index = make([]uint64, 0, len(m.items))
func (m *txSortedMap) reheap(withRlock bool) {
index := make(nonceHeap, 0, len(m.items))
for nonce := range m.items {
*m.index = append(*m.index, nonce)
if withRlock {
m.m.RLock()
log.Info("[DEBUG] Acquired lock over txpool map while performing reheap")
}
heap.Init(m.index)
for nonce := range m.items {
index = append(index, nonce)
}
if withRlock {
m.m.RUnlock()
}
heap.Init(&index)
if withRlock {
m.m.Lock()
}
m.index = &index
if withRlock {
m.m.Unlock()
}
m.cacheMu.Lock()
m.cache = nil
@ -521,12 +541,17 @@ func (l *txList) Filter(costLimit *uint256.Int, gasLimit uint64) (types.Transact
lowest = nonce
}
}
l.txs.m.Lock()
invalids = l.txs.filter(func(tx *types.Transaction) bool { return tx.Nonce() > lowest })
l.txs.m.Unlock()
}
// Reset total cost
l.subTotalCost(removed)
l.subTotalCost(invalids)
l.txs.reheap()
l.txs.reheap(true)
return removed, invalids
}

View file

@ -1,5 +1,5 @@
Source: bor
Version: 0.3.7
Version: 0.3.8-beta
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor
Version: 0.3.7
Version: 0.3.8-beta
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile
Version: 0.3.7
Version: 0.3.8-beta
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile
Version: 0.3.7
Version: 0.3.8-beta
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile
Version: 0.3.7
Version: 0.3.8-beta
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile
Version: 0.3.7
Version: 0.3.8-beta
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>

View file

@ -21,10 +21,10 @@ import (
)
const (
VersionMajor = 0 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release
VersionPatch = 7 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string
VersionMajor = 0 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release
VersionPatch = 8 // Patch version component of the current release
VersionMeta = "beta" // Version metadata to append to the version string
)
// Version holds the textual version string.