Skip to content

Composite State Store Part 5: WAL integration + Composite Pruning Manager#2785

Open
Kbhat1 wants to merge 8 commits intofeature/composite-ss-read-pathfrom
feature/composite-ss-wal-integration
Open

Composite State Store Part 5: WAL integration + Composite Pruning Manager#2785
Kbhat1 wants to merge 8 commits intofeature/composite-ss-read-pathfrom
feature/composite-ss-wal-integration

Conversation

@Kbhat1
Copy link
Contributor

@Kbhat1 Kbhat1 commented Jan 28, 2026

Describe your changes and provide context

  • Add RecoverCompositeStateStore to handle WAL replay for both stores on startup
  • Refactor pruning to go through CompositeStateStore so both Cosmos_SS and EVM_SS are pruned correctly
  • If EVM_SS is behind (e.g., newly enabled or crash), sync it from WAL before standard recovery
  • Standard WAL replay uses ApplyChangesetSync which dual-writes to both stores automatically
  • Backward search for replay offset matches existing RecoverStateStore pattern
  • Both stores stay consistent after crashes/restarts

Testing performed to validate your change

  • Unit tests
  • Verifying on node

@Kbhat1 Kbhat1 marked this pull request as draft January 28, 2026 22:20
@github-actions
Copy link

github-actions bot commented Jan 28, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 4, 2026, 9:32 PM

@Kbhat1 Kbhat1 changed the title WIP: CompositeStateStore Parrt 5: WAL integration WIP: CompositeStateStore Part 5: WAL integration Jan 28, 2026
@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 64.44444% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.61%. Comparing base (c095ad2) to head (785b74f).

Files with missing lines Patch % Lines
sei-db/state_db/ss/composite/store.go 64.44% 19 Missing and 13 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                       Coverage Diff                       @@
##           feature/composite-ss-read-path    #2785   +/-   ##
===============================================================
  Coverage                           41.61%   41.61%           
===============================================================
  Files                                1925     1925           
  Lines                              153234   153324   +90     
===============================================================
+ Hits                                63762    63811   +49     
- Misses                              83467    83484   +17     
- Partials                             6005     6029   +24     
Flag Coverage Δ
sei-chain 41.53% <64.44%> (+<0.01%) ⬆️
sei-db 68.72% <ø> (ø)

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

Files with missing lines Coverage Δ
sei-db/state_db/ss/composite/store.go 41.99% <64.44%> (+9.62%) ⬆️

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

@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch 2 times, most recently from c0a7f5b to db4a5a9 Compare January 29, 2026 17:39
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from 42e19d3 to 4084fe1 Compare January 29, 2026 17:54
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from ee8ea44 to a401330 Compare January 29, 2026 17:56
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from 4055a6d to ae9502c Compare January 29, 2026 20:56
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from 0cefbd5 to 1fc46b6 Compare January 29, 2026 20:56
@Kbhat1 Kbhat1 marked this pull request as ready for review January 30, 2026 03:43
@Kbhat1 Kbhat1 changed the title WIP: CompositeStateStore Part 5: WAL integration CompositeStateStore Part 5: WAL integration Jan 30, 2026
@Kbhat1 Kbhat1 changed the title CompositeStateStore Part 5: WAL integration Composite State Store Part 5: WAL integration Jan 30, 2026
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from ae9502c to a11dc21 Compare January 30, 2026 03:59
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from 1fc46b6 to dedf0c0 Compare January 30, 2026 04:00
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from a11dc21 to ca81638 Compare January 30, 2026 04:51
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from c9ef455 to f9a3987 Compare January 30, 2026 04:52
@Kbhat1 Kbhat1 changed the title Composite State Store Part 5: WAL integration Composite State Store Part 5: WAL integration + Composite Pruning Manager Jan 30, 2026
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from ca81638 to 8efe6df Compare January 30, 2026 05:21
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from c769c02 to 7803574 Compare January 30, 2026 05:24
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from 8efe6df to 9be2e36 Compare January 30, 2026 05:30
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from 7803574 to d0ff8d9 Compare January 30, 2026 05:30
logger.Info("Replaying WAL to EVM store", "startOffset", startOffset, "endOffset", lastOffset)

return streamHandler.Replay(startOffset, lastOffset, func(index uint64, entry proto.ChangelogEntry) error {
if entry.Version > cosmosVersion {
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: logging wal replay progress something like:

if index % 1000 == 0 { logger.Info("WAL replay progress", "offset", index, "version", entry.Version) }

@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from 9be2e36 to da06ac5 Compare February 2, 2026 15:32
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from d0ff8d9 to 4e18ca2 Compare February 2, 2026 15:32
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from da06ac5 to bca19d0 Compare February 2, 2026 15:50
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from 4e18ca2 to 53da684 Compare February 2, 2026 15:50
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from bca19d0 to b3b7cd4 Compare February 2, 2026 15:58
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from 53da684 to 17c7f7d Compare February 2, 2026 15:58
)

// Sync EVM_SS if behind
if evmVersion < cosmosVersion {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not compare EVM version with cosmos Version to determine behind or not, because both SS could be falling behind at the same time even if they are at the same height

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yzang2019 The logic handles both cases:

  1. syncEVMStore only runs if EVM_SS < Cosmos_SS (catches EVM up to Cosmos)
  2. recoverStandardWAL always runs after and replays through CompositeStateStore, which dual-writes to both stores

So if both are at version 80 and WAL is at 100, we skip step 1 (they're equal), then step 2 replays 81-100 to both stores via dual-write. The two-phase approach covers all scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm why do we need separate steps here? Would it be easier to just recover both SS till latest height?

}

// syncEVMStore replays WAL entries to catch up EVM_SS to Cosmos_SS version
func syncEVMStore(
Copy link
Contributor

@yzang2019 yzang2019 Feb 2, 2026

Choose a reason for hiding this comment

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

Can we consolidate the changelog restore logic into one function?

@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from b3b7cd4 to ba26486 Compare February 2, 2026 20:49
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch 2 times, most recently from c75185b to 34c9a63 Compare February 2, 2026 21:52
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from ba26486 to d7bca53 Compare February 2, 2026 21:52
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch 2 times, most recently from c1cafb6 to d53e24f Compare February 2, 2026 21:53
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from d7bca53 to eb51830 Compare February 2, 2026 21:54
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from d53e24f to 3eb8a27 Compare February 2, 2026 21:54
Add recovery mechanism ensuring both Cosmos_SS and EVM_SS stay in sync:

- RecoverCompositeStateStore: Syncs EVM_SS if behind, replays new WAL entries
- syncEVMStore: Catches up EVM_SS via WAL replay
- Standard WAL replay goes through ApplyChangesetSync (dual-writes)

Usage: Call RecoverCompositeStateStore after creating CompositeStateStore.
…function

- Replace separate syncEVMStore and recoverStandardWAL functions with
  a single generic replayWAL function that takes a handler callback
- replayWAL(fromVersion, toVersion, handler) handles all WAL replay:
  - fromVersion: start replaying from entries > this version
  - toVersion: stop at this version (-1 = replay to end of WAL)
  - handler: callback to process each entry
- RecoverCompositeStateStore now uses replayWAL for both phases:
  - Phase 1: Sync EVM if behind (replay only to EVM store)
  - Phase 2: Replay new entries (dual-write through CompositeStateStore)
Move newCompositeStateStoreWithStores from store.go to recovery_test.go
since it's only used for testing recovery scenarios.
Since Cosmos_SS and EVM_SS share the same changelog, consolidate recovery
into a single pass that routes each WAL entry appropriately:
- Entries Cosmos needs: dual-write through CompositeStateStore
- Entries only EVM needs (catch-up): write only to EVM store
- Entries both have: skip

This opens the WAL once instead of potentially twice, and the routing
logic is clear and consolidated in one place.
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-write-path branch from eb51830 to 8e4dc3a Compare February 3, 2026 21:52
@Kbhat1 Kbhat1 force-pushed the feature/composite-ss-wal-integration branch from b68f249 to f5d8315 Compare February 3, 2026 21:52
Base automatically changed from feature/composite-ss-write-path to feature/composite-ss-read-path February 3, 2026 21:52
Replace EnableRead/EnableWrite with WriteMode/ReadMode enums in test config.
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.

3 participants