From 361fcafceadf6d65df913f833467ec5ac5818d8e Mon Sep 17 00:00:00 2001 From: Charlie Chen <34498985+ws4charlie@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:39:41 -0600 Subject: [PATCH] fix: unprivileged outtx tracker removal (#1533) * unprivileged outtx tracker removal * updated changelog * added extra comment * differentiate API call failure from ErrCannotFindCctx --------- Co-authored-by: Lucas Bertrand --- changelog.md | 1 + .../keeper/msg_server_add_to_outtx_tracker.go | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index a09cc2d5bb..a80e9cdd5a 100644 --- a/changelog.md +++ b/changelog.md @@ -20,6 +20,7 @@ ### Fixes +* [1516](https://github.com/zeta-chain/node/issues/1516) - Unprivileged outtx tracker removal * [1537](https://github.com/zeta-chain/node/issues/1537) - Sanity check events of ZetaSent/ZetaReceived/ZetaRevertedWithdrawn/Deposited * [1530](https://github.com/zeta-chain/node/pull/1530) - Outbound tx confirmation/inclusion enhancement * [1496](https://github.com/zeta-chain/node/issues/1496) - post block header for enabled EVM chains only diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go index 0af5fc9a2b..64f1396859 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker.go @@ -29,6 +29,24 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO return nil, observertypes.ErrSupportedChains } + // the cctx must exist + cctx, err := k.CctxByNonce(ctx, &types.QueryGetCctxByNonceRequest{ + ChainID: msg.ChainId, + Nonce: msg.Nonce, + }) + if err != nil { + return nil, cosmoserrors.Wrap(err, "CcxtByNonce failed") + } + if cctx == nil || cctx.CrossChainTx == nil { + return nil, cosmoserrors.Wrapf(types.ErrCannotFindCctx, "no corresponding cctx found for chain %d, nonce %d", msg.ChainId, msg.Nonce) + } + // tracker submission is only allowed when the cctx is pending + if !IsPending(*cctx.CrossChainTx) { + // garbage tracker (for any reason) is harmful to outTx observation and should be removed + k.RemoveOutTxTracker(ctx, msg.ChainId, msg.Nonce) + return &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, nil + } + if msg.Proof == nil { // without proof, only certain accounts can send this message adminPolicyAccount := k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group1) isAdmin := msg.Creator == adminPolicyAccount @@ -53,18 +71,6 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO isProven = true } - cctx, err := k.CctxByNonce(ctx, &types.QueryGetCctxByNonceRequest{ - ChainID: msg.ChainId, - Nonce: msg.Nonce, - }) - if err != nil || cctx == nil || cctx.CrossChainTx == nil { - return nil, cosmoserrors.Wrap(types.ErrCannotFindCctx, "cannot add out tx: no corresponding cctx found") - } - if !IsPending(*cctx.CrossChainTx) { - k.RemoveOutTxTracker(ctx, msg.ChainId, msg.Nonce) - return &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, nil - } - tracker, found := k.GetOutTxTracker(ctx, msg.ChainId, msg.Nonce) hash := types.TxHashList{ TxHash: msg.TxHash,