Skip to content

core/txpool: use reheap snapshot to avoid duplicate entries in heap#2095

Merged
manav2401 merged 10 commits intodevelopfrom
manav/txpool-logical-race-fix2
Mar 5, 2026
Merged

core/txpool: use reheap snapshot to avoid duplicate entries in heap#2095
manav2401 merged 10 commits intodevelopfrom
manav/txpool-logical-race-fix2

Conversation

@manav2401
Copy link
Copy Markdown
Member

Description

A different solution to the problem stated in #2087.

This PR tries to add a new counter which just keeps track of the number of times reheap is done. We use this info while adding transactions to figure out whether to actually add the transaction to the heap or avoid it (so that there are no duplicates). This also ensures the calls still happen inside a go routine to keep the global tx pool lock as free as possible for the miner so that the performance benefits are intact.

Changes

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Changes only for a subset of nodes

Breaking changes

Please complete this section if any breaking changes have been made, otherwise delete it

Nodes audience

In case this PR includes changes that must be applied only to a subset of nodes, please specify how you handled it (e.g. by adding a flag with a default value...)

Checklist

  • I have added at least 2 reviewer or the whole pos-v1 team
  • I have added sufficient documentation in code
  • I will be resolving comments - if any - by pushing each fix in a separate commit and linking the commit hash in the comment reply
  • Created a task in Jira and informed the team for implementation in Erigon client (if applicable)
  • Includes RPC methods changes, and the Notion documentation has been updated

Cross repository changes

  • This PR requires changes to heimdall
    • In case link the PR here:
  • This PR requires changes to matic-cli
    • In case link the PR here:

Testing

  • I have added unit tests
  • I have added tests to CI
  • I have tested this code manually on local environment
  • I have tested this code manually on remote devnet using express-cli
  • I have tested this code manually on amoy
  • I have created new e2e tests into express-cli

Manual tests

Please complete this section with the steps you performed if you ran manual tests for this functionality, otherwise delete it

Additional comments

Please post additional comments in this section if you have them, otherwise delete it

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 82.14286% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.29%. Comparing base (cc35665) to head (ce0b7b3).
⚠️ Report is 6 commits behind head on develop.

Files with missing lines Patch % Lines
core/txpool/legacypool/legacypool.go 58.33% 4 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (82.14%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2095      +/-   ##
===========================================
- Coverage    51.31%   51.29%   -0.03%     
===========================================
  Files          878      878              
  Lines       152668   152680      +12     
===========================================
- Hits         78349    78315      -34     
- Misses       69232    69272      +40     
- Partials      5087     5093       +6     
Files with missing lines Coverage Δ
core/txpool/legacypool/list.go 92.22% <100.00%> (+1.22%) ⬆️
core/txpool/legacypool/legacypool.go 78.17% <58.33%> (+0.50%) ⬆️

... and 18 files with indirect coverage changes

Files with missing lines Coverage Δ
core/txpool/legacypool/list.go 92.22% <100.00%> (+1.22%) ⬆️
core/txpool/legacypool/legacypool.go 78.17% <58.33%> (+0.50%) ⬆️

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@lucca30 lucca30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks pretty good while keeping the asynchronous nature and keeping it performant. Would be good for the future looking to this small probabilistic case we discussed on one of the trends and als a benchmark to measure the improvements related to keeping it async, it still looks good to me and approved.

@manav2401
Copy link
Copy Markdown
Member Author

@claude review this PR focusing on performance and security. Also, make sure no regression and new race condition is introduced. Refer to the PR comments (and the original PR mentioned in description) for more context if needed.

@claude
Copy link
Copy Markdown

claude bot commented Mar 4, 2026

Claude encountered an error —— View job


I'll analyze this and get back to you.

@manav2401
Copy link
Copy Markdown
Member Author

@claude review this PR focusing on performance and security. Also, make sure no regression and new race condition is introduced. Refer to the PR comments (and the original PR mentioned in description) for more context if needed.

@claude
Copy link
Copy Markdown

claude bot commented Mar 4, 2026

Claude encountered an error —— View job


I'll analyze this and get back to you.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 4, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
8.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@manav2401 manav2401 merged commit 8214a2a into develop Mar 5, 2026
15 of 19 checks passed
@manav2401 manav2401 deleted the manav/txpool-logical-race-fix2 branch March 5, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants