From d3e4e2356fb59ffa61069cbe329d94100af78ab9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:21:27 -0400 Subject: [PATCH] use RunCached in vault abci (backport #1954) (#1955) Co-authored-by: Tian --- protocol/x/vault/abci.go | 47 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/protocol/x/vault/abci.go b/protocol/x/vault/abci.go index 4083733d9e..dcbce5d759 100644 --- a/protocol/x/vault/abci.go +++ b/protocol/x/vault/abci.go @@ -4,6 +4,7 @@ import ( "runtime/debug" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dydxprotocol/v4-chain/protocol/lib/abci" "github.com/dydxprotocol/v4-chain/protocol/lib/log" "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper" ) @@ -14,18 +15,17 @@ func BeginBlocker( ) { // Panic is not expected in BeginBlocker, but we should recover instead of // halting the chain. - defer func() { - if r := recover(); r != nil { - log.ErrorLog( - ctx, - "panic in vault BeginBlocker", - "stack", - string(debug.Stack()), - ) - } - }() - - keeper.DecommissionNonPositiveEquityVaults(ctx) + if err := abci.RunCached(ctx, func(ctx sdk.Context) error { + keeper.DecommissionNonPositiveEquityVaults(ctx) + return nil + }); err != nil { + log.ErrorLog( + ctx, + "panic in vault BeginBlocker", + "stack", + string(debug.Stack()), + ) + } } func EndBlocker( @@ -34,16 +34,15 @@ func EndBlocker( ) { // Panic is not expected in EndBlocker, but we should recover instead of // halting the chain. - defer func() { - if r := recover(); r != nil { - log.ErrorLog( - ctx, - "panic in vault EndBlocker", - "stack", - string(debug.Stack()), - ) - } - }() - - keeper.RefreshAllVaultOrders(ctx) + if err := abci.RunCached(ctx, func(ctx sdk.Context) error { + keeper.RefreshAllVaultOrders(ctx) + return nil + }); err != nil { + log.ErrorLog( + ctx, + "panic in vault EndBlocker", + "stack", + string(debug.Stack()), + ) + } }