diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index d045efda0a..9576bcfe32 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -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("aborted due to an internal error", err.Error()) + config.CCTX.SetAbort("internal error", err.Error()) return types.CctxStatus_Aborted, err } commit() diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go index 377117dfef..fc247ad7a4 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm.go +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -29,7 +29,7 @@ func (c CCTXGatewayZEVM) InitiateOutbound( if err != nil && !isContractReverted { // exceptional case; internal error; should abort CCTX config.CCTX.SetAbort( - "aborted because of an error during deposit that is not smart contract revert", + "error during deposit that is not smart contract revert", err.Error()) return types.CctxStatus_Aborted, err } diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_outbound.go b/x/crosschain/keeper/cctx_orchestrator_validate_outbound.go index 9fce366028..2f3acdd744 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_outbound.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_outbound.go @@ -54,8 +54,8 @@ func (k Keeper) ValidateOutboundZEVM( ) if err != nil { cctx.SetAbort( - "aborted because revert failed", - fmt.Sprintf("deposit error: %s, processing error: %s", depositErr, err.Error())) + "revert failed", + fmt.Sprintf("deposit error: %s, processing error: %s", depositErr.Error(), err.Error())) return types.CctxStatus_Aborted } diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go index 63ce40f335..5aa70be3bd 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go @@ -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.UpdateStatusAndErrorMessages(test.NonErrStatus, false, test.Msg, "") + test.Status.UpdateStatusAndErrorMessages(test.NonErrStatus, test.Msg, "") if test.IsErr { require.Equal(t, test.ErrStatus, test.Status.Status) } else { diff --git a/x/crosschain/types/cctx.go b/x/crosschain/types/cctx.go index ad503a1d0a..91004511d4 100644 --- a/x/crosschain/types/cctx.go +++ b/x/crosschain/types/cctx.go @@ -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.UpdateStatusAndErrorMessages(CctxStatus_Aborted, true, statusMsg, errorMsg) + m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_Aborted, statusMsg, errorMsg) } // SetPendingRevert sets the CCTX status to PendingRevert with the given error message. func (m CrossChainTx) SetPendingRevert(statusMsg, errorMsg string) { - m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_PendingRevert, true, statusMsg, errorMsg) + m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_PendingRevert, statusMsg, errorMsg) } // SetPendingOutbound sets the CCTX status to PendingOutbound with the given error message. func (m CrossChainTx) SetPendingOutbound(statusMsg string) { - m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_PendingOutbound, false, statusMsg, "") + m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_PendingOutbound, statusMsg, "") } // SetOutboundMined sets the CCTX status to OutboundMined with the given error message. func (m CrossChainTx) SetOutboundMined(statusMsg string) { - m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_OutboundMined, false, statusMsg, "") + m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_OutboundMined, statusMsg, "") } // SetReverted sets the CCTX status to Reverted with the given error message. func (m CrossChainTx) SetReverted(statusMsg, errorMsg string) { - m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_Reverted, true, statusMsg, errorMsg) + m.CctxStatus.UpdateStatusAndErrorMessages(CctxStatus_Reverted, statusMsg, errorMsg) } func (m CrossChainTx) GetCCTXIndexBytes() ([32]byte, error) { diff --git a/x/crosschain/types/status.go b/x/crosschain/types/status.go index 74bd4d7ec1..00c08bf6f7 100644 --- a/x/crosschain/types/status.go +++ b/x/crosschain/types/status.go @@ -10,14 +10,20 @@ func (m *Status) AbortRefunded() { } // UpdateStatusAndErrorMessages transitions the Status and Error messages. -func (m *Status) UpdateStatusAndErrorMessages(newStatus CctxStatus, isError bool, statusMsg, errorMsg string) { +func (m *Status) UpdateStatusAndErrorMessages(newStatus CctxStatus, statusMsg, errorMsg string) { m.UpdateStatus(newStatus, statusMsg) - m.UpdateErrorMessage(isError, errorMsg) + + if newStatus == CctxStatus_Aborted || newStatus == CctxStatus_Reverted || newStatus == CctxStatus_PendingRevert { + m.UpdateErrorMessage(errorMsg) + } } // UpdateStatus updates the cctx status and cctx.status.status_message. func (m *Status) UpdateStatus(newStatus CctxStatus, statusMsg string) { - if !m.ValidateTransition(newStatus) { + if m.ValidateTransition(newStatus) { + m.StatusMessage = fmt.Sprintf("Status changed from %s to %s", m.Status.String(), newStatus.String()) + m.Status = newStatus + } else { m.StatusMessage = fmt.Sprintf( "Failed to transition status from %s to %s", m.Status.String(), @@ -25,25 +31,17 @@ func (m *Status) UpdateStatus(newStatus CctxStatus, statusMsg string) { ) m.Status = CctxStatus_Aborted - return } - m.StatusMessage = fmt.Sprintf("Status changed from %s to %s", m.Status.String(), newStatus.String()) - if statusMsg != "" { m.StatusMessage += fmt.Sprintf(": %s", statusMsg) } - - m.Status = newStatus } // UpdateErrorMessage updates cctx.status.error_message. -func (m *Status) UpdateErrorMessage(isError bool, errorMsg string) { - if !isError { - return - } - +func (m *Status) UpdateErrorMessage(errorMsg string) { errMsg := errorMsg + if errMsg == "" { errMsg = "unknown error" } diff --git a/x/crosschain/types/status_test.go b/x/crosschain/types/status_test.go index 4650d4d3d1..5bb272d522 100644 --- a/x/crosschain/types/status_test.go +++ b/x/crosschain/types/status_test.go @@ -166,7 +166,7 @@ func TestStatus_ChangeStatus(t *testing.T) { assert.Equal( t, fmt.Sprintf( - "Failed to transition status from %s to %s", + "Failed to transition status from %s to %s: msg", types.CctxStatus_PendingOutbound.String(), types.CctxStatus_PendingInbound.String(), ),