Skip to content

Commit

Permalink
fix(db): Fix pebbleDB integration (#23552)
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe authored Jan 29, 2025
1 parent e2027bf commit 576448b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions simapp/v2/sim_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions simapp/v2/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions store/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion store/v2/db/pebbledb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion x/simulation/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 576448b

Please sign in to comment.