Skip to content

Make the composite store router an atomic pointer - #4470

Merged
masih merged 3 commits into
mainfrom
masih/1791282069-composite-atomic-router
Oct 6, 2026
Merged

masih merged 3 commits into
mainfrom
masih/1791282069-composite-atomic-router

Conversation

@masih

@masih masih commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

CompositeCommitStore keeps its migration router in a plain field. SetWriteMode replaces it when the write mode changes, while child-store views handed out by GetChildStoreByName read it on every call through a provider, and those accesses weren't synchronized.

The router now lives in an atomic.Pointer and every access goes through loadRouter and storeRouter. A new test reads through a cached child-store view across a SetWriteMode transition under -race. Behaviour and the AppHash are unchanged.

@devin-ai-integration

devin-ai-integration Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 6, 2026, 12:38 PM

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.85%. Comparing base (bf6c14f) to head (1682d7d).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4470      +/-   ##
==========================================
- Coverage   56.90%   56.85%   -0.05%     
==========================================
  Files        2130     2130              
  Lines      167505   167515      +10     
==========================================
- Hits        95315    95240      -75     
- Misses      72185    72270      +85     
  Partials        5        5              
Flag Coverage Δ
sei-chain 55.04% <ø> (-0.06%) ⬇️
sei-db 75.17% <ø> (ø)
sei-db-state-db 78.86% <100.00%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
sei-db/state_db/sc/composite/store.go 79.47% <100.00%> (+0.31%) ⬆️

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

SetWriteMode replaces the router while child-store views from GetChildStoreByName read it through a provider. Keep it in an atomic.Pointer and access it through loadRouter and storeRouter.
@devin-ai-integration
devin-ai-integration Bot force-pushed the masih/1791282069-composite-atomic-router branch from 3f0eed8 to 5b08d3e Compare October 6, 2026 10:29
@masih
masih marked this pull request as ready for review October 6, 2026 11:21
@cursor

cursor Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches hot paths for state reads and write-mode transitions during migration; behavior is unchanged but incorrect synchronization could cause rare query corruption under concurrent mode switches.

Overview
Synchronizes access to the composite store’s migration router so SetWriteMode can swap the router while cached child-store views from GetChildStoreByName still resolve routing on every read.

The router field is now an atomic.Pointer[migration.Router] with loadRouter / storeRouter used everywhere it is installed, cleared, or invoked (commits, reads, proofs, batch-size updates, close). GetChildStoreByName passes cs.loadRouter into NewRouterCommitKVStore instead of closing over a stale router value, so long-lived views pick up post-transition routing.

Adds TestComposite_Auto_ChildStoreReadsDuringWriteModeSwitch (intended for -race) to read through a cached child view while SetWriteMode(MigrateEVM) runs. Existing tests assert the router via loadRouter(). AppHash and routing semantics are unchanged aside from safe concurrent visibility.

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

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

Moves CompositeCommitStore's migration router into an atomic.Pointer reached only through loadRouter/storeRouter, so child-store views stop racing with SetWriteMode. The router accesses are now consistently synchronized and nothing blocks; the open points are that the new test does not reliably overlap reads with the switch, and that views can still race on cs.flatKV. The tree at the merge ref was read in full, and no Go toolchain was available, so the race test was not run. Kept codex's test-synchronization finding, which checks out.

Non-blocking

1 finding on the changed lines, as inline comments.

Pre-existing

Already true on the base branch, not introduced here.

  • suggestion — Views from GetChildStoreByName still read cs.flatKV without synchronization through their Iterator closure (cs.iterate, store.go ~1722). On the MemiavlOnly -> MigrateEVM edge, SetWriteMode assigns that field via materializeFlatKV/adoptFlatKV. That is the same concurrent-query scenario this PR addresses, so iteration during the kickoff block is still a data race, and the new test exercises only Get, so it would not catch it.

seidroid review · decision approve · session f47bf29309674702b9a3a0b73c556f88 · turn resp_claude_cf756772eda9d3ca8a3629f14b30d69b · item 81e309703d2551c989068341474d7445

Findings: 0 blocking | 1 non-blocking | 1 posted inline | 1 pre-existing

Comment thread sei-db/state_db/sc/composite/store_auto_test.go
@masih

masih commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

@seidroid review

@masih masih added the backport release/v6.7 Backport to release v6.7 label Oct 6, 2026

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

Since the last review only the new test changed. It now waits for the reader's first successful Get before calling SetWriteMode, and a deferred, once-guarded stop always shuts the reader down before Close, which addresses my earlier thread (raised with codex). The store.go change is unchanged and correct, so nothing blocks; the pre-existing race on cs.flatKV during iteration still stands. Codex found nothing this round, which agrees with this reading. The tree at the merge ref was read in full.

Pre-existing

Already true on the base branch, not introduced here.

  • suggestion — Views from GetChildStoreByName still read cs.flatKV without synchronization through their Iterator closure (cs.iterate, store.go ~1722). On the MemiavlOnly -> MigrateEVM edge, SetWriteMode assigns that field via materializeFlatKV/adoptFlatKV, so iteration during the kickoff block is still a data race. The new test exercises only Get, so it would not catch it.

seidroid review · decision approve · session f47bf29309674702b9a3a0b73c556f88 · turn resp_claude_fdf838def8fe9a3c7489f30c9b57f0fd · item 1821a50a3093553c9ca054db2026b13e

Findings: 0 blocking | 0 non-blocking | 0 posted inline | 1 pre-existing

@masih
masih added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit 77a50d6 Oct 6, 2026
70 checks passed
@masih
masih deleted the masih/1791282069-composite-atomic-router branch October 6, 2026 13:51
@seidroid

seidroid Bot commented Oct 6, 2026

Copy link
Copy Markdown

Successfully created backport PR for release/v6.7:

masih added a commit that referenced this pull request Oct 6, 2026
…inter (#4473)

Backport of #4470 to `release/v6.7`.

---------

Co-authored-by: Masih H. Derkani <m@derkani.org>
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 6, 2026
Follow-up to #4470. Child-store views returned by `GetChildStoreByName`,
and latest-height queries, read the composite store's `flatKV` backend
and effective write mode without holding the root store's lock, while
`SetWriteMode` can install both when the migration starts. As plain
fields those accesses are unsynchronised.

This stores both in `atomic.Pointer`s behind `loadFlatKV`/`storeFlatKV`
and `loadWriteMode`/`storeWriteMode`, matching the router accessors from
`TestComposite_Auto_ChildStoreIterationDuringWriteModeSwitch` iterates
through a cached view and through fresh views across the `MemiavlOnly`
to `MigrateEVM` switch; it reports data races under `-race` against the
previous `store.go` and passes with this change. No change to the
AppHash.

(cherry picked from commit 36941db)
revofusion pushed a commit to revofusion/sei-chain that referenced this pull request Oct 6, 2026
)

Follow-up to sei-protocol#4470. Child-store views returned by `GetChildStoreByName`,
and latest-height queries, read the composite store's `flatKV` backend
and effective write mode without holding the root store's lock, while
`SetWriteMode` can install both when the migration starts. As plain
fields those accesses are unsynchronised.

This stores both in `atomic.Pointer`s behind `loadFlatKV`/`storeFlatKV`
and `loadWriteMode`/`storeWriteMode`, matching the router accessors from
sei-protocol#4470, and has reader paths load each value once per call.
`TestComposite_Auto_ChildStoreIterationDuringWriteModeSwitch` iterates
through a cached view and through fresh views across the `MemiavlOnly`
to `MigrateEVM` switch; it reports data races under `-race` against the
previous `store.go` and passes with this change. No change to the
AppHash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants