From 576448b8211f040bfe8c12e086e417c4d9ebf7e1 Mon Sep 17 00:00:00 2001 From: Alexander Peters Date: Wed, 29 Jan 2025 12:58:31 +0100 Subject: [PATCH] fix(db): Fix pebbleDB integration (#23552) --- simapp/v2/sim_runner.go | 5 +++-- simapp/v2/sim_test.go | 4 ++-- store/v2/CHANGELOG.md | 3 +++ store/v2/db/pebbledb.go | 2 +- x/simulation/client/cli/flags.go | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/simapp/v2/sim_runner.go b/simapp/v2/sim_runner.go index 56a81f84c4..c64a34f74e 100644 --- a/simapp/v2/sim_runner.go +++ b/simapp/v2/sim_runner.go @@ -135,10 +135,11 @@ func SetupTestInstance[T Tx, V SimulationApp[T]]( appFactory AppFactory[T, V], appConfigFactory AppConfigFactory, randSource simsxv2.RandSource, + dbBackend string, ) TestInstance[T] { tb.Helper() vp := viper.New() - vp.Set("store.app-db-backend", "memdb") + vp.Set("store.app-db-backend", dbBackend) vp.Set("home", tb.TempDir()) depInjCfg := depinject.Configs( @@ -251,7 +252,7 @@ func RunWithRandSource[T Tx, V SimulationApp[T]]( require.NotEmpty(tb, initialBlockHeight, "initial block height must not be 0") setupFn := func(ctx context.Context, r *rand.Rand) (TestInstance[T], ChainState[T], []simtypes.Account) { - testInstance := SetupTestInstance[T, V](tb, appFactory, appConfigFactory, randSource) + testInstance := SetupTestInstance[T, V](tb, appFactory, appConfigFactory, randSource, tCfg.DBBackend) accounts, genesisAppState, chainID, genesisTimestamp := prepareInitialGenesisState( testInstance.App, r, diff --git a/simapp/v2/sim_test.go b/simapp/v2/sim_test.go index 4384c3d671..20b0fd4401 100644 --- a/simapp/v2/sim_test.go +++ b/simapp/v2/sim_test.go @@ -96,7 +96,7 @@ func TestAppSimulationAfterImport(t *testing.T) { chainID := SimAppChainID + "_2" importGenesisChainStateFactory := func(ctx context.Context, r *rand.Rand) (TestInstance[Tx], ChainState[Tx], []simtypes.Account) { - testInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource) + testInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource, cfg.DBBackend) newCs := testInstance.InitializeChain( tb, ctx, @@ -136,7 +136,7 @@ func TestAppImportExport(t *testing.T) { chainID := SimAppChainID tb.Log("importing genesis...\n") - newTestInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource) + newTestInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource, cfg.DBBackend) newTestInstance.InitializeChain( tb, context.Background(), diff --git a/store/v2/CHANGELOG.md b/store/v2/CHANGELOG.md index 2f4820544a..789d1be3d2 100644 --- a/store/v2/CHANGELOG.md +++ b/store/v2/CHANGELOG.md @@ -29,6 +29,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#23013](https://github.com/cosmos/cosmos-sdk/pull/23013) Support memDB for sims +### Bug Fixes + +* [#23552](https://github.com/cosmos/cosmos-sdk/pull/23552) Fix pebbleDB integration ## [v2.0.0-beta.2](https://github.com/cosmos/cosmos-sdk/releases/tag/store/v2.0.0-beta.2) diff --git a/store/v2/db/pebbledb.go b/store/v2/db/pebbledb.go index 62f35b47e4..1a3e39dc9e 100644 --- a/store/v2/db/pebbledb.go +++ b/store/v2/db/pebbledb.go @@ -72,7 +72,7 @@ func (db *PebbleDB) Get(key []byte) ([]byte, error) { return nil, fmt.Errorf("failed to perform PebbleDB read: %w", err) } - return bz, closer.Close() + return slices.Clone(bz), closer.Close() } func (db *PebbleDB) Has(key []byte) (bool, error) { diff --git a/x/simulation/client/cli/flags.go b/x/simulation/client/cli/flags.go index 4ede979e95..98c421aaab 100644 --- a/x/simulation/client/cli/flags.go +++ b/x/simulation/client/cli/flags.go @@ -46,7 +46,7 @@ func GetSimulatorFlags() { flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block") flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output") flag.BoolVar(&FlagCommitValue, "Commit", true, "have the simulation commit") - flag.StringVar(&FlagDBBackendValue, "DBBackend", "goleveldb", "custom db backend type: goleveldb, memdb") + flag.StringVar(&FlagDBBackendValue, "DBBackend", "memdb", "custom db backend type: goleveldb, pebbledb, memdb") // simulation flags flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")