-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: cctx validate inbound (#2340)
- Loading branch information
Showing
21 changed files
with
229 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/zeta-chain/zetacore/pkg/chains" | ||
"github.com/zeta-chain/zetacore/x/crosschain/types" | ||
) | ||
|
||
// CCTXGateway is interface implemented by every gateway. It is one of interfaces used for communication | ||
// between CCTX gateways and crosschain module, and it is called by crosschain module. | ||
type CCTXGateway interface { | ||
// Initiate a new outbound, this tells the CCTXGateway to carry out the action to execute the outbound. | ||
// It is the only entry point to initiate an outbound and it returns new CCTX status after it is completed. | ||
InitiateOutbound(ctx sdk.Context, config InitiateOutboundConfig) (newCCTXStatus types.CctxStatus, err error) | ||
} | ||
|
||
var cctxGateways map[chains.CCTXGateway]CCTXGateway | ||
|
||
// ResolveCCTXGateway respolves cctx gateway implementation based on provided cctx gateway | ||
func ResolveCCTXGateway(c chains.CCTXGateway, keeper Keeper) (CCTXGateway, bool) { | ||
cctxGateways = map[chains.CCTXGateway]CCTXGateway{ | ||
chains.CCTXGateway_observers: NewCCTXGatewayObservers(keeper), | ||
chains.CCTXGateway_zevm: NewCCTXGatewayZEVM(keeper), | ||
} | ||
|
||
cctxGateway, ok := cctxGateways[c] | ||
return cctxGateway, ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/zeta-chain/zetacore/x/crosschain/types" | ||
observertypes "github.com/zeta-chain/zetacore/x/observer/types" | ||
) | ||
|
||
// ValidateInbound is the only entry-point to create new CCTX (eg. when observers voting is done or new inbound event is detected). | ||
// It creates new CCTX object and calls InitiateOutbound method. | ||
func (k Keeper) ValidateInbound( | ||
ctx sdk.Context, | ||
msg *types.MsgVoteInbound, | ||
shouldPayGas bool, | ||
) (*types.CrossChainTx, error) { | ||
tss, tssFound := k.zetaObserverKeeper.GetTSS(ctx) | ||
if !tssFound { | ||
return nil, types.ErrCannotFindTSSKeys | ||
} | ||
|
||
// Do not process if inbound is disabled | ||
if !k.zetaObserverKeeper.IsInboundEnabled(ctx) { | ||
return nil, observertypes.ErrInboundDisabled | ||
} | ||
|
||
// 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, InitiateOutboundConfig{ | ||
CCTX: &cctx, | ||
ShouldPayGas: shouldPayGas, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
inCctxIndex, ok := ctx.Value(InCCTXIndexKey).(string) | ||
if ok { | ||
cctx.InboundParams.ObservedHash = inCctxIndex | ||
} | ||
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx) | ||
|
||
return &cctx, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.