From 6fd6658f65fe54d94ed387c864e03f6ecfcb1ecf Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 3 Apr 2023 21:29:38 -0700 Subject: [PATCH 1/7] 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 --- core/tx_list.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/tx_list.go b/core/tx_list.go index f7c3d08295..0f24c80a29 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -521,12 +521,19 @@ 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.m.RLock() + defer l.txs.m.RUnlock() + l.txs.reheap() + return removed, invalids } From 0e91009e00b6e65af77ad2b3b9282c45e0fc84a8 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Tue, 4 Apr 2023 09:44:44 +0400 Subject: [PATCH 2/7] txpool reorg locks --- core/tx_list.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/tx_list.go b/core/tx_list.go index 0f24c80a29..ab297951b0 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -150,19 +150,25 @@ 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) + index = append(index, nonce) } - heap.Init(m.index) + heap.Init(&index) + + if withRlock { + m.m.RLock() + m.index = &index + m.m.RUnlock() + } m.cacheMu.Lock() m.cache = nil @@ -521,6 +527,7 @@ 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() @@ -529,11 +536,7 @@ func (l *txList) Filter(costLimit *uint256.Int, gasLimit uint64) (types.Transact l.subTotalCost(removed) l.subTotalCost(invalids) - l.txs.m.RLock() - defer l.txs.m.RUnlock() - - l.txs.reheap() - + l.txs.reheap(true) return removed, invalids } From 9837d929e2ac5ec46f5f37cb1110c6e1c0f1cc36 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Tue, 4 Apr 2023 10:12:13 +0400 Subject: [PATCH 3/7] more locks --- core/tx_list.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/tx_list.go b/core/tx_list.go index ab297951b0..c3a061d6af 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -158,10 +158,18 @@ func (m *txSortedMap) Filter(filter func(*types.Transaction) bool) types.Transac func (m *txSortedMap) reheap(withRlock bool) { index := make(nonceHeap, 0, len(m.items)) + if withRlock { + m.m.RLock() + } + for nonce := range m.items { index = append(index, nonce) } + if withRlock { + m.m.RUnlock() + } + heap.Init(&index) if withRlock { From 8aff52b0ffeb793958a447f46411ed15a21f77cd Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Tue, 4 Apr 2023 13:31:35 +0400 Subject: [PATCH 4/7] locks --- core/tx_list.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/tx_list.go b/core/tx_list.go index c3a061d6af..538368c087 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -173,9 +173,13 @@ func (m *txSortedMap) reheap(withRlock bool) { heap.Init(&index) if withRlock { - m.m.RLock() - m.index = &index - m.m.RUnlock() + m.m.Lock() + } + + m.index = &index + + if withRlock { + m.m.Unlock() } m.cacheMu.Lock() From c1f19fff6a368fa4c71e0274c88bd30f69592bfe Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Tue, 4 Apr 2023 14:49:56 +0400 Subject: [PATCH 5/7] linters --- core/tx_list.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/tx_list.go b/core/tx_list.go index 538368c087..3a3bc2d7b3 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -549,6 +549,7 @@ func (l *txList) Filter(costLimit *uint256.Int, gasLimit uint64) (types.Transact l.subTotalCost(invalids) l.txs.reheap(true) + return removed, invalids } From 6df963b7630a9b5400414b02343120eabb5c7aa9 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Tue, 4 Apr 2023 16:37:18 +0530 Subject: [PATCH 6/7] params, packaging: update version for v0.3.8-beta release --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index a1159d2473..130226241b 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 0.3.7 +Version: 0.3.8-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 7f8d11d9b7..e8073532af 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 0.3.7 +Version: 0.3.8-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 228a7f44a2..a5b46bff79 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 0.3.7 +Version: 0.3.8-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 90f5e93624..b0d94da338 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 0.3.7 +Version: 0.3.8-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 0f2d320b2d..887713056a 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 0.3.7 +Version: 0.3.8-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 20a8302faf..f9fa7635a9 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 0.3.7 +Version: 0.3.8-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index aa1f21b992..affdc6b5eb 100644 --- a/params/version.go +++ b/params/version.go @@ -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. From 3ac28b49f45dde71f7a4b55cb7c5b9dadbee9dcb Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Tue, 4 Apr 2023 17:05:02 +0530 Subject: [PATCH 7/7] core: add logs in reheap --- core/tx_list.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/tx_list.go b/core/tx_list.go index 3a3bc2d7b3..851f732905 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -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 @@ -160,6 +161,7 @@ func (m *txSortedMap) reheap(withRlock bool) { if withRlock { m.m.RLock() + log.Info("[DEBUG] Acquired lock over txpool map while performing reheap") } for nonce := range m.items {