Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
662b214
build routers
Apr 28, 2026
da2a545
remove dual write test
Apr 28, 2026
865ef84
remove split write tests
Apr 28, 2026
879dac7
incremental progress
Apr 29, 2026
6c4927f
expand route API
Apr 29, 2026
1b7c9ab
add helper method to build a route to a migration manager
Apr 29, 2026
af35c76
Merge branch 'cjl/expanded-route-api' into cjl/migration-integration
Apr 29, 2026
fa89b45
cleanup
Apr 29, 2026
75a3b7c
made suggested change
Apr 29, 2026
3710f59
Merge branch 'cjl/expanded-route-api' into cjl/migration-integration
Apr 29, 2026
e0744b9
revert lots of changes
Apr 29, 2026
94c5e57
test utilities
Apr 29, 2026
78eb3bb
incremental progress on tests
Apr 29, 2026
2a6c03e
test evm migration
Apr 29, 2026
8a303e9
determinism
Apr 29, 2026
3900541
cleanup
Apr 29, 2026
d9fefc8
test post evm migration
Apr 29, 2026
eee79af
added next test
Apr 30, 2026
0b3cc6e
all migrated but bank
Apr 30, 2026
4f140de
final test
Apr 30, 2026
175b0f5
add thread safe wrapper
Apr 30, 2026
65c31dd
various fixes
Apr 30, 2026
2fc730a
Merge branch 'main' into cjl/migration-integration
May 1, 2026
97d0acc
implement thread safe router
May 1, 2026
ecd5a92
Add router based implementation of kvstore
May 1, 2026
8c9961c
made suggested changes
May 4, 2026
d0aead6
Merge branch 'cjl/thread-safe-router' into cjl/migration-integration
May 4, 2026
ee043b8
remove unused methods
May 4, 2026
ddafa97
Merge branch 'main' into cjl/migration-integration
May 4, 2026
9449881
test framework for migration tests
May 4, 2026
34d0dbe
made suggested changes
May 5, 2026
2f50f90
Merge branch 'cjl/migration-test-framework' into cjl/migration-integr…
May 5, 2026
cc367cd
Merge branch 'main' into cjl/migration-integration
May 5, 2026
247308f
Add replacement APIs for methods we intend to deprecate.
May 6, 2026
976c934
Merge branch 'main' into cjl/replacement-apis
May 6, 2026
0939d8d
fix tests
May 6, 2026
68a9dc1
Merge branch 'main' into cjl/migration-integration
May 6, 2026
4265c58
remove ctx
May 6, 2026
17915ce
Constants for migration code
May 6, 2026
d548214
made suggested change
May 6, 2026
5c2b89d
made suggested change
May 6, 2026
5e8524a
Merge branch 'cjl/migration-constants' into cjl/migration-integration
May 6, 2026
a864d0f
fix merge issue
May 6, 2026
01e41e2
Merge branch 'main' into cjl/migration-integration
May 7, 2026
76bfdf4
Merge branch 'cjl/replacement-apis' into cjl/migration-integration
May 7, 2026
95e7e03
add routers for steady state operation
May 7, 2026
bc1842c
add duplicating router
May 7, 2026
fd86181
add router for dual write mode
May 7, 2026
009bf03
Merge branch 'main' into cjl/migration-integration
May 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions sei-db/state_db/sc/migration/dual_write_router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package migration

import (
"fmt"

ics23 "github.com/confio/ics23/go"
"github.com/sei-protocol/sei-chain/sei-db/proto"
db "github.com/tendermint/tm-db"
)

var _ Router = (*TestOnlyDualWriteRouter)(nil)

// A router that dual-writes traffic, sending each batch of changesets to both backends. Read
// requests, requests for proofs, and requests for iteration are not dual-written, and are instead
// served exclusively by the primary backend.
//
// CRITICAL: this is a test-only router and should never be deployed to production machines.
type TestOnlyDualWriteRouter struct {
primary *Route
secondary DBWriter
}

// Create a new test-only dual-write router.
//
// CRITICAL: this is a test-only router and should never be deployed to production machines.
func NewTestOnlyDualWriteRouter(
// Read, proof, and iteration traffic is served by this route, and writes are also sent here.
// Module names associated with this route are ignored; this route forwards all regardless of the module names.
primary *Route,
// Write traffic is dual-written and also sent here. Reads, proofs, and iteration are not sent here.
secondary DBWriter,
) (*TestOnlyDualWriteRouter, error) {

if primary == nil {
return nil, fmt.Errorf("primary must not be nil")
}
if primary.proofBuilder == nil {
return nil, fmt.Errorf("primary proof builder must not be nil")
}
if primary.iteratorBuilder == nil {
return nil, fmt.Errorf("primary iterator builder must not be nil")
}
if secondary == nil {
return nil, fmt.Errorf("secondary must not be nil")
}

return &TestOnlyDualWriteRouter{primary: primary, secondary: secondary}, nil
}

func (t *TestOnlyDualWriteRouter) ApplyChangeSets(changesets []*proto.NamedChangeSet) error {
err := t.primary.writer(changesets)
if err != nil {
return fmt.Errorf("primary writer: %w", err)
}

err = t.secondary(changesets)
if err != nil {
return fmt.Errorf("secondary writer: %w", err)
}

return nil
}

func (t *TestOnlyDualWriteRouter) GetProof(store string, key []byte) (*ics23.CommitmentProof, error) {
proof, err := t.primary.proofBuilder(store, key)
if err != nil {
return nil, fmt.Errorf("primary proof builder: %w", err)
}
return proof, nil
}

func (t *TestOnlyDualWriteRouter) Iterator(
store string,
start []byte,
end []byte,
ascending bool,
) (db.Iterator, error) {
iterator, err := t.primary.iteratorBuilder(store, start, end, ascending)
if err != nil {
return nil, fmt.Errorf("primary iterator builder: %w", err)
}
return iterator, nil
}

func (t *TestOnlyDualWriteRouter) Read(store string, key []byte) ([]byte, bool, error) {
value, found, err := t.primary.reader(store, key)
if err != nil {
return nil, false, fmt.Errorf("primary reader: %w", err)
}
return value, found, nil
}

// BuildRoute returns a Route that dispatches the given module names to
// this DualWriteRouter. Reads, writes, iteration and proof requests
// for those modules will all flow through this dual-write router.
//
// Module names must be unique; NewRoute's validation rules apply. The
// returned Route may be passed to NewModuleRouter alongside other
// Routes to compose multi-database setups.
func (t *TestOnlyDualWriteRouter) BuildRoute(moduleNames ...string) (*Route, error) { // TODO LLM you need to write a unit test for this
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale LLM instruction left in source code

Low Severity

The comment // TODO LLM you need to write a unit test for this on BuildRoute is an accidentally committed prompt/instruction to an LLM. The unit tests it requests already exist extensively in dual_write_router_test.go (13+ test functions covering BuildRoute), making this TODO stale and confusing.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 009bf03. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stale TODO comment

return NewRoute(t.Read, t.ApplyChangeSets, t.Iterator, t.GetProof, moduleNames...)
}
Loading
Loading