Skip to content

Commit

Permalink
fix: payment trigger percentage & 0.5.1 update (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamewozniak authored Oct 7, 2024
1 parent 8c842d9 commit 602c1c6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion x/gmp/types/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions x/gmp/types/payments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 602c1c6

Please sign in to comment.