Skip to content

Commit fbc91b7

Browse files
authored
x/gamm : Fix public/private on GetNextPoolNumber API (#1987)
* Fix public/private on GetNextPoolNumber API * Add changelog * Drive by changelog improvement
1 parent 73a5853 commit fbc91b7

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4949

5050
#### Golang API breaks
5151

52+
* [#1987](https://github.com/osmosis-labs/osmosis/pull/1987) Remove `GammKeeper.GetNextPoolNumberAndIncrement` in favor of the non-mutative `GammKeeper.GetNextPoolNumber`.
5253
* [#1937](https://github.com/osmosis-labs/osmosis/pull/1937) Change `lockupKeeper.ExtendLock` to take in lockID instead of the direct lock struct.
5354
* [#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)
5455
* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Remove methods that constitute AppModuleSimulation APIs for several modules' AppModules, which implemented no-ops
5556
* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Add hourly epochs to `x/epochs` DefaultGenesis.
5657
* [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface, instead use simapp.App
5758
* [#1630](https://github.com/osmosis-labs/osmosis/pull/1630) Delete the v043_temp module, now that we're on an updated SDK version.
58-
* [#1667](https://github.com/osmosis-labs/osmosis/pull/1673) Move wasm-bindings code out of app .
59+
* [#1667](https://github.com/osmosis-labs/osmosis/pull/1673) Move wasm-bindings code out of app package into its own root level package.
5960

6061
### Features
6162

x/gamm/keeper/genesis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// state, which includes the current live pools, global pool parameters (e.g. pool creation fee), next pool number etc.
1212
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState, unpacker codectypes.AnyUnpacker) {
1313
k.SetParams(ctx, genState.Params)
14-
k.SetNextPoolNumber(ctx, genState.NextPoolNumber)
14+
k.setNextPoolNumber(ctx, genState.NextPoolNumber)
1515

1616
// Sums up the liquidity in all genesis state pools to find the total liquidity across all pools.
1717
// Also adds each genesis state pool to the x/gamm module's state
@@ -51,7 +51,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
5151
poolAnys = append(poolAnys, any)
5252
}
5353
return &types.GenesisState{
54-
NextPoolNumber: k.GetNextPoolNumberAndIncrement(ctx),
54+
NextPoolNumber: k.GetNextPoolNumber(ctx),
5555
Pools: poolAnys,
5656
Params: k.GetParams(ctx),
5757
}

x/gamm/keeper/grpc_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (q Querier) NumPools(ctx context.Context, _ *types.QueryNumPoolsRequest) (*
120120
sdkCtx := sdk.UnwrapSDKContext(ctx)
121121

122122
return &types.QueryNumPoolsResponse{
123-
NumPools: q.Keeper.GetNextPoolNumberAndIncrement(sdkCtx) - 1,
123+
NumPools: q.Keeper.GetNextPoolNumber(sdkCtx) - 1,
124124
}, nil
125125
}
126126

x/gamm/keeper/pool.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,17 @@ func (k Keeper) DeletePool(ctx sdk.Context, poolId uint64) error {
196196
// return nil
197197
// }
198198

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

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

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

222-
poolNumber = val.GetValue()
223+
nextPoolId = val.GetValue()
223224
}
225+
return nextPoolId
226+
}
224227

225-
k.SetNextPoolNumber(ctx, poolNumber+1)
226-
return poolNumber
228+
// getNextPoolNumberAndIncrement returns the next pool number, and increments the corresponding state entry.
229+
func (k Keeper) getNextPoolNumberAndIncrement(ctx sdk.Context) uint64 {
230+
nextPoolId := k.GetNextPoolNumber(ctx)
231+
k.setNextPoolNumber(ctx, nextPoolId+1)
232+
return nextPoolId
227233
}
228234

229235
// set ScalingFactors in stable stableswap pools

x/gamm/keeper/pool_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, er
105105
return 0, err
106106
}
107107

108-
poolId := k.GetNextPoolNumberAndIncrement(ctx)
108+
poolId := k.getNextPoolNumberAndIncrement(ctx)
109109
pool, err := msg.CreatePool(ctx, poolId)
110110
if err != nil {
111111
return 0, err

0 commit comments

Comments
 (0)