From b53fe10e30a0347f6be99b7f0ae421812d1f6749 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 13:12:36 -0400 Subject: [PATCH] feat: re add MsgCreateValidator check in ante (#271) (#277) (cherry picked from commit 7e8e42014c5abcded1ac7f2dd82e88099eaeb130) Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> --- app/app.go | 55 ++++++++++++------------------------ x/reporter/ante/ante.go | 4 +-- x/reporter/ante/ante_test.go | 28 +++++++++--------- 3 files changed, 34 insertions(+), 53 deletions(-) diff --git a/app/app.go b/app/app.go index 256e88744..9f4b2fa78 100644 --- a/app/app.go +++ b/app/app.go @@ -979,45 +979,26 @@ func (app *App) preBlocker(ph *ProposalHandler) func(sdk.Context, *abci.RequestF } func (app *App) RegisterUpgradeHandlers() { - // const UpgradeName = "v0.2.0" - - // app.UpgradeKeeper.SetUpgradeHandler( - // UpgradeName, - // func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // // one time thing, changing the team address - // currentParams, err := app.DisputeKeeper.Params.Get(ctx) - // if err != nil { - // return nil, err - // } - - // addrCdc := address.Bech32Codec{ - // Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), - // } - - // currentParams.TeamAddress, err = addrCdc.StringToBytes("tellor18wjwgr0j8pv4ektdaxvzsykpntdylftwz8ml97") - // if err != nil { - // return nil, err - // } - - // if err = app.DisputeKeeper.Params.Set(ctx, currentParams); err != nil { - // return nil, err - // } - - // return app.ModuleManager().RunMigrations(ctx, app.Configurator(), fromVM) - // }, - // ) - - // upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() - // if err != nil { - // panic(err) - // } + const UpgradeName = "v0.3.0" - // if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - // storeUpgrades := storetypes.StoreUpgrades{} + app.UpgradeKeeper.SetUpgradeHandler( + UpgradeName, + func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return app.ModuleManager().RunMigrations(ctx, app.Configurator(), fromVM) + }, + ) - // // configure store loader that checks if version == upgradeHeight and applies store upgrades - // app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) - // } + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(err) + } + + if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + storeUpgrades := storetypes.StoreUpgrades{} + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } } // Name returns the name of the App diff --git a/x/reporter/ante/ante.go b/x/reporter/ante/ante.go index 11316d561..99e89e551 100644 --- a/x/reporter/ante/ante.go +++ b/x/reporter/ante/ante.go @@ -31,8 +31,8 @@ func (t TrackStakeChangesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul var msgAmount math.Int for _, msg := range tx.GetMsgs() { switch msg := msg.(type) { - // case *stakingtypes.MsgCreateValidator: - // msgAmount = msg.Value.Amount + case *stakingtypes.MsgCreateValidator: + msgAmount = msg.Value.Amount case *stakingtypes.MsgDelegate: msgAmount = msg.Amount.Amount case *stakingtypes.MsgBeginRedelegate: diff --git a/x/reporter/ante/ante_test.go b/x/reporter/ante/ante_test.go index 52f921ffd..b28c409f0 100644 --- a/x/reporter/ante/ante_test.go +++ b/x/reporter/ante/ante_test.go @@ -31,20 +31,20 @@ func TestNewTrackStakeChangesDecorator(t *testing.T) { msg sdk.Msg err error }{ - // { - // name: "CreateValidator", - // msg: &stakingtypes.MsgCreateValidator{ - // Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(1)}, - // }, - // err: nil, - // }, - // { - // name: "CreateValidator", - // msg: &stakingtypes.MsgCreateValidator{ - // Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(100)}, - // }, - // err: errors.New("amount increases total stake by more than the allowed 5% in a twelve hour period"), - // }, + { + name: "CreateValidator", + msg: &stakingtypes.MsgCreateValidator{ + Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(1)}, + }, + err: nil, + }, + { + name: "CreateValidator", + msg: &stakingtypes.MsgCreateValidator{ + Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(100)}, + }, + err: errors.New("amount increases total stake by more than the allowed 5% in a twelve hour period"), + }, { name: "Delegate", msg: &stakingtypes.MsgDelegate{