From 3a0ee1cbde9f2ea91a38eeb2b2ba04473a916321 Mon Sep 17 00:00:00 2001 From: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:15:34 -0700 Subject: [PATCH 1/4] fix: payment trigger percentage fix --- x/gmp/types/payment.go | 6 +++++- x/gmp/types/payments_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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) { From 7e8983d0808e993e8c422c56e3c62c3444aa4c2e Mon Sep 17 00:00:00 2001 From: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:17:11 -0700 Subject: [PATCH 2/4] add v0.5.1 upgrade --- app/upgrades.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index e5438e70..aefd03a2 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 @@ -68,7 +69,7 @@ func (app *App) registerUpgrade0_1_4(_ upgradetypes.Plan) { ) } -//nolint: all +// nolint: all func (app *App) registerUpgrade0_2_0(upgradeInfo upgradetypes.Plan) { const planName = "v0.2.0" @@ -358,6 +359,21 @@ func (app *App) registerUpgrade0_5_0(upgradeInfo upgradetypes.Plan) { }) } +func (app *App) registerUpgrade0_5_1(upgradeInfo 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) { From 1ac4091642af93420a2f79fbdc432cfda094fba3 Mon Sep 17 00:00:00 2001 From: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:21:00 -0700 Subject: [PATCH 3/4] lint fix --- app/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index aefd03a2..aa9ad798 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -69,7 +69,7 @@ func (app *App) registerUpgrade0_1_4(_ upgradetypes.Plan) { ) } -// nolint: all +//nolint: all func (app *App) registerUpgrade0_2_0(upgradeInfo upgradetypes.Plan) { const planName = "v0.2.0" From 418a62749454ce0e56e0222973af8a35725c6a70 Mon Sep 17 00:00:00 2001 From: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:40:01 -0700 Subject: [PATCH 4/4] Update app/upgrades.go --- app/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index aa9ad798..bd6737da 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -359,7 +359,7 @@ func (app *App) registerUpgrade0_5_0(upgradeInfo upgradetypes.Plan) { }) } -func (app *App) registerUpgrade0_5_1(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) {