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: cosmwasmpool state export #6666

Merged
merged 7 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug Fixes
* [#6644](https://github.com/osmosis-labs/osmosis/pull/6644) fix: genesis bug in pool incentives linking NoLock gauges and PoolIDs
* [#6666](https://github.com/osmosis-labs/osmosis/pull/6666) fix: cosmwasmpool state export bug

## v19.2.0

Expand Down
2 changes: 1 addition & 1 deletion x/cosmwasmpool/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (k *Keeper) InitGenesis(ctx sdk.Context, gen *types.GenesisState, unpacker
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params := k.GetParams(ctx)

pools, err := k.GetPools(ctx)
pools, err := k.GetPoolsSerializable(ctx)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/cosmwasmpool/model/store_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p CosmWasmPool) GetAddress() sdk.AccAddress {
}

func (p CosmWasmPool) GetId() uint64 {
panic("CosmWasmPool.GetId not implemented")
return p.PoolId
}
Comment on lines 46 to 48
Copy link
Member Author

@czarcas7ic czarcas7ic Oct 11, 2023

Choose a reason for hiding this comment

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

Highlighting that we had to implement this method, otherwise when we call SetPool in InitGenesis with a CosmWasmPool instead of a Pool, we need access to the GetId method. It should be fine to implement this though, since its defined on the CosmWasmPool struct and there is no need for the wasmkeeper to retrieve this.


func (p CosmWasmPool) GetSpreadFactor(ctx sdk.Context) osmomath.Dec {
Expand Down
17 changes: 17 additions & 0 deletions x/cosmwasmpool/pool_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ func (k Keeper) GetPools(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) {
)
}

// GetPoolsSerializable retrieves all pool objects stored in the keeper.
// Because the Pool struct has a non-serializable wasmKeeper field, this method
// utilizes the CosmWasmPool struct directly instead, which allows it to be serialized
// in import/export genesis.
func (k Keeper) GetPoolsSerializable(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) {
return osmoutils.GatherValuesFromStorePrefix(
ctx.KVStore(k.storeKey), types.PoolsKey, func(value []byte) (poolmanagertypes.PoolI, error) {
pool := model.CosmWasmPool{}
err := k.cdc.Unmarshal(value, &pool)
if err != nil {
return nil, err
}
return &pool, nil
},
)
}

// GetPoolsWithWasmKeeper behaves the same as GetPools, but it also sets the WasmKeeper field of the pool.
func (k Keeper) GetPoolsWithWasmKeeper(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) {
return osmoutils.GatherValuesFromStorePrefix(
Expand Down