Skip to content

Commit

Permalink
avoid outputing an empty string as "revert_reason" to error logs
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed May 26, 2024
1 parent a30383b commit 71c6368
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions pkg/relay/ethereum/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,18 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) {

estimatedGas, err := c.client.EstimateGasFromTx(ctx, tx)
if err != nil {
var revertReason, rawErrorData string
if reason, data, err := c.getRevertReasonFromEstimateGas(err); err != nil {
if revertReason, rawErrorData, err := c.getRevertReasonFromEstimateGas(err); err != nil {
// Raw error data may be available even if revert reason isn't available.
rawErrorData = hex.EncodeToString(data)
logger.Error("failed to get revert reason", err,
logAttrRawErrorData, rawErrorData,
)
logger.Logger = logger.With(logAttrRawErrorData, hex.EncodeToString(rawErrorData))
logger.Error("failed to get revert reason", err)
} else {
revertReason = reason
rawErrorData = hex.EncodeToString(data)
logger.Logger = logger.With(
logAttrRawErrorData, hex.EncodeToString(rawErrorData),
logAttrRevertReason, revertReason,
)
}

logger.Error("failed to estimate gas", err,
logAttrRevertReason, revertReason,
logAttrRawErrorData, rawErrorData,
)
logger.Error("failed to estimate gas", err)
return nil, err
}

Expand Down Expand Up @@ -124,23 +120,19 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) {
}

if receipt.Status == gethtypes.ReceiptStatusFailed {
var revertReason, rawErrorData string
if reason, data, err := c.getRevertReasonFromReceipt(ctx, receipt); err != nil {
if revertReason, rawErrorData, err := c.getRevertReasonFromReceipt(ctx, receipt); err != nil {
// Raw error data may be available even if revert reason isn't available.
rawErrorData = hex.EncodeToString(data)
logger.Error("failed to get revert reason", err,
logAttrRawErrorData, rawErrorData,
)
logger.Logger = logger.With(logAttrRawErrorData, hex.EncodeToString(rawErrorData))
logger.Error("failed to get revert reason", err)
} else {
revertReason = reason
rawErrorData = hex.EncodeToString(data)
logger.Logger = logger.With(
logAttrRawErrorData, hex.EncodeToString(rawErrorData),
logAttrRevertReason, revertReason,
)
}

err := fmt.Errorf("tx execution reverted: revertReason=%s, rawErrorData=%x, msgIndex=%d, txHash=%s", revertReason, rawErrorData, i, tx.Hash())
logger.Error("tx execution reverted", err,
logAttrRevertReason, revertReason,
logAttrRawErrorData, rawErrorData,
)
err := errors.New("tx execution reverted")
logger.Error("tx execution reverted", err)
return nil, err
}
logger.Info("successfully sent tx")
Expand Down

0 comments on commit 71c6368

Please sign in to comment.