Skip to content

Commit

Permalink
feat(v2.11): upgrade handler fixing the escrow accounts balances
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Mar 19, 2024
1 parent cedcccb commit 12c5098
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,5 @@ const (
Upgrade2_8 = "v2.8"
Upgrade2_9 = "v2.9"
Upgrade2_10 = "v2.10"
Upgrade2_11 = "v2.11"
)
13 changes: 13 additions & 0 deletions app/upgrade_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
terraappconfig "github.com/terra-money/core/v2/app/config"
v2_10 "github.com/terra-money/core/v2/app/upgrades/v2.10"
v2_11 "github.com/terra-money/core/v2/app/upgrades/v2.11"
v2_2_0 "github.com/terra-money/core/v2/app/upgrades/v2.2.0"
v2_3_0 "github.com/terra-money/core/v2/app/upgrades/v2.3.0"
v2_4 "github.com/terra-money/core/v2/app/upgrades/v2.4"
Expand Down Expand Up @@ -101,6 +102,15 @@ func (app *TerraApp) RegisterUpgradeHandlers() {
app.GetAppCodec(),
),
)
app.Keepers.UpgradeKeeper.SetUpgradeHandler(
terraappconfig.Upgrade2_11,
v2_11.CreateUpgradeHandler(
app.GetModuleManager(),
app.GetConfigurator(),
app.Keepers.BankKeeper,
app.Keepers.TransferKeeper,
),
)
}

func (app *TerraApp) RegisterUpgradeStores() {
Expand Down Expand Up @@ -136,5 +146,8 @@ func (app *TerraApp) RegisterUpgradeStores() {
} else if upgradeInfo.Name == terraappconfig.Upgrade2_10 && !app.Keepers.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
} else if upgradeInfo.Name == terraappconfig.Upgrade2_11 && !app.Keepers.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))

Check warning on line 151 in app/upgrade_handler.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade_handler.go#L150-L151

Added lines #L150 - L151 were not covered by tests
}
}
61 changes: 61 additions & 0 deletions app/upgrades/v2.11/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package v2_11

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
custombankkeeper "github.com/terra-money/core/v2/x/bank/keeper"
)

type EscrowUpdate struct {
EscrowAddress sdk.AccAddress
Assets []sdk.Coin
}

func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
bankKeeper custombankkeeper.Keeper,
transferKeeper ibctransferkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// This slice is initialized with objects that describe the escrow account address and the coins that need to be minted to fix the discrepancy.
// To find the escrow account and address have been used the following software:
// https://github.com/strangelove-ventures/escrow-checker/commit/adf0d867e2210c9ff0a27d8dff1c74ed0c8a00dc
updates := []EscrowUpdate{
{
EscrowAddress: sdk.AccAddress("terra1s308jav50mgct9x4f87u23w2tfe8q6qe45y7s4"),
Assets: []sdk.Coin{sdk.NewCoin("ibc/815FC81EB6BD612206BD9A9909A02F7691D24A5B97CDFE2124B1BDCA9D4AB14C", sdk.NewInt(1000000000))},
},
}

for _, update := range updates {
for _, coin := range update.Assets {
coins := sdk.NewCoins(coin)

if err := bankKeeper.MintCoins(ctx, transfertypes.ModuleName, coins); err != nil {
return nil, err
}

if err := bankKeeper.SendCoinsFromModuleToAccount(ctx, transfertypes.ModuleName, update.EscrowAddress, coins); err != nil {
return nil, err
}

// For ibc-go v7+ you will also need to update the transfer module's store for the total escrow amounts.
currentTotalEscrow := transferKeeper.GetTotalEscrowForDenom(ctx, coin.GetDenom())
newTotalEscrow := currentTotalEscrow.Add(coin)
transferKeeper.SetTotalEscrowForDenom(ctx, newTotalEscrow)
}
}

// Run migrations.
versionMap, err := mm.RunMigrations(ctx, cfg, vm)
if err != nil {
return nil, err
}

return versionMap, err
}
}
4 changes: 2 additions & 2 deletions client/docs/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"swagger": "2.0",
"info": {
"description": "Explore the <a target='_blank' href='https://github.com/terra-money/core'>Terra Core v2.10 source code</a><br/>Interact with the chain using <a target='_blank' href='https://station.money/'>Station</a><br/>Create a DAO using <a target='_blank' href='https://enterprise.money/'>Enterprise</a><br/>Run on-chain automated jobs with <a target='_blank' href='https://warp.money/'>Warp</a><br/>Explore the network using <a target='_blank' href='https://terrasco.pe/'>TerraScope</a><br/>Learn about cross-chain staking with <a target='_blank' href='https://alliance.money/'>Alliance</a><br/>For more information on Terra, visit the <a target='_blank' href='https://docs.terra.money/'>Terra Docs</a>",
"version": "2.10"
"description": "Explore the <a target='_blank' href='https://github.com/terra-money/core'>Terra Core v2.11 source code</a><br/>Interact with the chain using <a target='_blank' href='https://station.money/'>Station</a><br/>Create a DAO using <a target='_blank' href='https://enterprise.money/'>Enterprise</a><br/>Run on-chain automated jobs with <a target='_blank' href='https://warp.money/'>Warp</a><br/>Explore the network using <a target='_blank' href='https://terrasco.pe/'>TerraScope</a><br/>Learn about cross-chain staking with <a target='_blank' href='https://alliance.money/'>Alliance</a><br/>For more information on Terra, visit the <a target='_blank' href='https://docs.terra.money/'>Terra Docs</a>",
"version": "2.11"
},
"apis": [
{
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ swagger: '2.0'
info:
description: >-
Explore the <a target='_blank'
href='https://github.com/terra-money/core'>Terra Core v2.10 source
href='https://github.com/terra-money/core'>Terra Core v2.11 source
code</a><br/>Interact with the chain using <a target='_blank'
href='https://station.money/'>Station</a><br/>Create a DAO using <a
target='_blank' href='https://enterprise.money/'>Enterprise</a><br/>Run
Expand All @@ -13,7 +13,7 @@ info:
href='https://alliance.money/'>Alliance</a><br/>For more information on
Terra, visit the <a target='_blank' href='https://docs.terra.money/'>Terra
Docs</a>
version: '2.10'
version: '2.11'
paths:
/terra/alliances:
get:
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terra-money/core-integration-tests",
"version": "v2.10.0",
"version": "v2.11.0",
"description": "Integration tests for Core using feather.js",
"main": "index.ts",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/setup/chain-upgrade/chain-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

OLD_VERSION=release/v2.9
OLD_VERSION=release/v2.10
UPGRADE_HEIGHT=20
CHAIN_ID=pisco-1
CHAIN_HOME=$(pwd)/chain-upgrade-data
DENOM=uluna
SOFTWARE_UPGRADE_NAME="v2.10"
SOFTWARE_UPGRADE_NAME="v2.11"
GOV_PERIOD="5s"

VAL_MNEMONIC_1="clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion"
Expand Down

0 comments on commit 12c5098

Please sign in to comment.