Skip to content

Commit

Permalink
add query to get cctx error message
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Oct 3, 2024
1 parent 8758f27 commit 4d7b1aa
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion e2e/e2etests/test_eth_deposit_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) {
r.Logger.Info("Cross-chain call to reverter reverted")

// Check the error carries the revert executed.
require.Contains(r, cctx.CctxStatus.ErrorMessage, "revert executed")
require.Contains(r, cctx.CctxStatus.ErrorMessage, "Revert executed")
}
2 changes: 1 addition & 1 deletion e2e/e2etests/test_solana_deposit_refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func TestSolanaDepositAndCallRefund(r *runner.E2ERunner, args []string) {
utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted)

// Check the error carries the revert executed.
require.Contains(r, cctx.CctxStatus.ErrorMessage, "revert executed")
require.Contains(r, cctx.CctxStatus.ErrorMessage, "Revert executed")
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ require (
github.com/bnb-chain/tss-lib v1.5.0
github.com/showa-93/go-mask v0.6.2
github.com/tonkeeper/tongo v1.9.3
gotest.tools v2.2.0+incompatible
)

require (
Expand Down
17 changes: 17 additions & 0 deletions x/crosschain/keeper/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ func (k Keeper) GetCrossChainTx(ctx sdk.Context, index string) (val types.CrossC
return val, true
}

// GetCrossChainTxError returns the error message for a given cctx index.
func (k Keeper) GetCrossChainTxError(ctx sdk.Context, index string) (errMsg string, found bool) {
var cctx types.CrossChainTx

p := types.KeyPrefix(fmt.Sprintf("%s", types.CCTXKey))
store := prefix.NewStore(ctx.KVStore(k.storeKey), p)

b := store.Get(types.KeyPrefix(index))
if b == nil {
return "", false
}

k.cdc.MustUnmarshal(b, &cctx)

return cctx.CctxStatus.ErrorMessage, true
}

// GetAllCrossChainTx returns all cctxs
func (k Keeper) GetAllCrossChainTx(ctx sdk.Context) (list []types.CrossChainTx) {
p := types.KeyPrefix(fmt.Sprintf("%s", types.CCTXKey))
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/cctx_gateway_observers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c CCTXGatewayObservers) InitiateOutbound(
}()
if err != nil {
// do not commit anything here as the CCTX should be aborted
config.CCTX.SetAbort("", err.Error())
config.CCTX.SetAbort("Aborted due to an internal error", err.Error())
return types.CctxStatus_Aborted, err
}
commit()
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/cctx_gateway_zevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c CCTXGatewayZEVM) InitiateOutbound(

if err != nil && !isContractReverted {
// exceptional case; internal error; should abort CCTX
config.CCTX.SetAbort("", err.Error())
config.CCTX.SetAbort("Aborted while trying to handle EVM deposit", err.Error())
return types.CctxStatus_Aborted, err
}

Expand Down
22 changes: 12 additions & 10 deletions x/crosschain/keeper/cctx_orchestrator_validate_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func (k Keeper) ValidateOutboundZEVM(
cctx.InboundParams.Amount,
)
if err != nil {
cctx.SetAbort("", fmt.Sprintf("deposit error %s, got error: %s", depositErr, err.Error()))
cctx.SetAbort(
"Aborted because an error was raised while trying to revert cctx",
fmt.Sprintf("Deposit error: %s, Processing error: %s", depositErr, err.Error()))
return types.CctxStatus_Aborted
}

Expand Down Expand Up @@ -122,7 +124,7 @@ func (k Keeper) processFailedOutboundObservers(ctx sdk.Context, cctx *types.Cros
if cctx.InboundParams.CoinType == coin.CoinType_Cmd {
// if the cctx is of coin type cmd or the sender chain is zeta chain, then we do not revert, the cctx is aborted
cctx.GetCurrentOutboundParam().TxFinalizationStatus = types.TxFinalizationStatus_Executed
cctx.SetAbort("", "outbound failed, cmd cctx reverted")
cctx.SetAbort("", "Outbound failed for admin tx")
} else if chains.IsZetaChain(cctx.InboundParams.SenderChainId, k.GetAuthorityKeeper().GetAdditionalChainList(ctx)) {
switch cctx.InboundParams.CoinType {
// Try revert if the coin-type is ZETA
Expand All @@ -137,7 +139,7 @@ func (k Keeper) processFailedOutboundObservers(ctx sdk.Context, cctx *types.Cros
default:
{
cctx.GetCurrentOutboundParam().TxFinalizationStatus = types.TxFinalizationStatus_Executed
cctx.SetAbort("", "outbound failed for non-ZETA cctx")
cctx.SetAbort("", "Outbound failed for non-ZETA cctx")
}
}
} else {
Expand Down Expand Up @@ -198,7 +200,7 @@ func (k Keeper) processFailedOutboundOnExternalChain(
cctx.SetPendingRevert("", revertMsg)
case types.CctxStatus_PendingRevert:
cctx.GetCurrentOutboundParam().TxFinalizationStatus = types.TxFinalizationStatus_Executed
cctx.SetAbort("", "outbound and revert failed")
cctx.SetAbort("Aborted while processing failed outbound", "Outbound and revert failed")
}
return nil
}
Expand All @@ -225,7 +227,7 @@ func (k Keeper) processSuccessfulOutbound(
oldStatus := cctx.CctxStatus.Status
switch oldStatus {
case types.CctxStatus_PendingRevert:
cctx.SetReverted("", "revert executed")
cctx.SetReverted("Reverted as part of a successful outbound", "Revert executed")
case types.CctxStatus_PendingOutbound:
cctx.SetOutboundMined("")
default:
Expand Down Expand Up @@ -256,7 +258,7 @@ func (k Keeper) processFailedZETAOutboundOnZEVM(ctx sdk.Context, cctx *types.Cro
}

// Trying to revert the transaction this would get set to a finalized status in the same block as this does not need a TSS singing
cctx.SetPendingRevert("", "outbound failed")
cctx.SetPendingRevert("", "Outbound failed")
data, err := base64.StdEncoding.DecodeString(cctx.RelayedMessage)
if err != nil {
return fmt.Errorf("failed decoding relayed message: %s", err.Error())
Expand Down Expand Up @@ -290,7 +292,7 @@ func (k Keeper) processFailedZETAOutboundOnZEVM(ctx sdk.Context, cctx *types.Cro
return fmt.Errorf("failed ZETARevertAndCallContract: %s", err.Error())
}

cctx.SetReverted("", "outbound failed")
cctx.SetReverted("", "Outbound failed")
if len(ctx.TxBytes()) > 0 {
// add event for tendermint transaction hash format
hash := tmbytes.HexBytes(tmtypes.Tx(ctx.TxBytes()).Hash())
Expand Down Expand Up @@ -336,7 +338,7 @@ func (k Keeper) processFailedOutboundV2(ctx sdk.Context, cctx *types.CrossChainT
}

// update status
cctx.SetPendingRevert("", "outbound failed")
cctx.SetPendingRevert("", "Outbound failed")

Check warning on line 341 in x/crosschain/keeper/cctx_orchestrator_validate_outbound.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/cctx_orchestrator_validate_outbound.go#L341

Added line #L341 was not covered by tests

// process the revert on ZEVM
if err := k.fungibleKeeper.ProcessV2RevertDeposit(
Expand All @@ -354,7 +356,7 @@ func (k Keeper) processFailedOutboundV2(ctx sdk.Context, cctx *types.CrossChainT
}

// tx is reverted
cctx.SetReverted("", "outbound failed")
cctx.SetReverted("", "Outbound failed")

Check warning on line 359 in x/crosschain/keeper/cctx_orchestrator_validate_outbound.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/cctx_orchestrator_validate_outbound.go#L359

Added line #L359 was not covered by tests

// add event for tendermint transaction hash format
if len(ctx.TxBytes()) > 0 {
Expand All @@ -367,7 +369,7 @@ func (k Keeper) processFailedOutboundV2(ctx sdk.Context, cctx *types.CrossChainT
cctx.GetCurrentOutboundParam().TxFinalizationStatus = types.TxFinalizationStatus_Executed
case types.CctxStatus_PendingRevert:
cctx.GetCurrentOutboundParam().TxFinalizationStatus = types.TxFinalizationStatus_Executed
cctx.SetAbort("", "outbound and revert failed")
cctx.SetAbort("Aborted while processing failed outbound", "Outbound and revert failed")

Check warning on line 372 in x/crosschain/keeper/cctx_orchestrator_validate_outbound.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/cctx_orchestrator_validate_outbound.go#L372

Added line #L372 was not covered by tests
}
return nil
}
7 changes: 6 additions & 1 deletion x/crosschain/keeper/cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ func TestCCTXs(t *testing.T) {
send, found := keeper.GetCrossChainTx(ctx, s.Index)
require.True(t, found)
require.Equal(t, s, send)
err, found := keeper.GetCrossChainTxError(ctx, s.Index)
require.True(t, found)
require.Equal(t, "", err)
}

err, found := keeper.GetCrossChainTxError(ctx, "does-not-exist")
require.False(t, found)
require.Equal(t, "", err)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/msg_server_vote_inbound_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func TestStatus_UpdateCctxStatus(t *testing.T) {
for _, test := range tt {
test := test
t.Run(test.Name, func(t *testing.T) {
test.Status.UpdateCctxMessages(test.NonErrStatus, false, test.Msg, "")
test.Status.UpdateStatusAndErrorMessages(test.NonErrStatus, false, test.Msg, "")
if test.IsErr {
require.Equal(t, test.ErrStatus, test.Status.Status)
} else {
Expand Down
10 changes: 5 additions & 5 deletions x/crosschain/types/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,27 @@ func (m *CrossChainTx) AddOutbound(

// SetAbort sets the CCTX status to Aborted with the given error message.
func (m CrossChainTx) SetAbort(statusMsg, errorMsg string) {
m.CctxStatus.UpdateCctxMessages(CctxStatus_Aborted, true, statusMsg, errorMsg)
m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_Aborted, true, statusMsg, errorMsg)
}

// SetPendingRevert sets the CCTX status to PendingRevert with the given error message.
func (m CrossChainTx) SetPendingRevert(statusMsg, errorMsg string) {
m.CctxStatus.UpdateCctxMessages(CctxStatus_PendingRevert, true, statusMsg, errorMsg)
m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_PendingRevert, true, statusMsg, errorMsg)
}

// SetPendingOutbound sets the CCTX status to PendingOutbound with the given error message.
func (m CrossChainTx) SetPendingOutbound(statusMsg string) {
m.CctxStatus.UpdateCctxMessages(CctxStatus_PendingOutbound, false, statusMsg, "")
m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_PendingOutbound, false, statusMsg, "")
}

// SetOutboundMined sets the CCTX status to OutboundMined with the given error message.
func (m CrossChainTx) SetOutboundMined(statusMsg string) {
m.CctxStatus.UpdateCctxMessages(CctxStatus_OutboundMined, false, statusMsg, "")
m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_OutboundMined, false, statusMsg, "")
}

// SetReverted sets the CCTX status to Reverted with the given error message.
func (m CrossChainTx) SetReverted(statusMsg, errorMsg string) {
m.CctxStatus.UpdateCctxMessages(CctxStatus_Reverted, true, statusMsg, errorMsg)
m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_Reverted, true, statusMsg, errorMsg)
}

func (m CrossChainTx) GetCCTXIndexBytes() ([32]byte, error) {
Expand Down
10 changes: 5 additions & 5 deletions x/crosschain/types/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ func (m *Status) AbortRefunded() {
m.StatusMessage = "CCTX aborted and Refunded"
}

// UpdateCctxMessages transitions the Status and Error messages.
func (m *Status) UpdateCctxMessages(newStatus CctxStatus, isError bool, statusMsg, errorMsg string) {
m.UpdateStatusMessage(newStatus, statusMsg)
// UpdateStatusAndErrorMessages transitions the Status and Error messages.
func (m *Status) UpdateStatusAndErrorMessages(newStatus CctxStatus, isError bool, statusMsg, errorMsg string) {
m.UpdateStatus(newStatus, statusMsg)
m.UpdateErrorMessage(isError, errorMsg)
}

// UpdateStatusMessage updates the cctx status and cctx.status.status_message.
func (m *Status) UpdateStatusMessage(newStatus CctxStatus, statusMsg string) {
// UpdateStatus updates the cctx status and cctx.status.status_message.
func (m *Status) UpdateStatus(newStatus CctxStatus, statusMsg string) {
if !m.ValidateTransition(newStatus) {
m.StatusMessage = fmt.Sprintf(
"Failed to transition status from %s to %s",
Expand Down
8 changes: 4 additions & 4 deletions x/crosschain/types/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/assert"

"github.com/zeta-chain/node/x/crosschain/types"
)
Expand Down Expand Up @@ -140,15 +140,15 @@ func TestStatus_ChangeStatus(t *testing.T) {
t.Run("should change status and msg if transition is valid", func(t *testing.T) {
s := types.Status{Status: types.CctxStatus_PendingInbound}

s.UpdateStatusMessage(types.CctxStatus_PendingOutbound, "msg")
s.UpdateStatus(types.CctxStatus_PendingOutbound, "msg")
assert.Equal(t, s.Status, types.CctxStatus_PendingOutbound)
assert.Equal(t, s.StatusMessage, "Status changed from PendingInbound to PendingOutbound: msg")
})

t.Run("should change status if transition is valid", func(t *testing.T) {
s := types.Status{Status: types.CctxStatus_PendingInbound}

s.UpdateStatusMessage(types.CctxStatus_PendingOutbound, "")
s.UpdateStatus(types.CctxStatus_PendingOutbound, "")
fmt.Printf("%+v\n", s)
assert.Equal(t, s.Status, types.CctxStatus_PendingOutbound)
assert.Equal(t, s.StatusMessage, fmt.Sprintf(
Expand All @@ -161,7 +161,7 @@ func TestStatus_ChangeStatus(t *testing.T) {
t.Run("should change status to aborted and msg if transition is invalid", func(t *testing.T) {
s := types.Status{Status: types.CctxStatus_PendingOutbound}

s.UpdateStatusMessage(types.CctxStatus_PendingInbound, "msg")
s.UpdateStatus(types.CctxStatus_PendingInbound, "msg")
assert.Equal(t, s.Status, types.CctxStatus_Aborted)
assert.Equal(
t,
Expand Down

0 comments on commit 4d7b1aa

Please sign in to comment.