-
Notifications
You must be signed in to change notification settings - Fork 14
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
+103
−34
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5152347
improve logging at SendMsgs and GetMsgResult
siburu f0ac44f
output raw error data in error logs even if revert reason isn't avail…
siburu 5178fa5
marshal tx for logging only when SendTx succeeds
siburu 744dcb9
use slog.Logger.With for cleaning up logging code in SendMsgs
siburu a30383b
add "msg_type" log attribute in SendMsgs
siburu 71c6368
avoid outputing an empty string as "revert_reason" to error logs
siburu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
// 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @siburu If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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())) | ||
|
@@ -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) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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