Skip to content

Commit 576448b

Browse files
authored
fix(db): Fix pebbleDB integration (#23552)
1 parent e2027bf commit 576448b

5 files changed

Lines changed: 10 additions & 6 deletions

File tree

simapp/v2/sim_runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ func SetupTestInstance[T Tx, V SimulationApp[T]](
135135
appFactory AppFactory[T, V],
136136
appConfigFactory AppConfigFactory,
137137
randSource simsxv2.RandSource,
138+
dbBackend string,
138139
) TestInstance[T] {
139140
tb.Helper()
140141
vp := viper.New()
141-
vp.Set("store.app-db-backend", "memdb")
142+
vp.Set("store.app-db-backend", dbBackend)
142143
vp.Set("home", tb.TempDir())
143144

144145
depInjCfg := depinject.Configs(
@@ -251,7 +252,7 @@ func RunWithRandSource[T Tx, V SimulationApp[T]](
251252
require.NotEmpty(tb, initialBlockHeight, "initial block height must not be 0")
252253

253254
setupFn := func(ctx context.Context, r *rand.Rand) (TestInstance[T], ChainState[T], []simtypes.Account) {
254-
testInstance := SetupTestInstance[T, V](tb, appFactory, appConfigFactory, randSource)
255+
testInstance := SetupTestInstance[T, V](tb, appFactory, appConfigFactory, randSource, tCfg.DBBackend)
255256
accounts, genesisAppState, chainID, genesisTimestamp := prepareInitialGenesisState(
256257
testInstance.App,
257258
r,

simapp/v2/sim_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
9696
chainID := SimAppChainID + "_2"
9797

9898
importGenesisChainStateFactory := func(ctx context.Context, r *rand.Rand) (TestInstance[Tx], ChainState[Tx], []simtypes.Account) {
99-
testInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource)
99+
testInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource, cfg.DBBackend)
100100
newCs := testInstance.InitializeChain(
101101
tb,
102102
ctx,
@@ -136,7 +136,7 @@ func TestAppImportExport(t *testing.T) {
136136
chainID := SimAppChainID
137137
tb.Log("importing genesis...\n")
138138

139-
newTestInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource)
139+
newTestInstance := SetupTestInstance(tb, appFactory, AppConfig, ti.RandSource, cfg.DBBackend)
140140
newTestInstance.InitializeChain(
141141
tb,
142142
context.Background(),

store/v2/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
2929

3030
* [#23013](https://github.com/cosmos/cosmos-sdk/pull/23013) Support memDB for sims
3131

32+
### Bug Fixes
33+
34+
* [#23552](https://github.com/cosmos/cosmos-sdk/pull/23552) Fix pebbleDB integration
3235

3336
## [v2.0.0-beta.2](https://github.com/cosmos/cosmos-sdk/releases/tag/store/v2.0.0-beta.2)
3437

store/v2/db/pebbledb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (db *PebbleDB) Get(key []byte) ([]byte, error) {
7272
return nil, fmt.Errorf("failed to perform PebbleDB read: %w", err)
7373
}
7474

75-
return bz, closer.Close()
75+
return slices.Clone(bz), closer.Close()
7676
}
7777

7878
func (db *PebbleDB) Has(key []byte) (bool, error) {

x/simulation/client/cli/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func GetSimulatorFlags() {
4646
flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block")
4747
flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output")
4848
flag.BoolVar(&FlagCommitValue, "Commit", true, "have the simulation commit")
49-
flag.StringVar(&FlagDBBackendValue, "DBBackend", "goleveldb", "custom db backend type: goleveldb, memdb")
49+
flag.StringVar(&FlagDBBackendValue, "DBBackend", "memdb", "custom db backend type: goleveldb, pebbledb, memdb")
5050

5151
// simulation flags
5252
flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")

0 commit comments

Comments
 (0)