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

[CORE-708] Explicitly log out delayed message when execution fails #687

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

teddyding
Copy link
Contributor

@teddyding teddyding commented Oct 23, 2023

Changelist

  • Explicitly log out message content and typeurl when message execution fails during dispatching. Action item from here
  • Also add e2e test case where delayed MsgCompleteBridge fails to execute

Test Plan

Added e2e test where a BridgeEvent contains 0adv4tnt transfer. The error log shows up as following:

E[2023-10-23|20:23:32.382] failed to execute delayed message            module=x/delaymsg id=1 error="0adv4tnt: invalid coins" message_content="authority:\"dydx1mkkvp26dngu6n8rmalaxyp3gwkjuzztq5zx6tr\" event:<coin:<denom:\"adv4tnt\" amount:\"0\" > address:\"dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4\" > " message_type_url=/dydxprotocol.bridge.MsgCompleteBridge

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2023

Walkthrough

The changes primarily focus on enhancing the logging capabilities in the delaymsg module and adding a new test case in the bridge module. The logging enhancements provide more context when a delayed message fails to execute. The new test case checks the successful execution of a bridge event with zero coin amount and a delay of 5 blocks.

Changes

File Summary
protocol/x/delaymsg/keeper/dispatch.go Improved error logging in the DispatchMessagesForBlock function by including additional information such as the delayed message content and type URL.
protocol/x/delaymsg/types/keys.go and protocol/x/delaymsg/types/logs.go Added new constants for logging keys and removed the IdLogKey constant.
protocol/testutil/constants/bridge.go Introduced new global variables emptyCoin and BridgeEvent_Id4_Height0_EmptyCoin for testing purposes.
protocol/x/bridge/app_test.go Added a new test case for the Bridge_Success function involving a bridge event with zero coin amount and a delay of 5 blocks.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

@teddyding teddyding changed the title [] Explicitly log out message when dispatch fails Explicitly log out delayed message when execution fails Oct 23, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cba238d and 37dcee8.
Files selected for processing (2)
  • protocol/x/delaymsg/keeper/dispatch.go (1 hunks)
  • protocol/x/delaymsg/types/keys.go (1 hunks)
Additional comments: 2
protocol/x/delaymsg/types/keys.go (1)
  • 26-28: The addition of MessageContentLogKey and MessageTypeUrlLogKey is a good move for enhancing the logging capabilities. However, ensure that the values assigned to these constants are not sensitive or private data that should not be logged. Also, consider the size of the message content, as logging large messages could impact performance or storage.
protocol/x/delaymsg/keeper/dispatch.go (1)
  • 54-64: The new logging statement provides more context when a delayed message fails to execute by including the message content and type URL in the error log. This is a good practice as it will help in debugging and troubleshooting. However, be aware that logging the entire message content might include sensitive data. If the messages can contain sensitive data, consider sanitizing or hashing the content before logging.
- k.Logger(ctx).Error("failed to execute delayed message", types.IdLogKey, id, constants.ErrorLogKey, err)
+ k.Logger(ctx).Error(
+    "failed to execute delayed message",
+    types.IdLogKey,
+    id,
+    constants.ErrorLogKey,
+    err,
+    types.MessageContentLogKey,
+    sanitize(msg.String()), // Ensure sensitive data is not logged
+    types.MessageTypeUrlLogKey,
+    delayedMsg.Msg.TypeUrl,
+ )

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 37dcee8 and ebf05a2.
Files selected for processing (2)
  • protocol/testutil/constants/bridge.go (2 hunks)
  • protocol/x/bridge/app_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/bridge/app_test.go
Additional comments: 2
protocol/testutil/constants/bridge.go (2)
  • 36-39: The emptyCoin variable is introduced with a denomination of "adv4tnt" and an amount of 0. Ensure that this denomination is valid and that a coin with an amount of 0 is handled correctly in all places where emptyCoin is used.

  • 73-78: A new BridgeEvent is introduced with an ID of 0, the address of Alice, the emptyCoin as the coin, and an Ethereum block height of 0. Ensure that these values are valid and handled correctly in all places where BridgeEvent_Id4_Height0_EmptyCoin is used. In particular, verify that a BridgeEvent with an ID of 0 and an Ethereum block height of 0 is acceptable and does not conflict with any existing events.

@teddyding teddyding changed the title Explicitly log out delayed message when execution fails [CORE-708] Explicitly log out delayed message when execution fails Oct 24, 2023
@linear
Copy link

linear bot commented Oct 24, 2023

CORE-708 In `delaymdg`, explicitly log out message that failed execution

I can take this one since crystal has quite a few other tasks here.

@@ -72,6 +72,23 @@ func TestBridge_Success(t *testing.T) {
blockTime: time.Now(),
expectNonEmptyBridgeTx: true,
},
"Success: 1 bridge event with 0 coin denom, delay 5 blocks": {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
"Success: 1 bridge event with 0 coin denom, delay 5 blocks": {
"Success: 1 bridge event with 0 coin amount, delay 5 blocks": {

@@ -23,5 +23,7 @@ const (

// Log
const (
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we should prob create a separate file types/constants.go or types/logs.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ebf05a2 and 27f59e0.
Files selected for processing (3)
  • protocol/x/bridge/app_test.go (1 hunks)
  • protocol/x/delaymsg/types/keys.go (1 hunks)
  • protocol/x/delaymsg/types/logs.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • protocol/x/bridge/app_test.go
  • protocol/x/delaymsg/types/keys.go
  • protocol/x/delaymsg/types/logs.go

@teddyding teddyding merged commit 1f065b4 into main Oct 24, 2023
14 of 15 checks passed
@teddyding teddyding deleted the td/delay-msg-log branch October 24, 2023 20:44
@teddyding
Copy link
Contributor Author

@Mergifyio backport release/protocol/v1.x

@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

backport release/protocol/v1.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 24, 2023
)

* explicitly log out message when dispatch fails

* add e2e test case where delayed MsgCompleteBridge fails to execute

* nits

(cherry picked from commit 1f065b4)
teddyding added a commit that referenced this pull request Oct 24, 2023
) (#696)

* explicitly log out message when dispatch fails

* add e2e test case where delayed MsgCompleteBridge fails to execute

* nits

(cherry picked from commit 1f065b4)

Co-authored-by: Teddy Ding <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants