Skip to content

Fix flaky evmrpc tests querying blocks before async writes landed - #4218

Merged
masih merged 2 commits into
mainfrom
masih/1789621025-flaky-evmrpc-tests-settle
Sep 17, 2026
Merged

masih merged 2 commits into
mainfrom
masih/1789621025-flaky-evmrpc-tests-settle

Conversation

@masih

@masih masih commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

The evmrpc/tests suites commit blocks through the real app and then query the JSON-RPC server straight away, but both stores those queries read from apply their writes in the background. Historical heights are served from the state store, and a handler that encodes a transaction reaches back one height for the base fee and chain config, so if the pebble writer has not yet applied that version the read comes back empty and the request fails, which the test helper surfaces as a nil result and an interface-conversion panic. Since #4159 the receipt store lags the same way, and pinning the receipt watermark to MaxInt64 made the RPC layer promise receipts that were not written yet. pinStateStoreLatestVersion only moved the version marker, which advertises the height without making its data readable, and an injected 200ms delay in the pebble apply loop reproduces every failure in this family deterministically.

settleCommittedBlocks now replaces the pin at both setup choke points (SetupTestServer and SetupBlocks): it drains the state store through WaitForPendingWrites, which CompositeStateStore gains by delegating to its cosmos and EVM stores exactly as EVMStateStore already does for its sub-DBs, and then follows ReceiptStore.LatestVersion up to the committed height, the watermark the store documents for readers. The receipt window is pinned to the height actually applied instead of MaxInt64, so the RPC watermark reflects real visibility. The wait on the receipt writer is bounded because a failed background write latches and would otherwise hang the package until the test timeout.

Flaked in: https://github.com/sei-protocol/sei-chain/actions/runs/34646271105/job/103417698875, https://github.com/sei-protocol/sei-chain/actions/runs/34620197535/job/103331963799, https://github.com/sei-protocol/sei-chain/actions/runs/33532797141/job/99939796789, https://github.com/sei-protocol/sei-chain/actions/runs/32806690899/job/97678081007

@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedSep 17, 2026, 10:28 AM

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.88%. Comparing base (e1af9f2) to head (cfce0c1).

Files with missing lines Patch % Lines
evmrpc/tests/utils.go 73.33% 4 Missing ⚠️
sei-db/state_db/ss/composite/store.go 0.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4218      +/-   ##
==========================================
- Coverage   66.94%   65.88%   -1.06%     
==========================================
  Files        2176     2064     -112     
  Lines      167157   156077   -11080     
==========================================
- Hits       111903   102837    -9066     
+ Misses      55113    53099    -2014     
  Partials      141      141              
Flag Coverage Δ
sei-chain-pr 78.20% <73.33%> (?)
sei-db 74.50% <ø> (ø)
sei-db-state-db ?
sei-db-state-db-pr 80.21% <0.00%> (?)

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

Files with missing lines Coverage Δ
evmrpc/tests/utils.go 79.16% <73.33%> (-0.47%) ⬇️
sei-db/state_db/ss/composite/store.go 78.86% <0.00%> (-0.83%) ⬇️

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

@masih
masih marked this pull request as ready for review September 17, 2026 10:27
@masih
masih requested a review from cody-littley September 17, 2026 10:27
@cursor

cursor Bot commented Sep 17, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Changes are limited to test utilities and a composite-store wait helper; production commit/query paths are unchanged aside from exposing WaitForPendingWrites on CompositeStateStore.

Overview
Fixes flaky evmrpc integration tests that query JSON-RPC immediately after Commit while the state store and receipt store still apply writes in the background.

Test helpers now call settleCommittedBlocks instead of pinStateStoreLatestVersion. That helper drains the state store via WaitForPendingWrites (when supported), keeps the version marker in sync, and polls the receipt store until LatestVersion reaches the committed height (bounded by a 30s timeout). Receipt pinning in setupTestServer uses the actually applied version instead of MaxInt64, so the RPC watermark matches what readers can see.

CompositeStateStore gains WaitForPendingWrites, delegating to its Cosmos and EVM sub-stores so the composite path used in tests can block on pending async applies.

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

@masih
masih requested a review from amir-deris September 17, 2026 10:33

@seidroid seidroid 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.

A well-targeted test-flake fix: draining the state store and following the receipt store's real watermark before serving queries is the correct ordering, and replacing the MaxInt64 receipt pin with the height actually applied makes the RPC watermark honest. No correctness problems found; one suggestion about the silently-optional capability the fix depends on.

Findings: 0 blocking | 2 non-blocking | 1 posted inline

Blockers

  • None at the file/PR level.

Non-blocking

  • [suggestion] CompositeStateStore.WaitForPendingWrites is the load-bearing half of this fix but nothing pins it: sei-db/state_db/ss/composite/store.go has compile-time checks for StateStore and ContextIteratorStore (lines 31-32) and sei-db/state_db/ss/store.go pins BlockCommitter for exactly this reason ("a store that loses the method fails the build"). Adding var _ types.PendingWriteWaiter = (*CompositeStateStore)(nil) alongside them, plus a small case in composite/store_test.go asserting the delegation reaches both sub-stores, would keep the drain from being dropped unnoticed.
  • 1 suggestion(s)/nit(s) flagged inline on specific lines.

Comment thread evmrpc/tests/utils.go
if err := stateStore.SetLatestVersion(latest); err != nil {
panic(err)
if stateStore := a.GetStateStore(); stateStore != nil {
if w, ok := stateStore.(dbtypes.PendingWriteWaiter); ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[suggestion] This capability check fails open: if a.GetStateStore() ever returns a store that does not implement PendingWriteWaiter (a new backend, a test double, a rename in sei-db), the drain is silently skipped and the SetLatestVersion pin below advertises a height whose data is not readable — exactly the failure this PR is fixing, with no signal beyond the flake coming back. The receipt branch a few lines down takes the opposite stance and panics with a message naming the versions. Consider matching it here (w, ok := ...; if !ok { panic(...) }), so a store that loses the capability fails the suite loudly instead of quietly reverting to the old behaviour.

@masih
masih added this pull request to the merge queue Sep 17, 2026
Merged via the queue into main with commit 0b253c2 Sep 17, 2026
84 checks passed
@masih
masih deleted the masih/1789621025-flaky-evmrpc-tests-settle branch September 17, 2026 12:43
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