Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devnet runs only in-memory #257

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ E2E_CONFIG_SETUP_PATH ?= e2e/optimism/packages/contracts-bedrock/deploy-config/d
FOUNDRY_ARTIFACTS_PATH ?= bindings/artifacts
FOUNDRY_CACHE_PATH ?= bindings/cache

.PHONY: monogen
monogen:
go build -o $(BIN)/monogen ./monogen/cmd

.PHONY: test
test:
$(GO_WRAPPER) test -short ./...
Expand Down
30 changes: 23 additions & 7 deletions integrations/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func startCommandHandler(
return fmt.Errorf("validate server config: %v", err)
}

app, err := startApp(env, svrCtx, appCreator, opts)
isDevnet := svrCtx.Viper.GetBool(flagDev)

app, err := startApp(env, svrCtx, appCreator, isDevnet, opts)
Comment on lines +121 to +123
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Standardize naming of the development mode flag

The variable and parameter names for the development mode flag are inconsistently named (isDevnet and devnet) across functions:

  • isDevnet in startCommandHandler and when passing to startApp and startInProcess.
  • devnet in startApp and startMonomerNode.

For improved code readability and maintainability, consider using a consistent naming convention for this flag throughout the codebase.

Apply this diff to standardize the naming to devnet:

 // In startCommandHandler function
-	isDevnet := svrCtx.Viper.GetBool(flagDev)
+	devnet := svrCtx.Viper.GetBool(flagDev)

-	app, err := startApp(env, svrCtx, appCreator, isDevnet, opts)
+	app, err := startApp(env, svrCtx, appCreator, devnet, opts)

 // Passing to startInProcess
-	if err := startInProcess(..., isDevnet, ...); err != nil {
+	if err := startInProcess(..., devnet, ...); err != nil {

 // In startInProcess function signature
-	func startInProcess(..., isDevnet bool, ...) error {
+	func startInProcess(..., devnet bool, ...) error {

 // Passing to startMonomerNode
-	if err := startMonomerNode(..., isDevnet); err != nil {
+	if err := startMonomerNode(..., devnet); err != nil {

Also applies to: 319-325, 354-354, 359-359, 404-404

if err != nil {
return fmt.Errorf("start application: %v", err)
}
Expand Down Expand Up @@ -158,11 +160,12 @@ func startCommandHandler(
l2ChainID,
appGenesis.AppState,
uint64(appGenesis.GenesisTime.Unix()),
isDevnet,
); err != nil {
return fmt.Errorf("start Monomer node in-process: %v", err)
}

if svrCtx.Viper.GetBool(flagDev) {
if isDevnet {
if err := startOPDevnet(monomerCtx, env, &cosmosToETHLogger{
log: svrCtx.Logger,
}, svrCtx.Viper, engineURL, l2ChainID); err != nil {
Expand Down Expand Up @@ -313,9 +316,14 @@ func startApp(
env *environment.Env,
svrCtx *server.Context,
appCreator servertypes.AppCreator,
devnet bool,
opts server.StartCmdOptions,
) (servertypes.Application, error) {
db, err := opts.DBOpener(svrCtx.Config.RootDir, server.GetAppDBBackend(svrCtx.Viper))
backendType := server.GetAppDBBackend(svrCtx.Viper)
if devnet {
backendType = dbm.MemDBBackend
}
db, err := opts.DBOpener(svrCtx.Config.RootDir, backendType)
if err != nil {
return nil, fmt.Errorf("open db: %v", err)
}
Expand Down Expand Up @@ -343,11 +351,12 @@ func startInProcess(
l2ChainID uint64,
appState json.RawMessage,
genesisTime uint64,
isDevnet bool,
) error {
svrCtx.Logger.Info("Starting Monomer node in-process")
if err := startMonomerNode(&WrappedApplication{
app: app,
}, env, monomerCtx, svrCtx, clientCtx, engineWS, l2ChainID, appState, genesisTime); err != nil {
}, env, monomerCtx, svrCtx, clientCtx, engineWS, l2ChainID, appState, genesisTime, isDevnet); err != nil {
return fmt.Errorf("start Monomer node: %v", err)
}

Expand Down Expand Up @@ -392,6 +401,7 @@ func startMonomerNode(
l2ChainID uint64,
appStateJSON json.RawMessage,
genesisTime uint64,
devnet bool,
) error {
cmtListenAddr := svrCtx.Config.RPC.ListenAddress
cmtListenAddr = strings.TrimPrefix(cmtListenAddr, "tcp://")
Expand All @@ -408,8 +418,14 @@ func startMonomerNode(
*clientCtx = clientCtx.WithClient(rpcclient)
clientCtx.ChainID = fmt.Sprintf("%d", l2ChainID)

backendType := dbm.BackendType(svrCtx.Config.DBBackend)
if devnet {
backendType = dbm.MemDBBackend
svrCtx.Logger.Info("Overriding provided db backend to use in-memory for devnet")
}

var blockPebbleDB *pebble.DB
if backendType := dbm.BackendType(svrCtx.Config.DBBackend); backendType == dbm.MemDBBackend {
if backendType == dbm.MemDBBackend {
blockPebbleDB, err = pebble.Open("", &pebble.Options{
FS: vfs.NewMem(),
})
Expand All @@ -424,13 +440,13 @@ func startMonomerNode(
}
env.DeferErr("close block db", blockPebbleDB.Close)

txdb, err := cometdb.NewDB("tx", cometdb.BackendType(svrCtx.Config.DBBackend), svrCtx.Config.RootDir)
txdb, err := cometdb.NewDB("tx", cometdb.BackendType(backendType), svrCtx.Config.RootDir)
if err != nil {
return fmt.Errorf("create tx db: %v", err)
}
env.DeferErr("close tx db", txdb.Close)

mempooldb, err := dbm.NewDB("mempool", dbm.BackendType(svrCtx.Config.DBBackend), svrCtx.Config.RootDir)
mempooldb, err := dbm.NewDB("mempool", backendType, svrCtx.Config.RootDir)
if err != nil {
return fmt.Errorf("create mempool db: %v", err)
}
Expand Down
Loading