diff --git a/app/app.go b/app/app.go index 21a36269..860625a3 100644 --- a/app/app.go +++ b/app/app.go @@ -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" "io" "net/http" "os" @@ -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" @@ -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. @@ -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", @@ -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 diff --git a/app/upgrades/v4_1_0/constants.go b/app/upgrades/v4_1_0/constants.go index c68f43a0..8f6be8cb 100644 --- a/app/upgrades/v4_1_0/constants.go +++ b/app/upgrades/v4_1_0/constants.go @@ -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" diff --git a/app/upgrades/v4_1_1/constants.go b/app/upgrades/v4_1_1/constants.go new file mode 100644 index 00000000..cf583639 --- /dev/null +++ b/app/upgrades/v4_1_1/constants.go @@ -0,0 +1,4 @@ +package v4 + +// UpgradeName testnet v4.1.1 rc3 +const UpgradeName = "v4.1.1" diff --git a/app/upgrades/v4_1_1/upgrades.go b/app/upgrades/v4_1_1/upgrades.go new file mode 100644 index 00000000..a352d1f1 --- /dev/null +++ b/app/upgrades/v4_1_1/upgrades.go @@ -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, + +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + + // 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) + } +} diff --git a/app/upgrades/v4_1_1/upgrades_test.go b/app/upgrades/v4_1_1/upgrades_test.go new file mode 100644 index 00000000..9a8e997e --- /dev/null +++ b/app/upgrades/v4_1_1/upgrades_test.go @@ -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) + }) +} diff --git a/scripts/run-node.sh b/scripts/run-node.sh index 227395cf..23f0afb2 100755 --- a/scripts/run-node.sh +++ b/scripts/run-node.sh @@ -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'"' @@ -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 diff --git a/scripts/upgrade_test.sh b/scripts/upgrade_test.sh index e07c8ac9..545acb17 100755 --- a/scripts/upgrade_test.sh +++ b/scripts/upgrade_test.sh @@ -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:-""} diff --git a/x/feeburn/ante/ante.go b/x/feeburn/ante/ante.go index ca7070c6..1bf2fb42 100644 --- a/x/feeburn/ante/ante.go +++ b/x/feeburn/ante/ante.go @@ -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())