Skip to content

Commit

Permalink
feat: add testnet handler upgrade v4.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Jan 30, 2024
1 parent e664b69 commit 7dd2d88
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 14 deletions.
29 changes: 22 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"encoding/json"
"fmt"
v3_0_2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v3_0_2"

Check failure on line 6 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"io"
"net/http"
"os"
Expand Down Expand Up @@ -154,10 +155,9 @@ import (
appparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/params"

// unnamed import of statik for swagger UI support
"github.com/rakyll/statik/fs"

v3_0_2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v3_0_2"
v4 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_0"
v4Rc3 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_1"
"github.com/rakyll/statik/fs"

// unnamed import of statik for swagger UI support
_ "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/client/docs/statik"
Expand Down Expand Up @@ -1152,6 +1152,16 @@ func (app *MigalooApp) setupUpgradeHandlers() {
),
)

app.UpgradeKeeper.SetUpgradeHandler(
v4Rc3.UpgradeName,
v4Rc3.CreateUpgradeHandler(
app.mm,
app.configurator,
app.AccountKeeper,
app.FeeBurnKeeper,
),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
Expand All @@ -1165,16 +1175,12 @@ func (app *MigalooApp) setupUpgradeHandlers() {
}

if upgradeInfo.Name == v4.UpgradeName {
// !! ATTENTION !!
// !! WHEN UPGRADING TO SDK v0.47 MAKE SURE TO INCLUDE THIS
// source: https://github.com/cosmos/cosmos-sdk/blob/release/v0.47.x/UPGRADING.md
storeUpgrades := &storetypes.StoreUpgrades{
Added: []string{
consensusparamtypes.StoreKey,
crisistypes.StoreKey,
icqtypes.StoreKey,
feeburnmoduletypes.StoreKey,
authtypes.FeeCollectorName,
},
Deleted: []string{
"intertx",
Expand All @@ -1183,6 +1189,15 @@ func (app *MigalooApp) setupUpgradeHandlers() {
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
if upgradeInfo.Name == v4Rc3.UpgradeName {
storeUpgrades := &storetypes.StoreUpgrades{
Added: []string{
authtypes.FeeCollectorName,
},
}
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
}

// GetMaccPerms returns a copy of the module account permissions
Expand Down
3 changes: 1 addition & 2 deletions app/upgrades/v4_1_0/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package v4

// UpgradeName defines the on-chain upgrade name for the Migaloo v3.0.2 upgrade.
// this upgrade includes the fix for pfm
// UpgradeName mainnet v4.1.0
const UpgradeName = "v4.1.0"
4 changes: 4 additions & 0 deletions app/upgrades/v4_1_1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package v4

// UpgradeName testnet v4.1.1 rc3
const UpgradeName = "v4.1.1"
35 changes: 35 additions & 0 deletions app/upgrades/v4_1_1/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package v4

import (
feeburnkeeper "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/x/feeburn/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// CreateUpgradeHandler small security fix, can be a no-op, running mm.RunMigarions just to be sure
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
accountKeeper authkeeper.AccountKeeper,
feeBurnKeeper feeburnkeeper.Keeper,

Check failure on line 18 in app/upgrades/v4_1_1/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

Check failure on line 21 in app/upgrades/v4_1_1/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
// Burning module permissions
moduleAccI := accountKeeper.GetModuleAccount(ctx, authtypes.FeeCollectorName)
moduleAcc := moduleAccI.(*authtypes.ModuleAccount)
moduleAcc.Permissions = []string{authtypes.Burner}
accountKeeper.SetModuleAccount(ctx, moduleAcc)

// set default fee_burn_percent to 50
feeBurnParams := feeBurnKeeper.GetParams(ctx)
feeBurnParams.TxFeeBurnPercent = "50"

_ = feeBurnKeeper.SetParams(ctx, feeBurnParams)
return mm.RunMigrations(ctx, configurator, fromVM)
}
}
45 changes: 45 additions & 0 deletions app/upgrades/v4_1_1/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package v4_test

import (
"testing"

apptesting "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app"
abci "github.com/cometbft/cometbft/abci/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/stretchr/testify/suite"
)

const (
v4UpgradeHeight = int64(10)
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
}

func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (suite *UpgradeTestSuite) TestUpgrade() {
suite.Setup(suite.T(), apptesting.SimAppChainID)
dummyUpgrade(suite)
feeBurnParam := suite.App.FeeBurnKeeper.GetParams(suite.Ctx)
suite.Require().Equal("50", feeBurnParam.GetTxFeeBurnPercent())
}

func dummyUpgrade(s *UpgradeTestSuite) {
s.Ctx = s.Ctx.WithBlockHeight(v4UpgradeHeight - 1)
plan := upgradetypes.Plan{Name: "v4.1.1", Height: v4UpgradeHeight}
err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan)
s.Require().NoError(err)
_, exists := s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx)
s.Require().True(exists)

s.Ctx = s.Ctx.WithBlockHeight(v4UpgradeHeight)

s.Require().NotPanics(func() {
beginBlockRequest := abci.RequestBeginBlock{}
s.App.BeginBlocker(s.Ctx, beginBlockRequest)
})
}
6 changes: 3 additions & 3 deletions scripts/run-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ $BINARY add-genesis-account $KEY "1000000000000${DENOM}" --keyring-backend $KEYR
$BINARY add-genesis-account $KEY1 "1000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR
$BINARY add-genesis-account $KEY2 "1000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR

update_test_genesis '.app_state["gov"]["voting_params"]["voting_period"]="20s"'
update_test_genesis '.app_state["gov"]["params"]["voting_period"]="20s"'
update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"'
update_test_genesis '.app_state["gov"]["deposit_params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1000000"}]'
update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1000000"}]'
update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}'
update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"'

Expand All @@ -82,5 +82,5 @@ $BINARY collect-gentxs --home $HOME_DIR

# Run this to ensure everything worked and that the genesis file is setup correctly
$BINARY validate-genesis --home $HOME_DIR
# $BINARY start --home $HOME_DIR
$BINARY start --home $HOME_DIR

4 changes: 2 additions & 2 deletions scripts/upgrade_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# the upgrade is a fork, "true" otherwise
FORK=${FORK:-"false"}

OLD_VERSION=v3.0.4
OLD_VERSION=v4.1.0-testnet-rc2
UPGRADE_WAIT=${UPGRADE_WAIT:-20}
HOME=mytestnet
ROOT=$(pwd)
DENOM=uwhale
CHAIN_ID=localmigaloo
SOFTWARE_UPGRADE_NAME="v4.1.0"
SOFTWARE_UPGRADE_NAME="v4.1.1"
ADDITIONAL_PRE_SCRIPTS=${ADDITIONAL_PRE_SCRIPTS:-""}
ADDITIONAL_AFTER_SCRIPTS=${ADDITIONAL_AFTER_SCRIPTS:-""}

Expand Down
2 changes: 2 additions & 0 deletions x/feeburn/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func DeductFees(bankKeeper BankKeeper, ctx sdk.Context, acc types.AccountI, fees
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}

fmt.Printf("burning %v\n", burningFees)

err = bankKeeper.BurnCoins(ctx, types.FeeCollectorName, burningFees)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
Expand Down

0 comments on commit 7dd2d88

Please sign in to comment.