Skip to content

Commit

Permalink
refactor(server/v2): simplify app manager (partial backport #22300) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 21, 2024
1 parent 89219a3 commit 39a726b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 41 deletions.
4 changes: 2 additions & 2 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ abci.Application = (*Consensus[transaction.Tx])(nil)
type Consensus[T transaction.Tx] struct {
logger log.Logger
appName, version string
app *appmanager.AppManager[T]
app appmanager.AppManager[T]
appCloser func() error
txCodec transaction.Codec[T]
store types.Store
Expand Down Expand Up @@ -77,7 +77,7 @@ type Consensus[T transaction.Tx] struct {
func NewConsensus[T transaction.Tx](
logger log.Logger,
appName string,
app *appmanager.AppManager[T],
app appmanager.AppManager[T],
appCloser func() error,
mp mempool.Mempool[T],
indexedEvents map[string]struct{},
Expand Down
17 changes: 8 additions & 9 deletions server/v2/cometbft/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ func setUpConsensus(t *testing.T, gasLimit uint64, mempool mempool.Mempool[mock.
}, nil
})

s, err := stf.NewSTF(
s, err := stf.New(
log.NewNopLogger().With("module", "stf"),
msgRouterBuilder,
queryRouterBuilder,
Expand All @@ -672,21 +672,20 @@ func setUpConsensus(t *testing.T, gasLimit uint64, mempool mempool.Mempool[mock.
sc := cometmock.NewMockCommiter(log.NewNopLogger(), string(actorName), "stf")
mockStore := cometmock.NewMockStore(ss, sc)

b := appmanager.Builder[mock.Tx]{
STF: s,
DB: mockStore,
am := appmanager.New(appmanager.Config{
ValidateTxGasLimit: gasLimit,
QueryGasLimit: gasLimit,
SimulationGasLimit: gasLimit,
InitGenesis: func(ctx context.Context, src io.Reader, txHandler func(json.RawMessage) error) (store.WriterMap, error) {
},
mockStore,
s,
func(ctx context.Context, src io.Reader, txHandler func(json.RawMessage) error) (store.WriterMap, error) {
_, st, err := mockStore.StateLatest()
require.NoError(t, err)
return branch.DefaultNewWriterMap(st), nil
},
}

am, err := b.Build()
require.NoError(t, err)
nil,
)

return NewConsensus[mock.Tx](log.NewNopLogger(), "testing-app", am, func() error { return nil }, mempool, map[string]struct{}{}, nil, mockStore, Config{AppTomlConfig: DefaultAppTomlConfig()}, mock.TxCodec{}, "test")
}
Expand Down
6 changes: 3 additions & 3 deletions server/v2/cometbft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ require (
cosmossdk.io/core v1.0.0-alpha.4
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5
cosmossdk.io/log v1.4.1
cosmossdk.io/server/v2 v2.0.0-20241014060734-0b43fcc2164c // main
cosmossdk.io/server/v2/appmanager v0.0.0-20241008175849-325728a9fd6c // main
cosmossdk.io/server/v2/stf v0.0.0-20241008175849-325728a9fd6c // main
cosmossdk.io/server/v2 v2.0.0-20241021134528-681366e3469c // main
cosmossdk.io/server/v2/appmanager v0.0.0-20241021134528-681366e3469c // main
cosmossdk.io/server/v2/stf v0.0.0-20241021134528-681366e3469c // main
cosmossdk.io/store/v2 v2.0.0-20241017091405-f01baf302e2b // main
cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
Expand Down
12 changes: 6 additions & 6 deletions server/v2/cometbft/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/server/v2 v2.0.0-20241014060734-0b43fcc2164c h1:P6Em4H2U4nSem6VzgCDZgu0tzqDGmhHe6FN48vnd8TQ=
cosmossdk.io/server/v2 v2.0.0-20241014060734-0b43fcc2164c/go.mod h1:mqEGRyHXCcB1ozs177VfstarUVYWKogXdqGET4vUT24=
cosmossdk.io/server/v2/appmanager v0.0.0-20241008175849-325728a9fd6c h1:MJCOTFyL7lPlMDUFvylEu/2zyFe7NcYe4eMaZowvzk4=
cosmossdk.io/server/v2/appmanager v0.0.0-20241008175849-325728a9fd6c/go.mod h1:/xDfniqVtn5nraiHkNJ4e6rYU0e83YAGsSjwmUA6H8k=
cosmossdk.io/server/v2/stf v0.0.0-20241008175849-325728a9fd6c h1:thOij3diZWxwfKaSJNS6S1SFX+fnOW93emnuu+WSHJY=
cosmossdk.io/server/v2/stf v0.0.0-20241008175849-325728a9fd6c/go.mod h1:MjuTMonZ319tZQX6CV2O5E/+F85KrkNUj5U5ObrrkWs=
cosmossdk.io/server/v2 v2.0.0-20241021134528-681366e3469c h1:LK1ycnBLeAE/anYr8lGSg36GB5iDaBnmv0qcS/jbsCs=
cosmossdk.io/server/v2 v2.0.0-20241021134528-681366e3469c/go.mod h1:FMGQ99V9+I3gpQV7nidWAtxMSRAwRizt2wqbAD7Z81I=
cosmossdk.io/server/v2/appmanager v0.0.0-20241021134528-681366e3469c h1:yKf19uDz3nJNEcud3G2KAzIf/dxkurGD0gSef5sZVfs=
cosmossdk.io/server/v2/appmanager v0.0.0-20241021134528-681366e3469c/go.mod h1:o20qgxElItJvBh+k9DJedXE2tp6udkNrWaf5Fn1mSb4=
cosmossdk.io/server/v2/stf v0.0.0-20241021134528-681366e3469c h1:MbjFJxzzr1vuXBI9ih/agdTl9fX4nvzhOBbsi38I7Yk=
cosmossdk.io/server/v2/stf v0.0.0-20241021134528-681366e3469c/go.mod h1:MjuTMonZ319tZQX6CV2O5E/+F85KrkNUj5U5ObrrkWs=
cosmossdk.io/store v1.0.0-rc.0.0.20241009154331-597e0fac1173 h1:MlvTcx2h4zmZZtIDg35B6bovbb5iUAExPmvaPE1Zci4=
cosmossdk.io/store v1.0.0-rc.0.0.20241009154331-597e0fac1173/go.mod h1:lrhcXu/hRXrLJP4L8syVbs68GJU1WSRBFO3mmjn5oGc=
cosmossdk.io/store/v2 v2.0.0-20241017091405-f01baf302e2b h1:epPBD1ebUwat6Ruw40rsEU4N9CHJ2ZN0ev8EGoNYBvE=
Expand Down
7 changes: 3 additions & 4 deletions server/v2/cometbft/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg
}

s.logger = logger.With(log.ModuleKey, s.Name())
rs := appI.GetStore()
rs := appI.Store()
consensus := NewConsensus(
s.logger,
appI.Name(),
appI.GetAppManager(),
appI,
appI.Close,
s.serverOptions.Mempool(cfg),
indexEvents,
appI.GetQueryHandlers(),
appI.QueryHandlers(),
rs,
s.config,
s.initTxCodec,
Expand All @@ -131,7 +131,6 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg
return err
}
consensus.snapshotManager = snapshots.NewManager(snapshotStore, s.serverOptions.SnapshotOptions(cfg), sc, ss, nil, s.logger)

s.Consensus = consensus

return nil
Expand Down
4 changes: 2 additions & 2 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func (app *SimApp[T]) TxConfig() client.TxConfig {
return app.txConfig
}

// GetStore returns the root store.
func (app *SimApp[T]) GetStore() store.RootStore {
// Store returns the root store.
func (app *SimApp[T]) Store() store.RootStore {
return app.store
}

Expand Down
4 changes: 2 additions & 2 deletions simapp/v2/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewTestApp(t *testing.T) (*SimApp[transaction.Tx], context.Context) {
genesisBytes, err := json.Marshal(genesis)
require.NoError(t, err)

st := app.GetStore()
st := app.Store()
ci, err := st.LastCommitID()
require.NoError(t, err)

Expand Down Expand Up @@ -107,7 +107,7 @@ func MoveNextBlock(t *testing.T, app *SimApp[transaction.Tx], ctx context.Contex

bz := sha256.Sum256([]byte{})

st := app.GetStore()
st := app.Store()
ci, err := st.LastCommitID()
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion simapp/v2/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (app *SimApp[T]) ExportAppStateAndValidators(
return exportedApp, err
}

readerMap, err := app.GetStore().StateAt(latestHeight)
readerMap, err := app.Store().StateAt(latestHeight)
if err != nil {
return exportedApp, err
}
Expand Down
8 changes: 4 additions & 4 deletions simapp/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
cosmossdk.io/depinject v1.0.0
cosmossdk.io/log v1.4.1
cosmossdk.io/math v1.3.0
cosmossdk.io/runtime/v2 v2.0.0-20241017091405-f01baf302e2b // main
cosmossdk.io/server/v2 v2.0.0-20241014060734-0b43fcc2164c // main
cosmossdk.io/runtime/v2 v2.0.0-20241021134528-681366e3469c // main
cosmossdk.io/server/v2 v2.0.0-20241021134528-681366e3469c // main
cosmossdk.io/server/v2/cometbft v0.0.0-00010101000000-000000000000
cosmossdk.io/store/v2 v2.0.0-20241017091405-f01baf302e2b // main
cosmossdk.io/tools/confix v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -62,8 +62,8 @@ require (
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
cosmossdk.io/server/v2/appmanager v0.0.0-20241008175849-325728a9fd6c // indirect; main
cosmossdk.io/server/v2/stf v0.0.0-20241008175849-325728a9fd6c // indirect; main
cosmossdk.io/server/v2/appmanager v0.0.0-20241021134528-681366e3469c // indirect; main
cosmossdk.io/server/v2/stf v0.0.0-20241021134528-681366e3469c // indirect; main
cosmossdk.io/store v1.1.1-0.20240909133312-50288938d1b6 // indirect; main
cosmossdk.io/x/tx v0.13.4-0.20241003111526-30003f667944 // indirect; main
filippo.io/edwards25519 v1.1.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions simapp/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/runtime/v2 v2.0.0-20241017091405-f01baf302e2b h1:h/jxffgtZTMa1qvqz9+5c4uOCxpcEWxYuwHONjd16IM=
cosmossdk.io/runtime/v2 v2.0.0-20241017091405-f01baf302e2b/go.mod h1:KROAOJt1EDL7nELDT7LPpFqWubhTJFD4Uwa1gy2/yxo=
cosmossdk.io/runtime/v2 v2.0.0-20241021134528-681366e3469c h1:f9qU7HpJ1CuUDj4OkHca4BFbSW4X3rAYgwzwFNXiBhg=
cosmossdk.io/runtime/v2 v2.0.0-20241021134528-681366e3469c/go.mod h1:KROAOJt1EDL7nELDT7LPpFqWubhTJFD4Uwa1gy2/yxo=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/server/v2 v2.0.0-20241014060734-0b43fcc2164c h1:P6Em4H2U4nSem6VzgCDZgu0tzqDGmhHe6FN48vnd8TQ=
cosmossdk.io/server/v2 v2.0.0-20241014060734-0b43fcc2164c/go.mod h1:mqEGRyHXCcB1ozs177VfstarUVYWKogXdqGET4vUT24=
cosmossdk.io/server/v2/appmanager v0.0.0-20241008175849-325728a9fd6c h1:MJCOTFyL7lPlMDUFvylEu/2zyFe7NcYe4eMaZowvzk4=
cosmossdk.io/server/v2/appmanager v0.0.0-20241008175849-325728a9fd6c/go.mod h1:/xDfniqVtn5nraiHkNJ4e6rYU0e83YAGsSjwmUA6H8k=
cosmossdk.io/server/v2/stf v0.0.0-20241008175849-325728a9fd6c h1:thOij3diZWxwfKaSJNS6S1SFX+fnOW93emnuu+WSHJY=
cosmossdk.io/server/v2/stf v0.0.0-20241008175849-325728a9fd6c/go.mod h1:MjuTMonZ319tZQX6CV2O5E/+F85KrkNUj5U5ObrrkWs=
cosmossdk.io/server/v2 v2.0.0-20241021134528-681366e3469c h1:LK1ycnBLeAE/anYr8lGSg36GB5iDaBnmv0qcS/jbsCs=
cosmossdk.io/server/v2 v2.0.0-20241021134528-681366e3469c/go.mod h1:FMGQ99V9+I3gpQV7nidWAtxMSRAwRizt2wqbAD7Z81I=
cosmossdk.io/server/v2/appmanager v0.0.0-20241021134528-681366e3469c h1:yKf19uDz3nJNEcud3G2KAzIf/dxkurGD0gSef5sZVfs=
cosmossdk.io/server/v2/appmanager v0.0.0-20241021134528-681366e3469c/go.mod h1:o20qgxElItJvBh+k9DJedXE2tp6udkNrWaf5Fn1mSb4=
cosmossdk.io/server/v2/stf v0.0.0-20241021134528-681366e3469c h1:MbjFJxzzr1vuXBI9ih/agdTl9fX4nvzhOBbsi38I7Yk=
cosmossdk.io/server/v2/stf v0.0.0-20241021134528-681366e3469c/go.mod h1:MjuTMonZ319tZQX6CV2O5E/+F85KrkNUj5U5ObrrkWs=
cosmossdk.io/store v1.0.0-rc.0.0.20240913190136-3bc707a5a214 h1:UUW0+2UgbDwQ452o2aw4DrVSWmowcad7DB7Vln+N94I=
cosmossdk.io/store v1.0.0-rc.0.0.20240913190136-3bc707a5a214/go.mod h1:ct8HATr+s48YYTRXEyP3HF33v9qEVWHMxwOL8P/v4iQ=
cosmossdk.io/store/v2 v2.0.0-20241017091405-f01baf302e2b h1:epPBD1ebUwat6Ruw40rsEU4N9CHJ2ZN0ev8EGoNYBvE=
Expand Down

0 comments on commit 39a726b

Please sign in to comment.