diff --git a/app/upgrades.go b/app/upgrades.go index e5438e70..bd6737da 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -49,6 +49,7 @@ func (app App) RegisterUpgradeHandlers() { app.registerUpgrade0_4_0(upgradeInfo) app.registerUpgrade0_4_1(upgradeInfo) app.registerUpgrade0_5_0(upgradeInfo) + app.registerUpgrade0_5_1(upgradeInfo) } // performs upgrade from v0.1.3 to v0.1.4 @@ -358,6 +359,21 @@ func (app *App) registerUpgrade0_5_0(upgradeInfo upgradetypes.Plan) { }) } +func (app *App) registerUpgrade0_5_1(_ upgradetypes.Plan) { + const planName = "v0.5.1" + app.UpgradeKeeper.SetUpgradeHandler(planName, + func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.Logger().Info("Upgrade handler execution", "name", planName) + + params := app.GasEstimateKeeper.GetParams(sdkCtx) + params.GasAdjustment = "0.35" + app.GasEstimateKeeper.SetParams(sdkCtx, params) + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) +} + // helper function to check if the store loader should be upgraded func (app *App) storeUpgrade(planName string, ui upgradetypes.Plan, stores storetypes.StoreUpgrades) { if ui.Name == planName && !app.UpgradeKeeper.IsSkipHeight(ui.Height) { diff --git a/x/gmp/types/payment.go b/x/gmp/types/payment.go index c90ce770..b1651d60 100644 --- a/x/gmp/types/payment.go +++ b/x/gmp/types/payment.go @@ -6,6 +6,10 @@ import ( ) func (p Payment) TriggerUpdate(rate math.LegacyDec, ctx sdk.Context) bool { - return p.LastPrice.Sub(rate).Abs().GT(p.Deviation) || + // Calculate the percentage difference + priceDiff := p.LastPrice.Sub(rate).Abs() + percentageDiff := priceDiff.Quo(p.LastPrice).MulInt64(100) + + return percentageDiff.GT(p.Deviation) || p.LastBlock < ctx.BlockHeight()-p.Heartbeat } diff --git a/x/gmp/types/payments_test.go b/x/gmp/types/payments_test.go index d9f611d3..e3296d74 100644 --- a/x/gmp/types/payments_test.go +++ b/x/gmp/types/payments_test.go @@ -52,6 +52,19 @@ func TestPayment_TriggerUpdate(t *testing.T) { ctx: sdk.Context{}.WithBlockHeight(102), want: true, }, + + { + name: "should not trigger update - deviation within threshol", + payment: Payment{ + LastPrice: math.LegacyMustNewDecFromStr("200"), + Deviation: math.LegacyMustNewDecFromStr("1"), + Heartbeat: 100, + LastBlock: 100, + }, + rate: math.LegacyMustNewDecFromStr("202"), + ctx: sdk.Context{}.WithBlockHeight(101), + want: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {