Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging at SendMsgs and GetMsgResult #44

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/relay/ethereum/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ethereum

const (
logAttrMsgIndex = "msg_index"
logAttrRevertReason = "revert_reason"
logAttrRawErrorData = "raw_error_data"
logAttrRawTxData = "raw_tx_data"
logAttrTxHash = "tx_hash"
logAttrBlockHash = "block_hash"
logAttrBlockNumber = "block_number"
logAttrTxIndex = "tx_index"
logAttrEstimatedGas = "estimated_gas"
logAttrMaxGasLimit = "max_gas_limit"
)
112 changes: 98 additions & 14 deletions pkg/relay/ethereum/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,127 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) {
opts.NoSend = true
tx, err = c.SendTx(opts, msg, skipUpdateClientCommitment)
if err != nil {
logger.Error("failed to send msg / NoSend: true", err, "msg_index", i)
logger.Error("failed to build tx for gas estimation", err, logAttrMsgIndex, i)
return nil, err
}
var rawTxData string
if bz, err := tx.MarshalBinary(); err != nil {
logger.Error("failed to encode tx", err, logAttrMsgIndex, i)
} else {
rawTxData = hex.EncodeToString(bz)
}
estimatedGas, err := c.client.EstimateGasFromTx(ctx, tx)
if err != nil {
revertReason, rawErrorData, err2 := c.getRevertReasonFromEstimateGas(err)
if err2 != nil {
logger.Error("failed to get revert reason", err2, "msg_index", i)
var revertReason, rawErrorData string
if reason, data, err := c.getRevertReasonFromEstimateGas(err); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siburu We should include raw error data in the log even if the `ErrorRepository's parser function returns an error.

Copy link
Contributor Author

@siburu siburu May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bluele I'm very sorry ... I fixed it.
f0ac44f

// 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,
logAttrMsgIndex, i,
logAttrRawTxData, rawTxData,
)
} else {
revertReason = reason
rawErrorData = hex.EncodeToString(data)
}

logger.Error("failed to estimate gas", err, "revert_reason", revertReason, "raw_error_data", hex.EncodeToString(rawErrorData), "msg_index", i)
logger.Error("failed to estimate gas", err,
logAttrRevertReason, revertReason,
logAttrRawErrorData, rawErrorData,
logAttrMsgIndex, i,
logAttrRawTxData, rawTxData,
)
return nil, err
}
txGasLimit := estimatedGas * c.Config().GasEstimateRate.Numerator / c.Config().GasEstimateRate.Denominator
if txGasLimit > c.Config().MaxGasLimit {
logger.Warn("estimated gas exceeds max gas limit", "estimated_gas", txGasLimit, "max_gas_limit", c.Config().MaxGasLimit, "msg_index", i)
logger.Warn("estimated gas exceeds max gas limit",
logAttrEstimatedGas, txGasLimit,
logAttrMaxGasLimit, c.Config().MaxGasLimit,
logAttrMsgIndex, i,
logAttrRawTxData, rawTxData,
)
txGasLimit = c.Config().MaxGasLimit
}
opts.GasLimit = txGasLimit
opts.NoSend = false
tx, err = c.SendTx(opts, msg, skipUpdateClientCommitment)
if bz, err := tx.MarshalBinary(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siburu If the tx is nil(and err !=nil) at line 96, doest it cause a nil reference error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bluele I'm very sorry. I have fixed it. 5178fa5

logger.Error("failed to encode tx", err,
logAttrMsgIndex, i,
logAttrTxHash, tx.Hash(),
)
} else {
rawTxData = hex.EncodeToString(bz)
}
if err != nil {
logger.Error("failed to send msg / NoSend: false", err, "msg_index", i)
logger.Error("failed to send msg", err,
logAttrMsgIndex, i,
logAttrTxHash, tx.Hash(),
logAttrRawTxData, rawTxData,
)
return nil, err
}
receipt, err := c.client.WaitForReceiptAndGet(ctx, tx.Hash())
if err != nil {
logger.Error("failed to get receipt", err, "msg_index", i, "tx_hash", tx.Hash())
logger.Error("failed to get receipt", err,
logAttrMsgIndex, i,
logAttrTxHash, tx.Hash(),
logAttrRawTxData, rawTxData,
)
return nil, err
}
if receipt.Status == gethtypes.ReceiptStatusFailed {
revertReason, rawErrorData, err2 := c.getRevertReasonFromReceipt(ctx, receipt)
if err2 != nil {
logger.Error("failed to get revert reason", err2, "msg_index", i, "tx_hash", tx.Hash())
var revertReason, rawErrorData string
if reason, data, 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,
logAttrMsgIndex, i,
logAttrTxHash, tx.Hash(),
logAttrRawTxData, rawTxData,
logAttrBlockHash, receipt.BlockHash.Hex(),
logAttrBlockNumber, receipt.BlockNumber.Uint64(),
logAttrTxIndex, receipt.TransactionIndex,
)
} else {
revertReason = reason
rawErrorData = hex.EncodeToString(data)
}

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, "revert_reason", revertReason, "raw_error_data", hex.EncodeToString(rawErrorData), "msg_index", i, "tx_hash", tx.Hash())
logger.Error("tx execution reverted", err,
logAttrRevertReason, revertReason,
logAttrRawErrorData, rawErrorData,
logAttrMsgIndex, i,
logAttrTxHash, tx.Hash(),
logAttrRawTxData, rawTxData,
logAttrBlockHash, receipt.BlockHash.Hex(),
logAttrBlockNumber, receipt.BlockNumber.Uint64(),
logAttrTxIndex, receipt.TransactionIndex,
)
return nil, err
}
logger.Info("successfully sent tx",
logAttrMsgIndex, i,
logAttrTxHash, tx.Hash(),
logAttrRawTxData, rawTxData,
logAttrBlockHash, receipt.BlockHash.Hex(),
logAttrBlockNumber, receipt.BlockNumber.Uint64(),
logAttrTxIndex, receipt.TransactionIndex,
)
if c.msgEventListener != nil {
if err := c.msgEventListener.OnSentMsg([]sdk.Msg{msg}); err != nil {
logger.Error("failed to OnSendMsg call", err, "msg_index", i, "tx_hash", tx.Hash())
logger.Error("failed to OnSendMsg call", err,
logAttrMsgIndex, i,
logAttrTxHash, tx.Hash(),
logAttrRawTxData, rawTxData,
logAttrBlockHash, receipt.BlockHash.Hex(),
logAttrBlockNumber, receipt.BlockNumber.Uint64(),
logAttrTxIndex, receipt.TransactionIndex,
)
}
}
msgIDs = append(msgIDs, NewMsgID(tx.Hash()))
Expand All @@ -116,7 +194,13 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) {
}
revertReason, rawErrorData, err := c.getRevertReasonFromReceipt(ctx, receipt)
if err != nil {
logger.Error("failed to get revert reason", err, "raw_error_data", hex.EncodeToString(rawErrorData), "tx_hash", msgID.TxHashHex)
logger.Error("failed to get revert reason", err,
logAttrRawErrorData, hex.EncodeToString(rawErrorData),
logAttrTxHash, msgID.TxHashHex,
logAttrBlockHash, receipt.BlockHash.Hex(),
logAttrBlockNumber, receipt.BlockNumber.Uint64(),
logAttrTxIndex, receipt.TransactionIndex,
)
}
return c.makeMsgResultFromReceipt(&receipt.Receipt, revertReason)
}
Expand Down