Skip to content

Commit

Permalink
Fix upgrade rate limit config logic, add helpful logs (#1212)
Browse files Browse the repository at this point in the history
* fix upgrade rate limit config bug to correct value

* less aggressive newline
  • Loading branch information
jonfung-dydx authored Mar 20, 2024
1 parent 1249edf commit 9310bb2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions protocol/app/upgrades/v5.0.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ func blockRateLimitConfigUpdate(
clobKeeper clobtypes.ClobKeeper,
) {
oldBlockRateLimitConfig := clobKeeper.GetBlockRateLimitConfiguration(ctx)
ctx.Logger().Info(
fmt.Sprintf(
"Combining the short term order placement and cancellation limits of previous config: %+v\n",
oldBlockRateLimitConfig,
),
)
numAllowedShortTermOrderPlacementsInOneBlock := 0
numAllowedShortTermOrderCancellationsInOneBlock := 0
oldShortTermOrderRateLimits := oldBlockRateLimitConfig.MaxShortTermOrdersPerNBlocks
for _, limit := range oldShortTermOrderRateLimits {
if limit.NumBlocks == 1 {
numAllowedShortTermOrderPlacementsInOneBlock += int(limit.NumBlocks)
numAllowedShortTermOrderPlacementsInOneBlock += int(limit.Limit)
break
}
}
Expand All @@ -55,7 +61,7 @@ func blockRateLimitConfigUpdate(
oldShortTermOrderCancellationRateLimits := oldBlockRateLimitConfig.MaxShortTermOrderCancellationsPerNBlocks
for _, limit := range oldShortTermOrderCancellationRateLimits {
if limit.NumBlocks == 1 {
numAllowedShortTermOrderCancellationsInOneBlock += int(limit.NumBlocks)
numAllowedShortTermOrderCancellationsInOneBlock += int(limit.Limit)
break
}
}
Expand All @@ -77,10 +83,19 @@ func blockRateLimitConfigUpdate(
},
},
}

ctx.Logger().Info(
fmt.Sprintf(
"Attempting to set rate limiting config to newly combined config: %+v\n",
blockRateLimitConfig,
),
)
if err := clobKeeper.InitializeBlockRateLimit(ctx, blockRateLimitConfig); err != nil {
panic(fmt.Sprintf("failed to update the block rate limit configuration: %s", err))
}
ctx.Logger().Info(
"Successfully upgraded block rate limit configuration to: %+v\n",
clobKeeper.GetBlockRateLimitConfiguration(ctx),
)
}

func CreateUpgradeHandler(
Expand Down

0 comments on commit 9310bb2

Please sign in to comment.