Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### State Compatible

* [#9334](https://github.com/osmosis-labs/osmosis/pull/9334) fix: iavl pruning issue move onto next version if stuck
* [#9332](https://github.com/osmosis-labs/osmosis/pull/9332) fix(poolmanager): only write to cache in finalize execution mode

## v28.0.5

Expand All @@ -68,7 +69,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#9050](https://github.com/osmosis-labs/osmosis/pull/9050) chore: bump ibc-go to v8.7.0
* [#9006](https://github.com/osmosis-labs/osmosis/pull/9006) feat: CosmWasm Pool raw state query


## v28.0.4

### State Breaking
Expand Down
33 changes: 24 additions & 9 deletions x/poolmanager/create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ func (k Keeper) getNextPoolIdAndIncrement(ctx sdk.Context) uint64 {
return nextPoolId
}

func (k *Keeper) getPoolRouteRaw(ctx sdk.Context, poolId uint64) (*types.ModuleRoute, error) {
store := ctx.KVStore(k.storeKey)
moduleRoute := &types.ModuleRoute{}
found, err := osmoutils.Get(store, types.FormatModuleRouteKey(poolId), moduleRoute)
if err != nil {
return nil, err
}
if !found {
return nil, types.FailedToFindRouteError{PoolId: poolId}
}
return moduleRoute, nil
}

func (k *Keeper) SetPoolRoute(ctx sdk.Context, poolId uint64, poolType types.PoolType) {
store := ctx.KVStore(k.storeKey)
osmoutils.MustSet(store, types.FormatModuleRouteKey(poolId), &types.ModuleRoute{PoolType: poolType})
Expand All @@ -167,11 +180,11 @@ type poolModuleCacheValue struct {
func (k *Keeper) GetPoolType(ctx sdk.Context, poolId uint64) (types.PoolType, error) {
poolModuleCandidate, cacheHit := k.cachedPoolModules.Load(poolId)
if !cacheHit {
_, err := k.GetPoolModule(ctx, poolId)
moduleRoute, err := k.getPoolRouteRaw(ctx, poolId)
if err != nil {
return 0, err
}
poolModuleCandidate, _ = k.cachedPoolModules.Load(poolId)
return moduleRoute.PoolType, nil
}
v, _ := poolModuleCandidate.(poolModuleCacheValue)
if cacheHit {
Expand Down Expand Up @@ -212,13 +225,15 @@ func (k *Keeper) GetPoolModule(ctx sdk.Context, poolId uint64) (types.PoolModule
return nil, types.UndefinedRouteError{PoolType: moduleRoute.PoolType, PoolId: poolId}
}

k.cachedPoolModules.Store(poolId, poolModuleCacheValue{
pooltype: moduleRoute.PoolType,
module: swapModule,
gasFlat: gasFlat,
gasKey: gasKey,
gasValue: gasVal,
})
if ctx.ExecMode() == sdk.ExecModeFinalize {
k.cachedPoolModules.Store(poolId, poolModuleCacheValue{
pooltype: moduleRoute.PoolType,
module: swapModule,
gasFlat: gasFlat,
gasKey: gasKey,
gasValue: gasVal,
})
}

return swapModule, nil
}
Expand Down
80 changes: 44 additions & 36 deletions x/poolmanager/create_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,42 +226,50 @@ func (s *KeeperTestSuite) TestCreatePool() {
},
}

for i, tc := range tests {
s.Run(tc.name, func() {
if tc.isPermissionlessPoolCreationDisabled {
params := s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx)
params.IsPermissionlessPoolCreationEnabled = false
s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, params)
}

if tc.expectedModuleType == cosmwasmKeeperType {
codeId := s.StoreCosmWasmPoolContractCode(apptesting.TransmuterContractName)
s.Require().Equal(validTransmuterCodeId, codeId)
s.App.CosmwasmPoolKeeper.WhitelistCodeId(s.Ctx, codeId)
}

poolmanagerKeeper := s.App.PoolManagerKeeper
ctx := s.Ctx

poolCreationFee := poolmanagerKeeper.GetParams(s.Ctx).PoolCreationFee
s.FundAcc(s.TestAccs[0], append(tc.creatorFundAmount, poolCreationFee...))

poolId, err := poolmanagerKeeper.CreatePool(ctx, tc.msg)

if tc.expectError {
s.Require().Error(err)
return
}

// Validate pool.
s.Require().NoError(err)
s.Require().Equal(uint64(i+1), poolId)

// Validate that mapping pool id -> module type has been persisted.
swapModule, err := poolmanagerKeeper.GetPoolModule(ctx, poolId)
s.Require().NoError(err)
s.Require().Equal(tc.expectedModuleType, reflect.TypeOf(swapModule))
})
// setup cosmwasm pool
codeId := s.StoreCosmWasmPoolContractCode(apptesting.TransmuterContractName)
s.Require().Equal(validTransmuterCodeId, codeId)
s.App.CosmwasmPoolKeeper.WhitelistCodeId(s.Ctx, codeId)

execModes := map[string]sdk.ExecMode{
"check": sdk.ExecModeCheck,
"finalize": sdk.ExecModeFinalize,
}
totalTestCount := 0
for _, tc := range tests {
for execModeName, execMode := range execModes {
totalTestCount++
s.Run(fmt.Sprintf("%s-%s", tc.name, execModeName), func() {
s.Ctx = s.Ctx.WithExecMode(execMode)
if tc.isPermissionlessPoolCreationDisabled {
params := s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx)
params.IsPermissionlessPoolCreationEnabled = false
s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, params)
}

poolmanagerKeeper := s.App.PoolManagerKeeper
ctx := s.Ctx

poolCreationFee := poolmanagerKeeper.GetParams(s.Ctx).PoolCreationFee
s.FundAcc(s.TestAccs[0], append(tc.creatorFundAmount, poolCreationFee...))

poolId, err := poolmanagerKeeper.CreatePool(ctx, tc.msg)

if tc.expectError {
s.Require().Error(err)
return
}

// Validate pool.
s.Require().NoError(err)
s.Require().Equal(uint64(totalTestCount), poolId)

// Validate that mapping pool id -> module type has been persisted.
swapModule, err := poolmanagerKeeper.GetPoolModule(ctx, poolId)
s.Require().NoError(err)
s.Require().Equal(tc.expectedModuleType, reflect.TypeOf(swapModule))
})
}
}
}

Expand Down