-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: improve locks in txpool #807
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6fd6658
added a write lock to the txs.filter method and a read lock to the tx…
thogard785 0e91009
txpool reorg locks
JekaMas 9837d92
more locks
JekaMas 8aff52b
locks
JekaMas c1f19ff
linters
JekaMas 6df963b
params, packaging: update version for v0.3.8-beta release
manav2401 3ac28b4
core: add logs in reheap
manav2401 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|
||
if withRlock { | ||
m.m.RLock() | ||
log.Info("[DEBUG] Acquired lock over txpool map while performing reheap") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use log.Debug |
||
} | ||
|
||
for nonce := range m.items { | ||
*m.index = append(*m.index, nonce) | ||
index = append(index, nonce) | ||
} | ||
|
||
heap.Init(m.index) | ||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
} | ||
// Reset total cost | ||
l.subTotalCost(removed) | ||
l.subTotalCost(invalids) | ||
l.txs.reheap() | ||
|
||
l.txs.reheap(true) | ||
|
||
return removed, invalids | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not good practice. Instead you should have two methods,
Reheap
andreheap
, whereReheap
wrapsreheap
and takes the lock.