Skip to content

Commit

Permalink
[CORE-538] Clean-up shutdown code since the DBs are now closed proper…
Browse files Browse the repository at this point in the history
…ly within Cosmos 0.50 SDK. (#920)
  • Loading branch information
lcwik authored Jan 4, 2024
1 parent 04ca58a commit d2ec340
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 24 deletions.
13 changes: 2 additions & 11 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"context"
"encoding/json"
"errors"
"io"
"math/big"
"net/http"
Expand Down Expand Up @@ -223,8 +222,6 @@ type App struct {
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry
db dbm.DB
snapshotDB dbm.DB
event runtime.EventService
closeOnce func() error

Expand Down Expand Up @@ -315,7 +312,6 @@ func assertAppPreconditions() {
func New(
logger log.Logger,
db dbm.DB,
snapshotDB dbm.DB,
traceStore io.Writer,
loadLatest bool,
appOpts servertypes.AppOptions,
Expand Down Expand Up @@ -390,8 +386,6 @@ func New(
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
db: db,
snapshotDB: snapshotDB,
}
app.closeOnce = sync.OnceValue[error](
func() error {
Expand All @@ -401,11 +395,7 @@ func New(
if app.Server != nil {
app.Server.Stop()
}
return errors.Join(
// TODO(CORE-538): Remove this if possible during upgrade to Cosmos 0.50.
app.db.Close(),
app.snapshotDB.Close(),
)
return nil
},
)

Expand Down Expand Up @@ -1600,6 +1590,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig) {

// Close invokes an ordered shutdown of routines.
func (app *App) Close() error {
app.BaseApp.Close()
return app.closeOnce()
}

Expand Down
3 changes: 0 additions & 3 deletions protocol/app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func BenchmarkFullAppSimulation(b *testing.B) {
return app.New(
logger,
db,
dbm.NewMemDB(),
nil,
true,
appOptions,
Expand Down Expand Up @@ -291,7 +290,6 @@ func TestFullAppSimulation(t *testing.T) {
return app.New(
logger,
db,
dbm.NewMemDB(),
nil,
true,
appOptions,
Expand Down Expand Up @@ -364,7 +362,6 @@ func TestAppStateDeterminism(t *testing.T) {
return app.New(
logger,
db,
dbm.NewMemDB(),
nil,
true,
appOptions,
Expand Down
2 changes: 0 additions & 2 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func (a appCreator) newApp(
return dydxapp.New(
logger,
db,
snapshotDB,
traceStore,
true,
appOpts,
Expand Down Expand Up @@ -354,7 +353,6 @@ func (a appCreator) appExport(
dydxApp := dydxapp.New(
logger,
db,
dbm.NewMemDB(),
traceStore,
height == -1, // -1: no height provided
appOpts,
Expand Down
5 changes: 0 additions & 5 deletions protocol/testutil/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ func DefaultTestApp(customFlags map[string]interface{}, baseAppOptions ...func(*
logger, _ = testlog.TestLogger()
}
db := dbm.NewMemDB()
snapshotsDB := dbm.NewMemDB()
dydxApp := app.New(
logger,
db,
snapshotsDB,
nil,
true,
appOptions,
Expand Down Expand Up @@ -1274,9 +1272,6 @@ func launchValidatorInDir(
case a = <-appCaptor:
shutdownFn = func() error {
cancelFn()
// TODO(CORE-538): Remove this explicit app.Close() invocation since wrapCPUProfile doesn't actually
// wait till the Cosmos app shuts down.
a.Close()
return <-done
}
return a, shutdownFn, nil
Expand Down
3 changes: 0 additions & 3 deletions protocol/testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func DefaultConfig(options *NetworkConfigOptions) network.Config {
return app.New(
val.GetCtx().Logger,
dbm.NewMemDB(),
dbm.NewMemDB(),
nil,
true,
appOptions,
Expand Down Expand Up @@ -177,7 +176,6 @@ func NewTestNetworkFixture() network.TestFixture {
dydxApp := app.New(
log.NewNopLogger(),
dbm.NewMemDB(),
dbm.NewMemDB(),
nil,
true,
appOptions,
Expand All @@ -187,7 +185,6 @@ func NewTestNetworkFixture() network.TestFixture {
return app.New(
val.GetCtx().Logger,
dbm.NewMemDB(),
dbm.NewMemDB(),
nil,
true,
appOptions,
Expand Down

0 comments on commit d2ec340

Please sign in to comment.