Skip to content

Commit

Permalink
use RunCached in vault abci (backport #1954) (#1955)
Browse files Browse the repository at this point in the history
Co-authored-by: Tian <[email protected]>
  • Loading branch information
mergify[bot] and tqin7 authored Jul 22, 2024
1 parent 67639e9 commit d3e4e23
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions protocol/x/vault/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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(
Expand All @@ -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()),
)
}
}

0 comments on commit d3e4e23

Please sign in to comment.