Skip to content

mempool evm metadata cache (CON-342)#3567

Merged
pompon0 merged 8 commits into
mainfrom
gprusak-rich-cache
Jun 9, 2026
Merged

mempool evm metadata cache (CON-342)#3567
pompon0 merged 8 commits into
mainfrom
gprusak-rich-cache

Conversation

@pompon0

@pompon0 pompon0 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The reported issue indicated that

  • we should avoid duplicate CheckTx calls whenever possible
  • in case a tx with nonce X fails, all tx with nonce X should again be eligible to be inserted to the mempool.

To achieve that, I have added caching of evm metadata after CheckTx - evm nonce, priority, requiredBalance and sender are all cached, so that at the next attempt to insert the given tx, we can quickly check if the tx has a chance to be inserted successfully, before even calling CheckTx.

To limit the increase in memory usage by cache, I have:

  • replaced containers/list in lru cache, with a custom generic list implementation
  • replaced big.Int with uint256.Int to store the balances.

The expected increase in memory usage by cache should be <2x.
Note: mempool cache has changed its role - it is no longer a superset of mempool txs. The early rejection semantics is strictly stronger though, as described above.
Additionally I have deprecated unused mempool config fields, and fixed timeout on the BroadcastTxCommit rpc.

@cursor

cursor Bot commented Jun 9, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes mempool admission and re-submission semantics on a hot path, plus an ABCI EvmBalance type change; incorrect cache logic could drop valid txs or allow extra CheckTx load.

Overview
Adds an EVM-aware mempool cache so CheckTx can be skipped when a tx is already known bad or would lose on nonce/priority/balance against what is in the pool. After a successful CheckTx, the store caches EVM metadata (sender, nonce, priority, required balance) and uses ShouldReject before calling the app; post-check failures use MarkInvalid instead of treating every cached hash as a duplicate.

The tx store LRU is replaced with a generic lruCache keyed by full tx hash, and balances move from *big.Int to uint256.Int on EvmBalance, EVMRequiredBalance, and related ABCI/proxy paths (with bigIntToUint256 in the app). Block updates change cache rules: successful executions are pinned invalid; first execution failures get a second chance before hard rejection.

Smaller follow-ons: pending TTL mempool config fields are deprecated as no-ops, duplicate-tx cache stops truncating keys, CheckTxSafe no longer requires non-nil EVMRequiredBalance, and BroadcastTxCommit honors timeout-broadcast-tx-commit via context timeout.

Reviewed by Cursor Bugbot for commit bbb1078. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJun 9, 2026, 5:56 PM

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4da3006. Configure here.

inner.failedTxs.Remove(txHash)
} else {
inner.failedTxs.Push(txHash, struct{}{})
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LRU evicts repeat-failure guard

Medium Severity

After a transaction fails in a block twice, Update marks the hash invalid in the LRU metadata cache and clears failedTxs, but ShouldReject only consults that cache. If LRU eviction drops the invalid marker, the same hash can pass early rejection and run CheckTx again, bypassing the intended one-retry limit for failed execution.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4da3006. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

WAI

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.86179% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.38%. Comparing base (1f52187) to head (bbb1078).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
app/abci.go 0.00% 10 Missing ⚠️
sei-tendermint/internal/mempool/tx.go 90.56% 4 Missing and 1 partial ⚠️
sei-tendermint/abci/types/mocks/application.go 0.00% 4 Missing ⚠️
sei-tendermint/internal/rpc/core/mempool.go 0.00% 4 Missing ⚠️
sei-cosmos/baseapp/baseapp.go 0.00% 2 Missing ⚠️
sei-tendermint/internal/mempool/mempool.go 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3567      +/-   ##
==========================================
- Coverage   59.18%   58.38%   -0.81%     
==========================================
  Files        2225     2152      -73     
  Lines      183625   175849    -7776     
==========================================
- Hits       108677   102665    -6012     
+ Misses      65154    64060    -1094     
+ Partials     9794     9124     -670     
Flag Coverage Δ
sei-chain-pr 55.95% <78.86%> (?)
sei-db 70.41% <ø> (ø)
sei-db-state-db ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-tendermint/abci/types/application.go 46.87% <100.00%> (ø)
sei-tendermint/abci/types/types.go 68.88% <ø> (ø)
sei-tendermint/config/config.go 77.08% <ø> (+3.90%) ⬆️
sei-tendermint/internal/mempool/cache.go 94.23% <100.00%> (-2.48%) ⬇️
sei-tendermint/internal/mempool/lru.go 100.00% <100.00%> (ø)
sei-tendermint/internal/proxy/proxy.go 91.66% <100.00%> (-0.27%) ⬇️
sei-tendermint/internal/mempool/mempool.go 79.80% <66.66%> (ø)
sei-cosmos/baseapp/baseapp.go 75.78% <0.00%> (ø)
sei-tendermint/abci/types/mocks/application.go 11.78% <0.00%> (ø)
sei-tendermint/internal/rpc/core/mempool.go 40.67% <0.00%> (-0.95%) ⬇️
... and 2 more

... and 77 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.

@pompon0 pompon0 added this pull request to the merge queue Jun 9, 2026
Merged via the queue into main with commit 7b5b01a Jun 9, 2026
55 checks passed
@pompon0 pompon0 deleted the gprusak-rich-cache branch June 9, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants