From d2ec340f54684c47ccccc896fc171762a048641c Mon Sep 17 00:00:00 2001 From: Lukasz Cwik <126621805+lcwik@users.noreply.github.com> Date: Thu, 4 Jan 2024 11:17:42 -0800 Subject: [PATCH] [CORE-538] Clean-up shutdown code since the DBs are now closed properly within Cosmos 0.50 SDK. (#920) --- protocol/app/app.go | 13 ++----------- protocol/app/simulation_test.go | 3 --- protocol/cmd/dydxprotocold/cmd/root.go | 2 -- protocol/testutil/app/app.go | 5 ----- protocol/testutil/network/network.go | 3 --- 5 files changed, 2 insertions(+), 24 deletions(-) diff --git a/protocol/app/app.go b/protocol/app/app.go index 86e8641dcf..8a51faf850 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -3,7 +3,6 @@ package app import ( "context" "encoding/json" - "errors" "io" "math/big" "net/http" @@ -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 @@ -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, @@ -390,8 +386,6 @@ func New( keys: keys, tkeys: tkeys, memKeys: memKeys, - db: db, - snapshotDB: snapshotDB, } app.closeOnce = sync.OnceValue[error]( func() error { @@ -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 }, ) @@ -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() } diff --git a/protocol/app/simulation_test.go b/protocol/app/simulation_test.go index 30a898e407..44de2bd1de 100644 --- a/protocol/app/simulation_test.go +++ b/protocol/app/simulation_test.go @@ -218,7 +218,6 @@ func BenchmarkFullAppSimulation(b *testing.B) { return app.New( logger, db, - dbm.NewMemDB(), nil, true, appOptions, @@ -291,7 +290,6 @@ func TestFullAppSimulation(t *testing.T) { return app.New( logger, db, - dbm.NewMemDB(), nil, true, appOptions, @@ -364,7 +362,6 @@ func TestAppStateDeterminism(t *testing.T) { return app.New( logger, db, - dbm.NewMemDB(), nil, true, appOptions, diff --git a/protocol/cmd/dydxprotocold/cmd/root.go b/protocol/cmd/dydxprotocold/cmd/root.go index 0d202d444a..c31d627a9a 100644 --- a/protocol/cmd/dydxprotocold/cmd/root.go +++ b/protocol/cmd/dydxprotocold/cmd/root.go @@ -314,7 +314,6 @@ func (a appCreator) newApp( return dydxapp.New( logger, db, - snapshotDB, traceStore, true, appOpts, @@ -354,7 +353,6 @@ func (a appCreator) appExport( dydxApp := dydxapp.New( logger, db, - dbm.NewMemDB(), traceStore, height == -1, // -1: no height provided appOpts, diff --git a/protocol/testutil/app/app.go b/protocol/testutil/app/app.go index 70f4ab0cbf..f9864c61a8 100644 --- a/protocol/testutil/app/app.go +++ b/protocol/testutil/app/app.go @@ -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, @@ -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 diff --git a/protocol/testutil/network/network.go b/protocol/testutil/network/network.go index 9c09f79225..49bd69d615 100644 --- a/protocol/testutil/network/network.go +++ b/protocol/testutil/network/network.go @@ -146,7 +146,6 @@ func DefaultConfig(options *NetworkConfigOptions) network.Config { return app.New( val.GetCtx().Logger, dbm.NewMemDB(), - dbm.NewMemDB(), nil, true, appOptions, @@ -177,7 +176,6 @@ func NewTestNetworkFixture() network.TestFixture { dydxApp := app.New( log.NewNopLogger(), dbm.NewMemDB(), - dbm.NewMemDB(), nil, true, appOptions, @@ -187,7 +185,6 @@ func NewTestNetworkFixture() network.TestFixture { return app.New( val.GetCtx().Logger, dbm.NewMemDB(), - dbm.NewMemDB(), nil, true, appOptions,