-
Notifications
You must be signed in to change notification settings - Fork 30
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in this pull request focus on enhancing the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
contrib/opbot/botmd/commands.go (2)
341-345
: Avoid variable shadowing oferr
in error handlingIn 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-declaringerr
.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 oferr
when sending responseSimilarly, 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 innererr
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) + }
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 | ||
} |
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.
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.
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 | |
} |
Deploying sanguine-fe with Cloudflare Pages
|
@@ -336,6 +336,22 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { | |||
return | |||
} | |||
|
|||
isRelayed, err := fastBridgeContract.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID))) |
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.
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.
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
Summary by CodeRabbit
New Features
rfqRefund
command to check if a transaction has already been relayed, preventing unnecessary refund attempts.Bug Fixes
rfqRefund
command to ensure users receive appropriate feedback when attempting to refund a relayed transaction.