Skip to content

Commit a6d5dea

Browse files
authored
feat: enforce app creator returning application implement AppWithPendingTxStream in build time (#440)
* feat: enforce app creator returning application implementing AppWithPendingTxStream in build time * update application interface and app creator wiring for EVM server integration * use cosmosevmserver.Application interface instead of servertypes.Application with assertion * add new Application interface and AppCreator type to support pending tx stream * add doc
1 parent c5ca267 commit a6d5dea

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
- [\#301](https://github.com/cosmos/evm/pull/301) Add 4-node localnet infrastructure for testing multi-validator setups
4747
- [\#304](https://github.com/cosmos/evm/pull/304) Add system test framework for integration testing
4848
- [\#344](https://github.com/cosmos/evm/pull/344) Add txpool RPC namespace stubs in preparation for app-side mempool implementation
49+
- [\#440](https://github.com/cosmos/evm/pull/440) Enforce app creator returning application implement AppWithPendingTxStream in build time.
4950

5051
### STATE BREAKING
5152

evmd/app.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ import (
132132
"github.com/cosmos/cosmos-sdk/x/staking"
133133
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
134134
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
135+
cosmosevmserver "github.com/cosmos/evm/server"
135136
)
136137

137138
func init() {
@@ -147,9 +148,9 @@ const appName = "evmd"
147148
var defaultNodeHome string
148149

149150
var (
150-
_ runtime.AppI = (*EVMD)(nil)
151-
_ servertypes.Application = (*EVMD)(nil)
152-
_ ibctesting.TestingApp = (*EVMD)(nil)
151+
_ runtime.AppI = (*EVMD)(nil)
152+
_ cosmosevmserver.Application = (*EVMD)(nil)
153+
_ ibctesting.TestingApp = (*EVMD)(nil)
153154
)
154155

155156
// EVMD extends an ABCI application, but with most of its parameters exported.

evmd/cmd/evmd/cmd/root.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,17 @@ func initRootCmd(rootCmd *cobra.Command, evmApp *evmd.EVMD) {
175175
cfg.Seal()
176176

177177
defaultNodeHome := evmdconfig.MustGetDefaultNodeHome()
178+
sdkAppCreator := func(l log.Logger, d dbm.DB, w io.Writer, ao servertypes.AppOptions) servertypes.Application {
179+
return newApp(l, d, w, ao)
180+
}
178181
rootCmd.AddCommand(
179182
genutilcli.InitCmd(evmApp.BasicModuleManager, defaultNodeHome),
180183
genutilcli.Commands(evmApp.TxConfig(), evmApp.BasicModuleManager, defaultNodeHome),
181184
cmtcli.NewCompletionCmd(rootCmd, true),
182185
debug.Cmd(),
183186
confixcmd.ConfigCommand(),
184-
pruning.Cmd(newApp, defaultNodeHome),
185-
snapshot.Cmd(newApp),
187+
pruning.Cmd(sdkAppCreator, defaultNodeHome),
188+
snapshot.Cmd(sdkAppCreator),
186189
NewTestnetCmd(evmApp.BasicModuleManager, banktypes.GenesisBalancesIterator{}, appCreator{}),
187190
)
188191

@@ -272,7 +275,7 @@ func newApp(
272275
db dbm.DB,
273276
traceStore io.Writer,
274277
appOpts servertypes.AppOptions,
275-
) servertypes.Application {
278+
) cosmosevmserver.Application {
276279
var cache storetypes.MultiStorePersistentCache
277280

278281
if cast.ToBool(appOpts.Get(sdkserver.FlagInterBlockCache)) {

server/start.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
cosmosevmtypes "github.com/cosmos/evm/types"
3535

3636
errorsmod "cosmossdk.io/errors"
37+
"cosmossdk.io/log"
3738
pruningtypes "cosmossdk.io/store/pruning/types"
3839

3940
"github.com/cosmos/cosmos-sdk/client"
@@ -53,6 +54,14 @@ import (
5354
// DBOpener is a function to open `application.db`, potentially with customized options.
5455
type DBOpener func(opts types.AppOptions, rootDir string, backend dbm.BackendType) (dbm.DB, error)
5556

57+
type Application interface {
58+
types.Application
59+
AppWithPendingTxStream
60+
}
61+
62+
// AppCreator is a function that allows us to lazily initialize an application implementing with AppWithPendingTxStream.
63+
type AppCreator func(log.Logger, dbm.DB, io.Writer, types.AppOptions) Application
64+
5665
// StartOptions defines options that can be customized in `StartCmd`
5766
type StartOptions struct {
5867
AppCreator types.AppCreator
@@ -61,9 +70,11 @@ type StartOptions struct {
6170
}
6271

6372
// NewDefaultStartOptions use the default db opener provided in tm-db.
64-
func NewDefaultStartOptions(appCreator types.AppCreator, defaultNodeHome string) StartOptions {
73+
func NewDefaultStartOptions(appCreator AppCreator, defaultNodeHome string) StartOptions {
6574
return StartOptions{
66-
AppCreator: appCreator,
75+
AppCreator: func(l log.Logger, d dbm.DB, w io.Writer, ao types.AppOptions) types.Application {
76+
return appCreator(l, d, w, ao)
77+
},
6778
DefaultNodeHome: defaultNodeHome,
6879
DBOpener: cosmosevmserverconfig.OpenDB,
6980
}

0 commit comments

Comments
 (0)