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

fix(opbot): reduce complexity, link to refund tx, and fix premature return #3029

Closed
wants to merge 8 commits into from

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Aug 15, 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 error handling in the refund process, allowing it to continue through multiple relayers.
    • Added methods for fetching statuses and constructing Slack blocks, improving modularity.
  • Bug Fixes

    • Resolved issues with concurrent fetching of quote request statuses, enhancing reliability and performance.
  • Refactor

    • Refactored core command functions to improve code organization and readability while maintaining existing functionalities.

@github-actions github-actions bot added go Pull requests that update Go code size/s labels Aug 15, 2024
Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Warning

Rate limit exceeded

@golangisfun123 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 35 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 6a0f91b and c825627.

Walkthrough

The recent refactor enhances the rfqLookupCommand and rfqRefund functions in the Bot class, improving code modularity and readability. Key changes include the introduction of the getStatuses and statusesToSlackBlocks methods, which streamline concurrency handling and response formatting. Additionally, the makeFastBridge method signature has been simplified, allowing for better error handling and more resilient processing. Overall, these improvements facilitate easier maintenance while preserving functionality.

Changes

File Path Change Summary
contrib/opbot/botmd/commands.go Refactored rfqLookupCommand and rfqRefund functions; introduced getStatuses and statusesToSlackBlocks; modified makeFastBridge method signature; added new Status type.
contrib/screener-api/go.mod Removed dependency on github.com/BurntSushi/toml v1.4.0.
ethergo/go.mod Removed dependency on github.com/BurntSushi/toml v1.4.0.

Poem

🐰 In the code where bunnies hop,
Refactoring makes our worries stop!
Statuses fetched with graceful ease,
Slack blocks crafted, sure to please.
Each line now clearer, each function bright,
Our bot’s new dance is pure delight! 🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request refactors the rfqLookupCommand and rfqRefund functions in the opbot's commands.go file, aiming to reduce complexity and improve functionality.

  • Introduced getStatuses function to fetch quote request statuses, but it contains a critical bug returning nil instead of the statuses
  • Added statusesToSlackBlocks function to convert statuses to Slack blocks for improved readability
  • Modified rfqRefund to include a link to the refund transaction in the response
  • Fixed a premature return in rfqLookupCommand by moving the Slack response outside the loop
  • Reduced overall complexity by separating concerns into helper functions

1 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings

}
wg.Wait()

return nil
Copy link

Choose a reason for hiding this comment

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

logic: This function always returns nil, which will cause the rfqLookupCommand to fail

Comment on lines 230 to 238
// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
txHash, err := relClient.GetTxHashByNonce(ctx.Context(), &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
},
)
_, err = ctx.Response().Reply(
fmt.Sprintf("refund submitted with nonce %d, transaction %s", nonce, toTXSlackLink(txHash.Hash, rawRequest.OriginChainID)),
)
Copy link

Choose a reason for hiding this comment

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

style: Consider handling the error from GetTxHashByNonce

tx := stripLinks(ctx.Request().Param("tx"))

var wg sync.WaitGroup
// 2 routines per relayer, one for tx hashh one for tx id
Copy link

Choose a reason for hiding this comment

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

syntax: Typo in comment: 'hashh' should be 'hash'

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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f99fad and bdb5b22.

Files selected for processing (1)
  • contrib/opbot/botmd/commands.go (8 hunks)
Additional context used
GitHub Check: Lint (contrib/opbot)
contrib/opbot/botmd/commands.go

[failure] 242-242:
S1023: redundant return statement (gosimple)


[failure] 231-231:
SA4006: this value of err is never used (staticcheck)


[failure] 275-275:
exported type Status should have comment or be unexported (golint)


[failure] 280-280:
(*Bot).getStatuses - result 0 ([]github.com/synapsecns/sanguine/contrib/opbot/botmd.Status) is always nil (unparam)

Additional comments not posted (4)
contrib/opbot/botmd/commands.go (4)

Line range hint 161-175:
Refactoring improves modularity and readability.

The use of getStatuses and statusesToSlackBlocks methods simplifies the command logic and enhances maintainability. Ensure that these methods are tested to verify they maintain the intended functionality.


Line range hint 247-268:
Simplified function signature improves maintainability.

The change to accept originChainID directly reduces dependencies and simplifies the function. Ensure that the logic remains correct with this new parameter.


320-365: Well-structured function enhances code organization.

The statusesToSlackBlocks function effectively separates concerns and improves readability. Ensure that the error handling and Slack message formatting are correct.


195-242: Improved error handling and transaction linking.

The refactoring enhances resilience by continuing through relayers and linking refund transactions. Ensure that the makeFastBridge function is used correctly with the updated signature.

However, verify that all calls to makeFastBridge are updated to match the new signature.

Verification successful

All makeFastBridge calls match the updated signature.

The function call to makeFastBridge in commands.go is consistent with its updated signature, and there are no discrepancies found in the usage throughout the codebase. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `makeFastBridge` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'makeFastBridge'

Length of output: 893

Tools
GitHub Check: Lint (contrib/opbot)

[failure] 242-242:
S1023: redundant return statement (gosimple)


[failure] 231-231:
SA4006: this value of err is never used (staticcheck)

Comment on lines +275 to +278
type Status struct {
relayer string
*relapi.GetQuoteRequestStatusResponse
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment to the exported Status type.

The Status type should have a comment explaining its purpose, as it is exported.

// Status represents the status of a quote request from a relayer.
type Status struct {
	relayer string
	*relapi.GetQuoteRequestStatusResponse
}
Tools
GitHub Check: Lint (contrib/opbot)

[failure] 275-275:
exported type Status should have comment or be unexported (golint)

Comment on lines 280 to 317
func (b *Bot) getStatuses(ctx *slacker.CommandContext) []Status {
var statuses []Status
var sliceMux sync.Mutex

tx := stripLinks(ctx.Request().Param("tx"))

var wg sync.WaitGroup
// 2 routines per relayer, one for tx hashh one for tx id
wg.Add(len(b.cfg.RelayerURLS) * 2)
for _, relayer := range b.cfg.RelayerURLS {
client := relapi.NewRelayerClient(b.handler, relayer)
go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxHash(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx hash: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()

go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxID(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx id: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
}
wg.Wait()

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the return value of getStatuses.

The function should return the statuses slice instead of nil.

-	return nil
+	return statuses
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
func (b *Bot) getStatuses(ctx *slacker.CommandContext) []Status {
var statuses []Status
var sliceMux sync.Mutex
tx := stripLinks(ctx.Request().Param("tx"))
var wg sync.WaitGroup
// 2 routines per relayer, one for tx hashh one for tx id
wg.Add(len(b.cfg.RelayerURLS) * 2)
for _, relayer := range b.cfg.RelayerURLS {
client := relapi.NewRelayerClient(b.handler, relayer)
go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxHash(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx hash: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxID(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx id: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
}
wg.Wait()
return nil
func (b *Bot) getStatuses(ctx *slacker.CommandContext) []Status {
var statuses []Status
var sliceMux sync.Mutex
tx := stripLinks(ctx.Request().Param("tx"))
var wg sync.WaitGroup
// 2 routines per relayer, one for tx hashh one for tx id
wg.Add(len(b.cfg.RelayerURLS) * 2)
for _, relayer := range b.cfg.RelayerURLS {
client := relapi.NewRelayerClient(b.handler, relayer)
go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxHash(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx hash: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxID(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx id: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
}
wg.Wait()
return statuses
Tools
GitHub Check: Lint (contrib/opbot)

[failure] 280-280:
(*Bot).getStatuses - result 0 ([]github.com/synapsecns/sanguine/contrib/opbot/botmd.Status) is always nil (unparam)

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

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

Project coverage is 23.35381%. Comparing base (77f5863) to head (c825627).
Report is 54 commits behind head on master.

Files Patch % Lines
contrib/opbot/botmd/commands.go 0.00000% 126 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3029         +/-   ##
===================================================
+ Coverage   20.71326%   23.35381%   +2.64055%     
===================================================
  Files            490         644        +154     
  Lines          42509       50146       +7637     
  Branches          82          82                 
===================================================
+ Hits            8805       11711       +2906     
- Misses         32769       37271       +4502     
- Partials         935        1164        +229     
Flag Coverage Δ
cctp-relayer 31.97848% <ø> (?)
core 59.24185% <ø> (?)
ethergo 47.78384% <ø> (-0.05790%) ⬇️
git-changes-action 23.69615% <ø> (?)
omnirpc 33.23904% <ø> (ø)
opbot 0.48222% <0.00000%> (-0.00679%) ⬇️
promexporter 7.06260% <ø> (?)
screener-api 29.45990% <ø> (?)
scribe 18.18182% <ø> (ø)
tools 30.55118% <ø> (ø)

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

cloudflare-workers-and-pages bot commented Aug 15, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: d1f7c5f
Status: ✅  Deploy successful!
Preview URL: https://5ea42345.sanguine-fe.pages.dev
Branch Preview URL: https://fix-opbot-error.sanguine-fe.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This pull request focuses on improving the opbot's command handling in the contrib/opbot/botmd/commands.go file. The main changes include:

  • Enhanced error handling in the rfqRefund command, allowing it to continue through multiple relayers if errors occur.
  • Added a new Status struct to hold relayer and quote request status information.
  • Implemented a getStatuses function to fetch quote request statuses concurrently from multiple relayers.
  • Created a statusesToSlackBlocks function to convert statuses to Slack blocks for improved readability.
  • Fixed a bug in the getStatuses function that was causing premature returns.

These changes aim to improve the robustness and functionality of the opbot, particularly in handling RFQ (Request for Quote) related commands. The refactoring should lead to better code organization and error handling, enhancing the overall reliability of the bot's interactions with the RFQ relayer service.

1 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

Comment on lines 231 to 237
txHash, err := relClient.GetTxHashByNonce(ctx.Context(), &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
if err != nil {
log.Printf("error fetching tx hash by nonce: %v\n", err)
}
Copy link

Choose a reason for hiding this comment

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

style: Error handling for GetTxHashByNonce is good, but consider returning early or notifying the user if the hash couldn't be fetched

tx := stripLinks(ctx.Request().Param("tx"))

var wg sync.WaitGroup
// 2 routines per relayer, one for tx hashh one for tx id
Copy link

Choose a reason for hiding this comment

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

syntax: Typo in comment: 'hashh' should be 'hash'

Comment on lines +294 to +304
go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxHash(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx hash: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
Copy link

Choose a reason for hiding this comment

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

style: Consider using a pointer to the Status struct to avoid copying large objects

Comment on lines +307 to +316
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxID(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx id: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
Copy link

Choose a reason for hiding this comment

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

style: This goroutine is nearly identical to the previous one. Consider refactoring to reduce code duplication

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: 4

Outside diff range, codebase verification and nitpick comments (1)
contrib/opbot/botmd/commands.go (1)

Line range hint 249-265:
Add test coverage for makeFastBridge.

Ensure that the new function signature and logic are covered by tests to validate its behavior.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: codecov/patch

[warning] 260-260: contrib/opbot/botmd/commands.go#L260
Added line #L260 was not covered by tests


[warning] 265-265: contrib/opbot/botmd/commands.go#L265
Added line #L265 was not covered by tests

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdb5b22 and fd87de1.

Files selected for processing (1)
  • contrib/opbot/botmd/commands.go (8 hunks)
Additional context used
GitHub Check: codecov/patch
contrib/opbot/botmd/commands.go

[warning] 161-161: contrib/opbot/botmd/commands.go#L161
Added line #L161 was not covered by tests


[warning] 170-170: contrib/opbot/botmd/commands.go#L170
Added line #L170 was not covered by tests


[warning] 195-197: contrib/opbot/botmd/commands.go#L195-L197
Added lines #L195 - L197 were not covered by tests


[warning] 199-200: contrib/opbot/botmd/commands.go#L199-L200
Added lines #L199 - L200 were not covered by tests


[warning] 211-213: contrib/opbot/botmd/commands.go#L211-L213
Added lines #L211 - L213 were not covered by tests


[warning] 219-224: contrib/opbot/botmd/commands.go#L219-L224
Added lines #L219 - L224 were not covered by tests


[warning] 226-228: contrib/opbot/botmd/commands.go#L226-L228
Added lines #L226 - L228 were not covered by tests


[warning] 231-237: contrib/opbot/botmd/commands.go#L231-L237
Added lines #L231 - L237 were not covered by tests


[warning] 239-244: contrib/opbot/botmd/commands.go#L239-L244
Added lines #L239 - L244 were not covered by tests


[warning] 249-249: contrib/opbot/botmd/commands.go#L249
Added line #L249 was not covered by tests


[warning] 260-260: contrib/opbot/botmd/commands.go#L260
Added line #L260 was not covered by tests


[warning] 265-265: contrib/opbot/botmd/commands.go#L265
Added line #L265 was not covered by tests


[warning] 283-303: contrib/opbot/botmd/commands.go#L283-L303
Added lines #L283 - L303 were not covered by tests


[warning] 306-315: contrib/opbot/botmd/commands.go#L306-L315
Added lines #L306 - L315 were not covered by tests


[warning] 318-320: contrib/opbot/botmd/commands.go#L318-L320
Added lines #L318 - L320 were not covered by tests


[warning] 323-329: contrib/opbot/botmd/commands.go#L323-L329
Added lines #L323 - L329 were not covered by tests


[warning] 331-364: contrib/opbot/botmd/commands.go#L331-L364
Added lines #L331 - L364 were not covered by tests


[warning] 366-366: contrib/opbot/botmd/commands.go#L366
Added line #L366 was not covered by tests


[warning] 368-368: contrib/opbot/botmd/commands.go#L368
Added line #L368 was not covered by tests


[warning] 412-412: contrib/opbot/botmd/commands.go#L412
Added line #L412 was not covered by tests

Additional comments not posted (5)
contrib/opbot/botmd/commands.go (5)

Line range hint 161-175:
LGTM!

The refactoring in rfqLookupCommand improves modularity and readability by delegating tasks to getStatuses and statusesToSlackBlocks.

Tools
GitHub Check: codecov/patch

[warning] 170-170: contrib/opbot/botmd/commands.go#L170
Added line #L170 was not covered by tests


195-244: LGTM!

The changes in rfqRefund enhance error handling and resilience, allowing for continued processing through multiple relayers.

Tools
GitHub Check: codecov/patch

[warning] 195-197: contrib/opbot/botmd/commands.go#L195-L197
Added lines #L195 - L197 were not covered by tests


[warning] 199-200: contrib/opbot/botmd/commands.go#L199-L200
Added lines #L199 - L200 were not covered by tests


[warning] 211-213: contrib/opbot/botmd/commands.go#L211-L213
Added lines #L211 - L213 were not covered by tests


[warning] 219-224: contrib/opbot/botmd/commands.go#L219-L224
Added lines #L219 - L224 were not covered by tests


[warning] 226-228: contrib/opbot/botmd/commands.go#L226-L228
Added lines #L226 - L228 were not covered by tests


[warning] 231-237: contrib/opbot/botmd/commands.go#L231-L237
Added lines #L231 - L237 were not covered by tests


[warning] 239-244: contrib/opbot/botmd/commands.go#L239-L244
Added lines #L239 - L244 were not covered by tests


Line range hint 249-265:
LGTM!

The simplification of the makeFastBridge function signature improves clarity and reduces dependencies.

Tools
GitHub Check: codecov/patch

[warning] 260-260: contrib/opbot/botmd/commands.go#L260
Added line #L260 was not covered by tests


[warning] 265-265: contrib/opbot/botmd/commands.go#L265
Added line #L265 was not covered by tests


283-320: LGTM!

The use of goroutines and a mutex in getStatuses effectively handles concurrent status retrieval.

Tools
GitHub Check: codecov/patch

[warning] 283-303: contrib/opbot/botmd/commands.go#L283-L303
Added lines #L283 - L303 were not covered by tests


[warning] 306-315: contrib/opbot/botmd/commands.go#L306-L315
Added lines #L306 - L315 were not covered by tests


[warning] 318-320: contrib/opbot/botmd/commands.go#L318-L320
Added lines #L318 - L320 were not covered by tests


323-368: LGTM!

The statusesToSlackBlocks function is well-structured for formatting statuses into Slack blocks.

Tools
GitHub Check: codecov/patch

[warning] 323-329: contrib/opbot/botmd/commands.go#L323-L329
Added lines #L323 - L329 were not covered by tests


[warning] 331-364: contrib/opbot/botmd/commands.go#L331-L364
Added lines #L331 - L364 were not covered by tests


[warning] 366-366: contrib/opbot/botmd/commands.go#L366
Added line #L366 was not covered by tests


[warning] 368-368: contrib/opbot/botmd/commands.go#L368
Added line #L368 was not covered by tests

}
wg.Wait()

statuses := b.getStatuses(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for rfqLookupCommand.

The new logic in rfqLookupCommand involving getStatuses and statusesToSlackBlocks should be covered by tests to ensure reliability.

Would you like assistance in generating unit tests for this function?

Also applies to: 170-170

Tools
GitHub Check: codecov/patch

[warning] 161-161: contrib/opbot/botmd/commands.go#L161
Added line #L161 was not covered by tests

Comment on lines 195 to 244
var rawRequest *relapi.GetQuoteRequestResponse
var err error
var relClient relapi.RelayerClient
for _, relayer := range b.cfg.RelayerURLS {
relClient := relapi.NewRelayerClient(b.handler, relayer)

rawRequest, err := getQuoteRequest(ctx.Context(), relClient, tx)
relClient = relapi.NewRelayerClient(b.handler, relayer)
rawRequest, err = getQuoteRequest(ctx.Context(), relClient, tx)
if err != nil {
_, err := ctx.Response().Reply("error fetching quote request")
if err != nil {
log.Println(err)
}
return
}

fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
// continue through the rest of the relayers
continue
}
}

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest.OriginChainID)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
}

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
txHash, err := relClient.GetTxHashByNonce(ctx.Context(), &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
if err != nil {
log.Printf("error fetching tx hash by nonce: %v\n", err)
}

_, err = ctx.Response().Reply(
fmt.Sprintf("refund submitted with nonce %d, transaction %s", nonce, toTXSlackLink(txHash.Hash, rawRequest.OriginChainID)),
)
if err != nil {
log.Println(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for rfqRefund.

The refund logic and error handling should be covered by tests to ensure the function behaves as expected under various conditions.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: codecov/patch

[warning] 195-197: contrib/opbot/botmd/commands.go#L195-L197
Added lines #L195 - L197 were not covered by tests


[warning] 199-200: contrib/opbot/botmd/commands.go#L199-L200
Added lines #L199 - L200 were not covered by tests


[warning] 211-213: contrib/opbot/botmd/commands.go#L211-L213
Added lines #L211 - L213 were not covered by tests


[warning] 219-224: contrib/opbot/botmd/commands.go#L219-L224
Added lines #L219 - L224 were not covered by tests


[warning] 226-228: contrib/opbot/botmd/commands.go#L226-L228
Added lines #L226 - L228 were not covered by tests


[warning] 231-237: contrib/opbot/botmd/commands.go#L231-L237
Added lines #L231 - L237 were not covered by tests


[warning] 239-244: contrib/opbot/botmd/commands.go#L239-L244
Added lines #L239 - L244 were not covered by tests

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This pull request enhances the opbot's command handling, focusing on the rfqRefund command in contrib/opbot/botmd/commands.go.

  • Improved error handling in rfqRefund command, allowing continuation through multiple relayers
  • Added getStatuses function for concurrent fetching of quote request statuses from multiple relayers
  • Implemented statusesToSlackBlocks function to convert statuses to Slack blocks for better readability
  • Fixed a bug in getStatuses that was causing premature returns
  • Refactored code to improve organization and reduce complexity in RFQ-related command handling

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

No major changes found since last review.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This pull request focuses on improving the opbot commands implementation, particularly the refund command and related functions. Here's a concise summary of the key changes:

  • Refactored the rfqRefund command to handle multiple relayers, improving error handling and reliability.
  • Introduced new helper methods getStatuses and statusesToSlackBlocks to enhance modularity and readability.
  • Implemented concurrent fetching of quote request statuses, improving performance when dealing with multiple relayers.
  • Added a link to the refund transaction in the Slack response, providing better traceability.
  • Fixed a premature return issue in the refund process, allowing it to continue through all configured relayers.

These changes aim to reduce complexity, improve error handling, and enhance the overall functionality of the opbot, particularly in handling refund requests across multiple relayers.

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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: 3

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

Line range hint 162-176:
Add test coverage for rfqLookupCommand.

The new logic in rfqLookupCommand involving getStatuses and statusesToSlackBlocks should be covered by tests to ensure reliability.

Would you like assistance in generating unit tests for this function?


286-290: Add a comment to the exported Status type.

The Status type should have a comment explaining its purpose, as it is exported.

// Status represents the status of a quote request from a relayer.
type Status struct {
	relayer string
	*relapi.GetQuoteRequestStatusResponse
}
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fd87de1 and 805dca0.

Files ignored due to path filters (2)
  • contrib/screener-api/go.sum is excluded by !**/*.sum
  • core/go.sum is excluded by !**/*.sum
Files selected for processing (3)
  • contrib/opbot/botmd/commands.go (9 hunks)
  • contrib/screener-api/go.mod (1 hunks)
  • ethergo/go.mod (1 hunks)
Files skipped from review due to trivial changes (2)
  • contrib/screener-api/go.mod
  • ethergo/go.mod
Additional context used
GitHub Check: Lint (contrib/opbot)
contrib/opbot/botmd/commands.go

[failure] 232-232:
Error return value of retry.WithBackoff is not checked (errcheck)

Additional comments not posted (1)
contrib/opbot/botmd/commands.go (1)

Line range hint 258-283:
LGTM!

The refactored makeFastBridge function simplifies the method signature and improves error handling.

Comment on lines 196 to 253
var rawRequest *relapi.GetQuoteRequestResponse
var err error
var relClient relapi.RelayerClient
for _, relayer := range b.cfg.RelayerURLS {
relClient := relapi.NewRelayerClient(b.handler, relayer)

rawRequest, err := getQuoteRequest(ctx.Context(), relClient, tx)
relClient = relapi.NewRelayerClient(b.handler, relayer)
rawRequest, err = getQuoteRequest(ctx.Context(), relClient, tx)
if err != nil {
_, err := ctx.Response().Reply("error fetching quote request")
if err != nil {
log.Println(err)
}
return
}

fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
// continue through the rest of the relayers
continue
}
}

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest.OriginChainID)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
}

var txHash *relapi.TxHashByNonceResponse
retry.WithBackoff(
ctx.Context(),
func(_ context.Context) error {
txHash, err = relClient.GetTxHashByNonce(ctx.Context(), &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
if err != nil {
return fmt.Errorf("error fetching tx hash by nonce: %w", err)
}
return nil
},
retry.WithMaxAttempts(5),
retry.WithMaxTotalTime(30*time.Second),
)

_, err = ctx.Response().Reply(
fmt.Sprintf("refund submitted with nonce %d, transaction %s", nonce, toTXSlackLink(txHash.Hash, rawRequest.OriginChainID)),
)
if err != nil {
log.Println(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for rfqRefund.

The refund logic and error handling should be covered by tests to ensure the function behaves as expected under various conditions.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: Lint (contrib/opbot)

[failure] 232-232:
Error return value of retry.WithBackoff is not checked (errcheck)

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

No major changes found since last review.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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: 3

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

Line range hint 162-171:
Add test coverage for rfqLookupCommand.

The logic involving getStatuses and statusesToSlackBlocks should be covered by tests to ensure reliability.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: codecov/patch

[warning] 162-162: contrib/opbot/botmd/commands.go#L162
Added line #L162 was not covered by tests


Line range hint 261-277:
Add test coverage for makeFastBridge.

Tests should verify the function's behavior under various conditions, including error scenarios.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: codecov/patch

[warning] 272-272: contrib/opbot/botmd/commands.go#L272
Added line #L272 was not covered by tests


[warning] 277-277: contrib/opbot/botmd/commands.go#L277
Added line #L277 was not covered by tests

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 805dca0 and 6a0f91b.

Files selected for processing (1)
  • contrib/opbot/botmd/commands.go (9 hunks)
Additional context used
GitHub Check: codecov/patch
contrib/opbot/botmd/commands.go

[warning] 162-162: contrib/opbot/botmd/commands.go#L162
Added line #L162 was not covered by tests


[warning] 171-171: contrib/opbot/botmd/commands.go#L171
Added line #L171 was not covered by tests


[warning] 196-198: contrib/opbot/botmd/commands.go#L196-L198
Added lines #L196 - L198 were not covered by tests


[warning] 200-201: contrib/opbot/botmd/commands.go#L200-L201
Added lines #L200 - L201 were not covered by tests


[warning] 212-214: contrib/opbot/botmd/commands.go#L212-L214
Added lines #L212 - L214 were not covered by tests


[warning] 220-225: contrib/opbot/botmd/commands.go#L220-L225
Added lines #L220 - L225 were not covered by tests


[warning] 227-229: contrib/opbot/botmd/commands.go#L227-L229
Added lines #L227 - L229 were not covered by tests


[warning] 231-242: contrib/opbot/botmd/commands.go#L231-L242
Added lines #L231 - L242 were not covered by tests


[warning] 247-249: contrib/opbot/botmd/commands.go#L247-L249
Added lines #L247 - L249 were not covered by tests


[warning] 251-256: contrib/opbot/botmd/commands.go#L251-L256
Added lines #L251 - L256 were not covered by tests


[warning] 261-261: contrib/opbot/botmd/commands.go#L261
Added line #L261 was not covered by tests


[warning] 272-272: contrib/opbot/botmd/commands.go#L272
Added line #L272 was not covered by tests


[warning] 277-277: contrib/opbot/botmd/commands.go#L277
Added line #L277 was not covered by tests


[warning] 295-315: contrib/opbot/botmd/commands.go#L295-L315
Added lines #L295 - L315 were not covered by tests


[warning] 318-327: contrib/opbot/botmd/commands.go#L318-L327
Added lines #L318 - L327 were not covered by tests


[warning] 330-332: contrib/opbot/botmd/commands.go#L330-L332
Added lines #L330 - L332 were not covered by tests


[warning] 335-341: contrib/opbot/botmd/commands.go#L335-L341
Added lines #L335 - L341 were not covered by tests


[warning] 343-376: contrib/opbot/botmd/commands.go#L343-L376
Added lines #L343 - L376 were not covered by tests


[warning] 378-378: contrib/opbot/botmd/commands.go#L378
Added line #L378 was not covered by tests


[warning] 380-380: contrib/opbot/botmd/commands.go#L380
Added line #L380 was not covered by tests


[warning] 424-424: contrib/opbot/botmd/commands.go#L424
Added line #L424 was not covered by tests

Additional comments not posted (1)
contrib/opbot/botmd/commands.go (1)

424-424: LGTM!

The logic for fetching a quote request is clear and well-handled.

Tools
GitHub Check: codecov/patch

[warning] 424-424: contrib/opbot/botmd/commands.go#L424
Added line #L424 was not covered by tests

Comment on lines 196 to 256
var rawRequest *relapi.GetQuoteRequestResponse
var err error
var relClient relapi.RelayerClient
for _, relayer := range b.cfg.RelayerURLS {
relClient := relapi.NewRelayerClient(b.handler, relayer)

rawRequest, err := getQuoteRequest(ctx.Context(), relClient, tx)
relClient = relapi.NewRelayerClient(b.handler, relayer)
rawRequest, err = getQuoteRequest(ctx.Context(), relClient, tx)
if err != nil {
_, err := ctx.Response().Reply("error fetching quote request")
if err != nil {
log.Println(err)
}
return
}

fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
// continue through the rest of the relayers
continue
}
}

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest.OriginChainID)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
}

var txHash *relapi.TxHashByNonceResponse
err = retry.WithBackoff(
ctx.Context(),
func(_ context.Context) error {
txHash, err = relClient.GetTxHashByNonce(ctx.Context(), &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
if err != nil {
return fmt.Errorf("error fetching tx hash by nonce: %w", err)
}
return nil
},
retry.WithMaxAttempts(5),
retry.WithMaxTotalTime(30*time.Second),
)
if err != nil {
log.Printf("error fetching tx hash by nonce: %v\n", err)
}

_, err = ctx.Response().Reply(
fmt.Sprintf("refund submitted with nonce %d, transaction %s", nonce, toTXSlackLink(txHash.Hash, rawRequest.OriginChainID)),
)
if err != nil {
log.Println(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for rfqRefund.

The refund logic and error handling should be covered by tests to ensure the function behaves as expected under various conditions.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: codecov/patch

[warning] 196-198: contrib/opbot/botmd/commands.go#L196-L198
Added lines #L196 - L198 were not covered by tests


[warning] 200-201: contrib/opbot/botmd/commands.go#L200-L201
Added lines #L200 - L201 were not covered by tests


[warning] 212-214: contrib/opbot/botmd/commands.go#L212-L214
Added lines #L212 - L214 were not covered by tests


[warning] 220-225: contrib/opbot/botmd/commands.go#L220-L225
Added lines #L220 - L225 were not covered by tests


[warning] 227-229: contrib/opbot/botmd/commands.go#L227-L229
Added lines #L227 - L229 were not covered by tests


[warning] 231-242: contrib/opbot/botmd/commands.go#L231-L242
Added lines #L231 - L242 were not covered by tests


[warning] 247-249: contrib/opbot/botmd/commands.go#L247-L249
Added lines #L247 - L249 were not covered by tests


[warning] 251-256: contrib/opbot/botmd/commands.go#L251-L256
Added lines #L251 - L256 were not covered by tests

Comment on lines +295 to +332
func (b *Bot) getStatuses(ctx *slacker.CommandContext) []Status {
var statuses []Status
var sliceMux sync.Mutex

tx := stripLinks(ctx.Request().Param("tx"))

var wg sync.WaitGroup
// 2 routines per relayer, one for tx hashh one for tx id
wg.Add(len(b.cfg.RelayerURLS) * 2)
for _, relayer := range b.cfg.RelayerURLS {
client := relapi.NewRelayerClient(b.handler, relayer)
go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxHash(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx hash: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()

go func() {
defer wg.Done()
res, err := client.GetQuoteRequestStatusByTxID(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request status by tx id: %v\n", err)
return
}
sliceMux.Lock()
defer sliceMux.Unlock()
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res})
}()
}
wg.Wait()

return statuses
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for getStatuses.

The concurrent status retrieval logic should be covered by tests to ensure thread safety and correctness.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: codecov/patch

[warning] 295-315: contrib/opbot/botmd/commands.go#L295-L315
Added lines #L295 - L315 were not covered by tests


[warning] 318-327: contrib/opbot/botmd/commands.go#L318-L327
Added lines #L318 - L327 were not covered by tests


[warning] 330-332: contrib/opbot/botmd/commands.go#L330-L332
Added lines #L330 - L332 were not covered by tests

Comment on lines +335 to +380
func (b *Bot) statusesToSlackBlocks(ctx *slacker.CommandContext, statuses []Status) []slack.Block {
var slackBlocks []slack.Block
for _, status := range statuses {
client, err := b.rpcClient.GetChainClient(ctx.Context(), int(status.OriginChainID))
if err != nil {
log.Printf("error getting chain client: %v\n", err)
}

objects := []*slack.TextBlockObject{
{
Type: slack.MarkdownType,
Text: fmt.Sprintf("*Relayer*: %s", status.relayer),
},
{
Type: slack.MarkdownType,
Text: fmt.Sprintf("*Status*: %s", status.Status),
},
{
Type: slack.MarkdownType,
Text: fmt.Sprintf("*TxID*: %s", toExplorerSlackLink(status.TxID)),
},
{
Type: slack.MarkdownType,
Text: fmt.Sprintf("*OriginTxHash*: %s", toTXSlackLink(status.OriginTxHash, status.OriginChainID)),
},
{
Type: slack.MarkdownType,
Text: fmt.Sprintf("*Estimated Tx Age*: %s", getTxAge(ctx.Context(), client, status.GetQuoteRequestStatusResponse)),
},
}

if status.DestTxHash == (common.Hash{}).String() {
objects = append(objects, &slack.TextBlockObject{
Type: slack.MarkdownType,
Text: "*DestTxHash*: not available",
})
} else {
objects = append(objects, &slack.TextBlockObject{
Type: slack.MarkdownType,
Text: fmt.Sprintf("*DestTxHash*: %s", toTXSlackLink(status.DestTxHash, status.DestChainID)),
})
}

slackBlocks = append(slackBlocks, slack.NewSectionBlock(nil, objects, nil))
}
return slackBlocks
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for statusesToSlackBlocks.

Test the Slack block formatting logic to ensure it correctly represents the statuses.

Would you like assistance in generating unit tests for this function?

Tools
GitHub Check: codecov/patch

[warning] 335-341: contrib/opbot/botmd/commands.go#L335-L341
Added lines #L335 - L341 were not covered by tests


[warning] 343-376: contrib/opbot/botmd/commands.go#L343-L376
Added lines #L343 - L376 were not covered by tests


[warning] 378-378: contrib/opbot/botmd/commands.go#L378
Added line #L378 was not covered by tests


[warning] 380-380: contrib/opbot/botmd/commands.go#L380
Added line #L380 was not covered by tests

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This pull request introduces improvements to the rfqRefund function in the contrib/opbot/botmd/commands.go file, focusing on enhancing error handling and user experience for the refund process. Key changes include:

  • Improved error handling when fetching quote requests from multiple relayers
  • Added retry mechanism for fetching transaction hash by nonce
  • Enhanced logging for better debugging and monitoring
  • More detailed error messages for users

These updates should result in a more robust and user-friendly refund process within the OpBot system.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This pull request further refines the OpBot's RFQ-related commands, focusing on the rfqLookupCommand and rfqRefund functions in the contrib/opbot/botmd/commands.go file. Key improvements include:

  • Extracted getStatuses method to handle concurrent fetching of quote request statuses from multiple relayers, improving code organization and performance.
  • Introduced statusesToSlackBlocks method to separate the logic for constructing Slack message blocks, enhancing modularity.
  • Improved error handling in the refund process, allowing it to continue through multiple relayers if one fails.
  • Added linking to the refund transaction in the Slack response, providing better visibility of the refund process.
  • Reduced complexity in the main command functions by moving logic to separate methods, improving readability and maintainability.

These changes build upon the previous improvements, further enhancing the robustness and user experience of the OpBot's RFQ-related functionalities.

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

}
wg.Wait()

statuses := b.getStatuses(ctx)
if len(statuses) == 0 {
Copy link

Choose a reason for hiding this comment

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

style: Consider adding a more specific error message here, indicating why no quote request was found

Comment on lines +259 to +260
fmt.Sprintf("refund submitted with nonce %d, transaction %s", nonce, toTXSlackLink(txHash.Hash, rawRequest.OriginChainID)),
)
Copy link

Choose a reason for hiding this comment

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

style: Consider handling the case where txHash is nil

@trajan0x
Copy link
Contributor

@golangisfun123 version of this pr deployed at 805dca0 kept crashing witht his error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x18947aa]

goroutine 224 [running]:
github.com/synapsecns/sanguine/contrib/opbot/botmd.NewBot.(*Bot).rfqRefund.func5(0xc00cd3ec80)
	/__w/sanguine/sanguine/contrib/opbot/botmd/commands.go:212 +0x22a
github.com/synapsecns/sanguine/contrib/opbot/botmd.NewBot.(*Bot).metricsMiddleware.func3.1(0xc00cd3ec80)
	/__w/sanguine/sanguine/contrib/opbot/botmd/middleware.go:113 +0x24f
github.com/synapsecns/sanguine/contrib/opbot/botmd.NewBot.(*Bot).tracingMiddleware.func2.1(0xc00cd3ec80)
	/__w/sanguine/sanguine/contrib/opbot/botmd/middleware.go:35 +0x432
github.com/slack-io/slacker.executeCommand(0xc00cd3ec80, 0xc00c9cb810?, {0xc00c110850, 0xc00bf42970?, 0xc00c88cc80?})
	/github/home/go/pkg/mod/github.com/slack-io/[email protected]/executors.go:12 +0x62
github.com/slack-io/slacker.(*Slacker).handleMessageEvent(0xc00c89e6c0, {0x2766968, 0xc00c9cb810}, {0x1e65940?, 0xc00b535980?})
	/github/home/go/pkg/mod/github.com/slack-io/[email protected]/slacker.go:525 +0x4a6
created by github.com/slack-io/slacker.(*Slacker).Listen.func1 in goroutine 92
	/github/home/go/pkg/mod/github.com/slack-io/[email protected]/slacker.go:287 +0xaf3

Also, anecdotally rfq command was erroring a lot, I think b/c of status endpoint mismatch or something:

image

@trajan0x trajan0x linked an issue Aug 20, 2024 that may be closed by this pull request
@golangisfun123
Copy link
Collaborator Author

gonna redo this after #3057 and #3038

@github-actions github-actions bot deleted the fix-opbot-error branch August 26, 2024 20:17
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/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[opbot] refund fails if relayer is down
2 participants