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

feat(opbot): add additional relay check [SLT-359] #3312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Oct 18, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Enhanced the rfqRefund command to check if a transaction has already been relayed, preventing unnecessary refund attempts.
  • Bug Fixes

    • Improved error handling for the rfqRefund command to ensure users receive appropriate feedback when attempting to refund a relayed transaction.

Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The changes in this pull request focus on enhancing the rfqRefund method within the botmd package of the Bot struct. A new validation step has been introduced to check if a transaction has already been relayed by utilizing the BridgeRelays method. If the transaction is confirmed as relayed, the command will terminate early, providing a user response that the refund cannot be processed. Additionally, error handling has been improved to accommodate this new check.

Changes

File Path Change Summary
contrib/opbot/botmd/commands.go Updated rfqRefund method to include a check for relayed transactions and enhanced error handling.

Possibly related PRs

Suggested labels

go, size/s

Suggested reviewers

  • trajan0x

🐇 In the garden where bunnies play,
A command was changed in a clever way.
With checks for relays, oh what a sight,
Refunds now handled just right!
Hopping with joy, we celebrate,
For smoother transactions, let’s all elevate! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Oct 18, 2024
@golangisfun123 golangisfun123 changed the title feat(opb0t: add additional relay check feat(opbot): add additional relay check [SLT-359] Oct 18, 2024
Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 26.95425%. Comparing base (0a2abde) to head (c5659ed).

Files with missing lines Patch % Lines
contrib/opbot/botmd/commands.go 0.00000% 13 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3312         +/-   ##
===================================================
- Coverage   26.98386%   26.95425%   -0.02962%     
===================================================
  Files            178         178                 
  Lines          11833       11846         +13     
  Branches          82          82                 
===================================================
  Hits            3193        3193                 
- Misses          8357        8370         +13     
  Partials         283         283                 
Flag Coverage Δ
opbot 0.48485% <0.00000%> (-0.00386%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
contrib/opbot/botmd/commands.go (2)

341-345: Avoid variable shadowing of err in error handling

In line 341, the err variable is re-declared within the inner scope:

_, err := ctx.Response().Reply("error fetching bridge relays")

This shadows the outer err variable from line 339. Shadowing can lead to confusion and potential bugs, especially in more complex functions. It's advisable to use a different variable name or handle the error without re-declaring err.

Apply this diff to avoid variable shadowing:

-        _, err := ctx.Response().Reply("error fetching bridge relays")
-        if err != nil {
-            log.Println(err)
-        }
+        _, replyErr := ctx.Response().Reply("error fetching bridge relays")
+        if replyErr != nil {
+            log.Println(replyErr)
+        }

348-352: Avoid variable shadowing of err when sending response

Similarly, in line 348, err is re-declared when sending the response:

_, err := ctx.Response().Reply("transaction has already been relayed")

This shadows the outer err variable. To improve code clarity and maintainability, consider renaming the inner err variable.

Apply this diff to avoid variable shadowing:

-        _, err := ctx.Response().Reply("transaction has already been relayed")
-        if err != nil {
-            log.Println(err)
-        }
+        _, replyErr := ctx.Response().Reply("transaction has already been relayed")
+        if replyErr != nil {
+            log.Println(replyErr)
+        }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0a2abde and c5659ed.

📒 Files selected for processing (1)
  • contrib/opbot/botmd/commands.go (1 hunks)
🧰 Additional context used

Comment on lines +339 to +346
isRelayed, err := fastBridgeContract.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID)))
if err != nil {
_, err := ctx.Response().Reply("error fetching bridge relays")
if err != nil {
log.Println(err)
}
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use common.HexToHash for proper TxID conversion

The current code uses [32]byte(common.Hex2Bytes(rawRequest.TxID)) to convert rawRequest.TxID to a [32]byte array. This approach may lead to incorrect results if rawRequest.TxID is not exactly 64 hexadecimal characters (representing 32 bytes). If the TxID is shorter or longer than expected, this conversion can cause incorrect behavior or even a panic.

To ensure accurate and safe conversion, consider using common.HexToHash(rawRequest.TxID), which returns a common.Hash (an alias for [32]byte) and properly handles the hex string conversion.

Apply this diff to fix the issue:

-isRelayed, err := fastBridgeContract.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID)))
+isRelayed, err := fastBridgeContract.BridgeRelays(nil, common.HexToHash(rawRequest.TxID))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
isRelayed, err := fastBridgeContract.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID)))
if err != nil {
_, err := ctx.Response().Reply("error fetching bridge relays")
if err != nil {
log.Println(err)
}
return
}
isRelayed, err := fastBridgeContract.BridgeRelays(nil, common.HexToHash(rawRequest.TxID))
if err != nil {
_, err := ctx.Response().Reply("error fetching bridge relays")
if err != nil {
log.Println(err)
}
return
}

Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: c5659ed
Status: ✅  Deploy successful!
Preview URL: https://cc8dde4d.sanguine-fe.pages.dev
Branch Preview URL: https://additional-screening.sanguine-fe.pages.dev

View logs

@@ -336,6 +336,22 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return
}

isRelayed, err := fastBridgeContract.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

fastBridgeContract is the contract on the origin chain, whereas we need to check if the relay happened on the destination.

I guess one of the possible solutions would involve adjusting makeFastBridge to make both origin and destination instances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/xs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants