Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): Fix pebbleDB integration #23552

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the fix. Cloning the data ensures it remains valid after the closer call

}

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
Loading