Skip to content

Commit

Permalink
applied suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Oct 7, 2024
1 parent 21ca074 commit 93f1789
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
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("aborted due to an internal error", err.Error())
config.CCTX.SetAbort("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 @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/cctx_orchestrator_validate_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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.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 {
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.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) {
Expand Down
24 changes: 11 additions & 13 deletions x/crosschain/types/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,38 @@ 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(),
newStatus.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"
}
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
Expand Down

0 comments on commit 93f1789

Please sign in to comment.