Skip to content

Commit

Permalink
fix: cosmwasm pool model code ID migration (#7595)
Browse files Browse the repository at this point in the history
* fix: cosmwasm pool model code ID migration

* changelog

* Generated protofile changes

* lint

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
p0mvn and github-actions authored Feb 23, 2024
1 parent ef33c2c commit a84bdc4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#7509](https://github.com/osmosis-labs/osmosis/pull/7509) Distributing ProtoRev profits to the community pool and burn address
* [#7550](https://github.com/osmosis-labs/osmosis/pull/7550) Speedup small CL swaps, by only fetching CL uptime accumulators if there is a tick crossing.
* [#7562](https://github.com/osmosis-labs/osmosis/pull/7562) Speedup Protorev estimation logic by removing unnecessary taker fee simulations.
* [#7595](https://github.com/osmosis-labs/osmosis/pull/7595) Fix cosmwasm pool model code ID migration.

### State Compatible

Expand Down
4 changes: 4 additions & 0 deletions x/cosmwasmpool/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (k Keeper) migrateCosmwasmPools(ctx sdk.Context, poolIds []uint64, newCodeI
if err != nil {
return err
}

// Update code ID to the updated one in state
cwPool.SetCodeId(newCodeId)
k.SetPool(ctx, cwPool)
}

// Whitelist new code id. No-op if already whitelisted.
Expand Down
17 changes: 15 additions & 2 deletions x/cosmwasmpool/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
preUploadCodeIdPlaceholder uint64 = 1000
zeroCodeId uint64 = 0
defaultPoolCountToPreCreate uint64 = 3

// We create a code id for each pool. Since we provide code to upload in this test,
// we expect the code id to be one greater than the default pool count.
expectedNewCodeId uint64 = defaultPoolCountToPreCreate + 1
)

type MigrateMsg struct{}
Expand Down Expand Up @@ -181,7 +185,7 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
byteCode: emptyByteCode,
migrateMsg: emptyMigrateMsg,

expectedCodeId: validCodeId,
expectedCodeId: expectedNewCodeId,
},
{
name: "happy path with code id to upload",
Expand All @@ -192,7 +196,7 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
migrateMsg: emptyMigrateMsg,
shouldWhitelistCWPoolModuleAccountUpload: true,

expectedCodeId: validCodeId,
expectedCodeId: expectedNewCodeId,
},
{
name: "error: contract without migration entrypoint",
Expand Down Expand Up @@ -298,6 +302,15 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
// Check that the code id is whitelisted.
s.Require().True(cosmwasmPoolKeeper.IsWhitelisted(s.Ctx, tc.expectedCodeId))

s.Require().NotEqual(0, len(tc.poolIdsToMigrate))
for _, poolID := range tc.poolIdsToMigrate {
// Check that the pool is migrated.
pool, err := cosmwasmPoolKeeper.GetPoolById(s.Ctx, poolID)
s.Require().NoError(err)

s.Require().Equal(tc.expectedCodeId, pool.GetCodeId())
}

// Validate that the event is emitted.
s.AssertEventEmitted(s.Ctx, types.TypeEvtMigratedCosmwasmPoolCode, 1)
})
Expand Down
5 changes: 5 additions & 0 deletions x/cosmwasmpool/model/store_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ func (p CosmWasmPool) SetWasmKeeper(wasmKeeper types.WasmKeeper) {
func (p *CosmWasmPool) GetPoolDenoms(ctx sdk.Context) []string {
panic("CosmWasmPool.GetPoolDenoms not implemented")
}

// SetCodeId implements types.CosmWasmExtension.
func (p *CosmWasmPool) SetCodeId(codeId uint64) {
p.CodeId = codeId
}
2 changes: 2 additions & 0 deletions x/cosmwasmpool/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ type CosmWasmExtension interface {
SetWasmKeeper(wasmKeeper WasmKeeper)

GetTotalPoolLiquidity(ctx sdk.Context) sdk.Coins

SetCodeId(codeId uint64)
}

0 comments on commit a84bdc4

Please sign in to comment.