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

x/gamm : Fix public/private on GetNextPoolNumber API #1987

Merged
merged 3 commits into from
Jul 7, 2022
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Golang API breaks

* [#1987](https://github.com/osmosis-labs/osmosis/pull/1987) Remove `GammKeeper.GetNextPoolNumberAndIncrement` in favor of the non-mutative `GammKeeper.GetNextPoolNumber`.
* [#1937](https://github.com/osmosis-labs/osmosis/pull/1937) Change `lockupKeeper.ExtendLock` to take in lockID instead of the direct lock struct.
* [#1893](https://github.com/osmosis-labs/osmosis/pull/1893) Change `EpochsKeeper.SetEpochInfo` to `AddEpochInfo`, which has more safety checks with it. (Makes it suitable to be called within upgrades)
* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Remove methods that constitute AppModuleSimulation APIs for several modules' AppModules, which implemented no-ops
* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Add hourly epochs to `x/epochs` DefaultGenesis.
* [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface, instead use simapp.App
* [#1630](https://github.com/osmosis-labs/osmosis/pull/1630) Delete the v043_temp module, now that we're on an updated SDK version.
* [#1667](https://github.com/osmosis-labs/osmosis/pull/1673) Move wasm-bindings code out of app .
* [#1667](https://github.com/osmosis-labs/osmosis/pull/1673) Move wasm-bindings code out of app package into its own root level package.

### Features

Expand Down
4 changes: 2 additions & 2 deletions x/gamm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// state, which includes the current live pools, global pool parameters (e.g. pool creation fee), next pool number etc.
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState, unpacker codectypes.AnyUnpacker) {
k.SetParams(ctx, genState.Params)
k.SetNextPoolNumber(ctx, genState.NextPoolNumber)
k.setNextPoolNumber(ctx, genState.NextPoolNumber)

// Sums up the liquidity in all genesis state pools to find the total liquidity across all pools.
// Also adds each genesis state pool to the x/gamm module's state
Expand Down Expand Up @@ -51,7 +51,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
poolAnys = append(poolAnys, any)
}
return &types.GenesisState{
NextPoolNumber: k.GetNextPoolNumberAndIncrement(ctx),
NextPoolNumber: k.GetNextPoolNumber(ctx),
Pools: poolAnys,
Params: k.GetParams(ctx),
}
Expand Down
2 changes: 1 addition & 1 deletion x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (q Querier) NumPools(ctx context.Context, _ *types.QueryNumPoolsRequest) (*
sdkCtx := sdk.UnwrapSDKContext(ctx)

return &types.QueryNumPoolsResponse{
NumPools: q.Keeper.GetNextPoolNumberAndIncrement(sdkCtx) - 1,
NumPools: q.Keeper.GetNextPoolNumber(sdkCtx) - 1,
}, nil
}

Expand Down
22 changes: 14 additions & 8 deletions x/gamm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,17 @@ func (k Keeper) DeletePool(ctx sdk.Context, poolId uint64) error {
// return nil
// }

// SetNextPoolNumber sets next pool number.
func (k Keeper) SetNextPoolNumber(ctx sdk.Context, poolNumber uint64) {
// setNextPoolNumber sets next pool number.
func (k Keeper) setNextPoolNumber(ctx sdk.Context, poolNumber uint64) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: poolNumber})
store.Set(types.KeyNextGlobalPoolNumber, bz)
}

// GetNextPoolNumberAndIncrement returns the next pool number, and increments the corresponding state entry.
func (k Keeper) GetNextPoolNumberAndIncrement(ctx sdk.Context) uint64 {
var poolNumber uint64
// GetNextPoolNumber returns the next pool number.
// TODO: Rename NextPoolNumber to NextPoolId
func (k Keeper) GetNextPoolNumber(ctx sdk.Context) uint64 {
var nextPoolId uint64
store := ctx.KVStore(k.storeKey)

bz := store.Get(types.KeyNextGlobalPoolNumber)
Expand All @@ -219,11 +220,16 @@ func (k Keeper) GetNextPoolNumberAndIncrement(ctx sdk.Context) uint64 {
panic(err)
}

poolNumber = val.GetValue()
nextPoolId = val.GetValue()
}
return nextPoolId
}

k.SetNextPoolNumber(ctx, poolNumber+1)
return poolNumber
// getNextPoolNumberAndIncrement returns the next pool number, and increments the corresponding state entry.
func (k Keeper) getNextPoolNumberAndIncrement(ctx sdk.Context) uint64 {
nextPoolId := k.GetNextPoolNumber(ctx)
k.setNextPoolNumber(ctx, nextPoolId+1)
return nextPoolId
}

// set ScalingFactors in stable stableswap pools
Expand Down
2 changes: 1 addition & 1 deletion x/gamm/keeper/pool_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, er
return 0, err
}

poolId := k.GetNextPoolNumberAndIncrement(ctx)
poolId := k.getNextPoolNumberAndIncrement(ctx)
pool, err := msg.CreatePool(ctx, poolId)
if err != nil {
return 0, err
Expand Down