Skip to content

Commit

Permalink
move validate inbound for observers logic to separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jun 10, 2024
1 parent 16f858f commit 59c6d5f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
26 changes: 26 additions & 0 deletions x/crosschain/keeper/cctx_orchestrator_validate_inbound.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func (k Keeper) ValidateInboundObservers(ctx sdk.Context, msg *types.MsgVoteInbound) (*types.CrossChainTx, error) {
tss, tssFound := k.zetaObserverKeeper.GetTSS(ctx)
if !tssFound {
return nil, types.ErrCannotFindTSSKeys
}
// create a new CCTX from the inbound message.The status of the new CCTX is set to PendingInbound.
cctx, err := types.NewCCTX(ctx, *msg, tss.TssPubkey)
if err != nil {
return nil, err
}
// Initiate outbound, the process function manages the state commit and cctx status change.
// If the process fails, the changes to the evm state are rolled back.
_, err = k.InitiateOutbound(ctx, &cctx)
if err != nil {
return nil, err
}

return &cctx, nil
}
17 changes: 4 additions & 13 deletions x/crosschain/keeper/msg_server_vote_inbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,14 @@ func (k msgServer) VoteInbound(
if !finalized {
return &types.MsgVoteInboundResponse{}, nil
}
tss, tssFound := k.zetaObserverKeeper.GetTSS(ctx)
if !tssFound {
return nil, types.ErrCannotFindTSSKeys
}
// create a new CCTX from the inbound message.The status of the new CCTX is set to PendingInbound.
cctx, err := types.NewCCTX(ctx, *msg, tss.TssPubkey)
if err != nil {
return nil, err
}
// Initiate outbound, the process function manages the state commit and cctx status change.
// If the process fails, the changes to the evm state are rolled back.
_, err = k.InitiateOutbound(ctx, &cctx)

cctx, err := k.ValidateInboundObservers(ctx, msg)
if err != nil {
return nil, err
}

// Save the inbound CCTX to the store. This is called irrespective of the status of the CCTX or the outcome of the process function.
k.SaveInbound(ctx, &cctx, msg.EventIndex)
k.SaveInbound(ctx, cctx, msg.EventIndex)
return &types.MsgVoteInboundResponse{}, nil
}

Expand Down

0 comments on commit 59c6d5f

Please sign in to comment.