Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keeper level panic catches #3312

Merged
merged 3 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#2914](https://github.com/osmosis-labs/osmosis/pull/2914) Remove out of gas panics from node logs
* [#2937](https://github.com/osmosis-labs/osmosis/pull/2937) End block ordering - staking after gov and module sorting.
* [#2923](https://github.com/osmosis-labs/osmosis/pull/2923) TWAP calculation now errors if it uses records that have errored previously.
* [#3312](https://github.com/osmosis-labs/osmosis/pull/3312) Add better panic catches within GAMM txs

### Misc Improvements

Expand Down
28 changes: 26 additions & 2 deletions x/gamm/keeper/pool_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ func (k Keeper) JoinPoolNoSwap(
shareOutAmount sdk.Int,
tokenInMaxs sdk.Coins,
) (tokenIn sdk.Coins, sharesOut sdk.Int, err error) {
// defer to catch panics, in case something internal overflows.
defer func() {
if r := recover(); r != nil {
tokenIn = sdk.Coins{}
sharesOut = sdk.Int{}
err = fmt.Errorf("function JoinPoolNoSwap failed due to internal reason: %v", r)
}
}()
// all pools handled within this method are pointer references, `JoinPool` directly updates the pools
pool, err := k.GetPoolAndPoke(ctx, poolId)
if err != nil {
Expand Down Expand Up @@ -281,13 +289,21 @@ func (k Keeper) JoinSwapExactAmountIn(
poolId uint64,
tokensIn sdk.Coins,
shareOutMinAmount sdk.Int,
) (sdk.Int, error) {
) (sharesOut sdk.Int, err error) {
// defer to catch panics, in case something internal overflows.
defer func() {
if r := recover(); r != nil {
sharesOut = sdk.Int{}
err = fmt.Errorf("function JoinSwapExactAmountIn failed due to internal reason: %v", r)
}
}()

pool, err := k.getPoolForSwap(ctx, poolId)
if err != nil {
return sdk.Int{}, err
}

sharesOut, err := pool.JoinPool(ctx, tokensIn, pool.GetSwapFee(ctx))
sharesOut, err = pool.JoinPool(ctx, tokensIn, pool.GetSwapFee(ctx))
switch {
case err != nil:
return sdk.ZeroInt(), err
Expand Down Expand Up @@ -318,6 +334,14 @@ func (k Keeper) JoinSwapShareAmountOut(
shareOutAmount sdk.Int,
tokenInMaxAmount sdk.Int,
) (tokenInAmount sdk.Int, err error) {
// defer to catch panics, in case something internal overflows.
defer func() {
if r := recover(); r != nil {
tokenInAmount = sdk.Int{}
err = fmt.Errorf("function JoinSwapShareAmountOut failed due to internal reason: %v", r)
}
}()

pool, err := k.getPoolForSwap(ctx, poolId)
if err != nil {
return sdk.Int{}, err
Expand Down