Skip to content

Commit

Permalink
fix: bnb migration (#1823)
Browse files Browse the repository at this point in the history
## Description

Logs error in case there is a supply rather then failing the migration.

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] added appropriate labels to the PR
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
robert-zaremba authored Feb 15, 2023
1 parent 614d2c5 commit 57abf1e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
13 changes: 6 additions & 7 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ func (app *UmeeApp) registerUpgrade4_1(_ upgradetypes.Plan) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
ctx.Logger().Info("Run v4.1 migration")
leverageUpgrader := leveragekeeper.NewMigrator(&app.LeverageKeeper)
err := leverageUpgrader.MigrateBNB(ctx)
migrated, err := leverageUpgrader.MigrateBNB(ctx)
if err != nil {
ctx.Logger().Error("Unable to run v4.1 leverage Migration!", "err", err)
ctx.Logger().Error("Error in v4.1 leverage Migration!", "err", err)
return fromVM, err
}
oracleUpgrader := oraclekeeper.NewMigrator(&app.OracleKeeper)
err = oracleUpgrader.MigrateBNB(ctx)
if err != nil {
ctx.Logger().Error("Unable to run v4.1 oracle Migration!", "err", err)
return fromVM, err
if migrated {
// If leverage BNB migration was skipped, also skip oracle so they stay in sync
oracleUpgrader := oraclekeeper.NewMigrator(&app.OracleKeeper)
oracleUpgrader.MigrateBNB(ctx)
}
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
Expand Down
32 changes: 16 additions & 16 deletions x/leverage/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ func NewMigrator(keeper *Keeper) Migrator {
return Migrator{keeper: keeper}
}

// MigrateBNB fixes the BNB base denom for the 4.1 upgrade
func (m Migrator) MigrateBNB(ctx sdk.Context) error {
// MigrateBNB fixes the BNB base denom for the 4.1 upgrade.
// Also returns a boolean representing whether the token was changed.
func (m Migrator) MigrateBNB(ctx sdk.Context) (bool, error) {
// Bad BNB token denom
badDenom := "ibc/77BCD42E49E5B7E0FC6B269FEBF0185B15044F13F6F38CA285DF0AF883459F40"
// Ensure zero supply of the token being removed from leverage registry
uSupply := m.keeper.GetUTokenSupply(ctx, types.ToUTokenDenom(badDenom))
if !uSupply.IsZero() {
return types.ErrBadSupplyDetected.Wrap(uSupply.String())
ctx.Logger().Error("can't correctly migrate leverage with existing supply",
"token", badDenom, "total_u_supply", uSupply)
return false, nil
}
// Get the existing BNB token settings
correctDenom := "ibc/8184469200C5E667794375F5B0EC3B9ABB6FF79082941BF5D0F8FF59FEBA862E"
token, err := m.keeper.GetTokenSettings(ctx, badDenom)
if err != nil {
return err
return false, err
}
// Modify base denom
token.BaseDenom = correctDenom
// Delete initial entry in token registry
// Delete previous entry in token registry
store := ctx.KVStore(m.keeper.storeKey)
badKey := types.KeyRegisteredToken(badDenom)
store.Delete(badKey)
// Add back to store, but bypass the hooks in SetRegisteredToken
trueKey := types.KeyRegisteredToken(correctDenom)
store.Delete(types.KeyRegisteredToken(badDenom))
// Modify base denom and add back to store, bypassing the hooks in SetRegisteredToken
correctDenom := "ibc/8184469200C5E667794375F5B0EC3B9ABB6FF79082941BF5D0F8FF59FEBA862E"
token.BaseDenom = correctDenom
bz, err := m.keeper.cdc.Marshal(&token)
if err != nil {
return err
return false, err
}
store.Set(trueKey, bz)
return nil
store.Set(types.KeyRegisteredToken(correctDenom), bz)
return true, nil
}
3 changes: 1 addition & 2 deletions x/leverage/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ var (
ErrBlacklisted = errors.Register(ModuleName, 205, "blacklisted Token")
ErrCollateralWeightZero = errors.Register(ModuleName, 206,
"collateral weight of Token is zero: can't be used as a collateral")
ErrDuplicateToken = errors.Register(ModuleName, 207, "duplicate token")
ErrBadSupplyDetected = errors.Register(ModuleName, 208, "supply of a bad token detected")
ErrDuplicateToken = errors.Register(ModuleName, 207, "duplicate token")

// 3XX = User Positions
ErrInsufficientBalance = errors.Register(ModuleName, 300, "insufficient balance")
Expand Down
3 changes: 1 addition & 2 deletions x/oracle/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m Migrator) HistoracleParams3x4(ctx sdk.Context) error {
}

// MigrateBNB fixes the BNB base denom for the 4.1 upgrade without using leverage hooks
func (m Migrator) MigrateBNB(ctx sdk.Context) error {
func (m Migrator) MigrateBNB(ctx sdk.Context) {
badDenom := "ibc/77BCD42E49E5B7E0FC6B269FEBF0185B15044F13F6F38CA285DF0AF883459F40"
correctDenom := "ibc/8184469200C5E667794375F5B0EC3B9ABB6FF79082941BF5D0F8FF59FEBA862E"
acceptList := m.keeper.AcceptList(ctx)
Expand All @@ -46,5 +46,4 @@ func (m Migrator) MigrateBNB(ctx sdk.Context) error {
}
// Overwrite previous accept list
m.keeper.SetAcceptList(ctx, acceptList)
return nil
}

0 comments on commit 57abf1e

Please sign in to comment.