From c70c8b2a7f93cf3c0468641a7d4c7f6754659062 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 11 Oct 2023 16:29:31 -0600 Subject: [PATCH 1/6] use CosmWasmExtension --- x/cosmwasmpool/pool_module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/cosmwasmpool/pool_module.go b/x/cosmwasmpool/pool_module.go index 51496f237ea..814af73c815 100644 --- a/x/cosmwasmpool/pool_module.go +++ b/x/cosmwasmpool/pool_module.go @@ -100,7 +100,7 @@ func (k Keeper) GetPool(ctx sdk.Context, poolId uint64) (poolmanagertypes.PoolI, func (k Keeper) GetPools(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) { return osmoutils.GatherValuesFromStorePrefix( ctx.KVStore(k.storeKey), types.PoolsKey, func(value []byte) (poolmanagertypes.PoolI, error) { - pool := model.Pool{} + pool := model.CosmWasmPool{} err := k.cdc.Unmarshal(value, &pool) if err != nil { return nil, err From 19858e634d5c136537ae67963ab07414bf023f48 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 11 Oct 2023 16:35:30 -0600 Subject: [PATCH 2/6] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2539e2bb33e..9f481ff1223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From c778d874054997cee140017f7d6e7754d950132f Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 11 Oct 2023 17:33:45 -0600 Subject: [PATCH 3/6] just implement getId for deserialization --- x/cosmwasmpool/model/store_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/cosmwasmpool/model/store_model.go b/x/cosmwasmpool/model/store_model.go index 009eb8ed7f2..592378edf5b 100644 --- a/x/cosmwasmpool/model/store_model.go +++ b/x/cosmwasmpool/model/store_model.go @@ -44,7 +44,7 @@ func (p CosmWasmPool) GetAddress() sdk.AccAddress { } func (p CosmWasmPool) GetId() uint64 { - panic("CosmWasmPool.GetId not implemented") + return p.PoolId } func (p CosmWasmPool) GetSpreadFactor(ctx sdk.Context) osmomath.Dec { From 987d1ef16bfa5a4510f0925a477c3dff2a72b3a6 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 11 Oct 2023 17:49:15 -0600 Subject: [PATCH 4/6] separate method for serializable pools --- x/cosmwasmpool/genesis.go | 2 +- x/cosmwasmpool/pool_module.go | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/x/cosmwasmpool/genesis.go b/x/cosmwasmpool/genesis.go index 351a796abd4..be8cecd696c 100644 --- a/x/cosmwasmpool/genesis.go +++ b/x/cosmwasmpool/genesis.go @@ -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) } diff --git a/x/cosmwasmpool/pool_module.go b/x/cosmwasmpool/pool_module.go index 814af73c815..6d57c394bba 100644 --- a/x/cosmwasmpool/pool_module.go +++ b/x/cosmwasmpool/pool_module.go @@ -98,6 +98,23 @@ func (k Keeper) GetPool(ctx sdk.Context, poolId uint64) (poolmanagertypes.PoolI, // - An error if unmarshalling fails for any of the values fetched from the store. // In this case, the slice of PoolI interfaces will be nil. func (k Keeper) GetPools(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) { + return osmoutils.GatherValuesFromStorePrefix( + ctx.KVStore(k.storeKey), types.PoolsKey, func(value []byte) (poolmanagertypes.PoolI, error) { + pool := model.Pool{} + err := k.cdc.Unmarshal(value, &pool) + if err != nil { + return nil, err + } + return &pool, nil + }, + ) +} + +// 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{} @@ -383,7 +400,7 @@ func (k Keeper) GetTotalPoolLiquidity(ctx sdk.Context, poolId uint64) (sdk.Coins // GetTotalLiquidity retrieves the total liquidity of all cw pools. func (k Keeper) GetTotalLiquidity(ctx sdk.Context) (sdk.Coins, error) { totalLiquidity := sdk.Coins{} - pools, err := k.GetPoolsWithWasmKeeper(ctx) + pools, err := k.GetPoolsSerializable(ctx) if err != nil { return sdk.Coins{}, err } From 8294ea3b1fd4614ad51cfb7de6a09964df680d7b Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 11 Oct 2023 17:56:48 -0600 Subject: [PATCH 5/6] fix accident --- x/cosmwasmpool/pool_module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/cosmwasmpool/pool_module.go b/x/cosmwasmpool/pool_module.go index 6d57c394bba..b6182100067 100644 --- a/x/cosmwasmpool/pool_module.go +++ b/x/cosmwasmpool/pool_module.go @@ -400,7 +400,7 @@ func (k Keeper) GetTotalPoolLiquidity(ctx sdk.Context, poolId uint64) (sdk.Coins // GetTotalLiquidity retrieves the total liquidity of all cw pools. func (k Keeper) GetTotalLiquidity(ctx sdk.Context) (sdk.Coins, error) { totalLiquidity := sdk.Coins{} - pools, err := k.GetPoolsSerializable(ctx) + pools, err := k.GetPoolsWithWasmKeeper(ctx) if err != nil { return sdk.Coins{}, err } From dea8e713a68aabbe5599dec65b8c01eb4332d333 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Thu, 12 Oct 2023 10:56:36 -0600 Subject: [PATCH 6/6] add test --- x/cosmwasmpool/genesis_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/cosmwasmpool/genesis_test.go b/x/cosmwasmpool/genesis_test.go index 637e38b5cac..5d97308c24d 100644 --- a/x/cosmwasmpool/genesis_test.go +++ b/x/cosmwasmpool/genesis_test.go @@ -91,6 +91,10 @@ func (s *PoolModuleSuite) TestExportGenesis() { genesis := s.App.CosmwasmPoolKeeper.ExportGenesis(s.Ctx) s.Require().Len(genesis.Pools, 2) + + for _, pool := range genesis.Pools { + s.Require().Equal("/osmosis.cosmwasmpool.v1beta1.CosmWasmPool", pool.GetTypeUrl()) + } } func (s *PoolModuleSuite) TestMarshalUnmarshalGenesis() {