Skip to content

Commit

Permalink
CNS-828: add authz unwrap to dualstaking antehandler
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Jan 23, 2024
1 parent 2d14373 commit 2bda492
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions x/dualstaking/ante/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/x/dualstaking/keeper"
)

Expand All @@ -20,9 +22,40 @@ func NewRedelegationFlager(dualstaking keeper.Keeper) RedelegationFlager {
}

func (rf RedelegationFlager) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
msgs, err := rf.unwrapAuthz(tx)
if err != nil {
return ctx, err
}

err = rf.disableRedelegationHooks(ctx, msgs)
if err != nil {
return ctx, err
}

return next(ctx, tx, simulate)
}

func (rf RedelegationFlager) unwrapAuthz(tx sdk.Tx) ([]sdk.Msg, error) {
var unwrappedMsgs []sdk.Msg
for _, txMsg := range tx.GetMsgs() {
if authzMsg, ok := txMsg.(*authz.MsgExec); ok {
msgs, err := authzMsg.GetMessages()
if err != nil {
return nil, utils.LavaFormatError("could not unwrap authz from msgs", err)
}
unwrappedMsgs = append(unwrappedMsgs, msgs...)
} else {
unwrappedMsgs = append(unwrappedMsgs, txMsg)
}
}

return unwrappedMsgs, nil
}

func (rf RedelegationFlager) disableRedelegationHooks(ctx sdk.Context, msgs []sdk.Msg) error {
redelegations := false
others := false
for _, msg := range tx.GetMsgs() {
for _, msg := range msgs {
if _, ok := msg.(*stakingtypes.MsgBeginRedelegate); ok {
redelegations = true
} else {
Expand All @@ -31,10 +64,9 @@ func (rf RedelegationFlager) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo
}

if redelegations && others {
return ctx, fmt.Errorf("cannot send batch requests with redelegation messages")
return utils.LavaFormatWarning("could not disable redelegation hooks", fmt.Errorf("cannot send batch requests with redelegation messages"))
}

keeper.DisableDualstakingHook = redelegations

return next(ctx, tx, simulate)
return nil
}

0 comments on commit 2bda492

Please sign in to comment.