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): fix refund forever #3082

Merged
merged 10 commits into from
Aug 30, 2024
Merged

fix(opbot): fix refund forever #3082

merged 10 commits into from
Aug 30, 2024

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Aug 30, 2024

#3076 first, then this

Summary by CodeRabbit

  • New Features

    • Enhanced bot functionality with the integration of a screener client for improved operational capabilities.
    • Added a new configuration option for the screener URL, expanding customization options.
    • Included sender information in quote request responses for better tracking and auditing.
  • Bug Fixes

    • Improved error handling and control flow in the refund processing logic to enhance robustness.
  • Chores

    • Updated project dependencies to include the new screener API module for local development.

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes involve the integration of a new dependency on the screener-api package, enhancing the Bot struct with a screener field. The Start method has been modified to initialize this client. Additionally, improvements have been made to error handling and control flow in the rfqRefund function, while new fields have been added to the Config struct and response models to accommodate additional data.

Changes

Files Change Summary
contrib/opbot/botmd/botmd.go, contrib/opbot/botmd/commands.go Added screener field to Bot, updated Start method for client initialization, and improved error handling in rfqRefund.
contrib/opbot/config/config.go Introduced ScreenerURL field in Config struct.
contrib/opbot/go.mod Added dependency on sanguine/contrib/screener-api and set up local path replacement.
services/rfq/relayer/relapi/handler.go, services/rfq/relayer/relapi/model.go Added Sender field to GetQuoteRequestResponse and updated related methods to include this field.

Sequence Diagram(s)

sequenceDiagram
    participant Bot
    participant ScreenerClient
    participant QuoteRequest

    Bot->>ScreenerClient: Initialize with NewClient
    Bot->>QuoteRequest: Fetch quote request
    QuoteRequest-->>Bot: Return quote request
    Bot->>ScreenerClient: Submit refund
    ScreenerClient-->>Bot: Confirmation of refund
Loading

🐇 "In the meadow, changes bloom,
A screener's song dispels the gloom.
With refunds swift and quotes so bright,
Our bot hops forth, a joyful sight!
New fields to track, new paths to tread,
In this code dance, we're never misled!"
🌼


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 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/s labels Aug 30, 2024
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

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

Project coverage is 25.04098%. Comparing base (a6e1781) to head (d5ad596).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
contrib/opbot/botmd/commands.go 0.00000% 34 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3082         +/-   ##
===================================================
+ Coverage   23.06899%   25.04098%   +1.97199%     
===================================================
  Files            193         173         -20     
  Lines          11639       10371       -1268     
  Branches          82          82                 
===================================================
- Hits            2685        2597         -88     
+ Misses          8712        7535       -1177     
+ Partials         242         239          -3     
Flag Coverage Δ
opbot 0.49813% <0.00000%> (-0.00093%) ⬇️
promexporter ?

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 30, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: d5ad596
Status: ✅  Deploy successful!
Preview URL: https://117247b5.sanguine-fe.pages.dev
Branch Preview URL: https://fix-refund-forever.sanguine-fe.pages.dev

View logs

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

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

94-99: Test coverage missing for new logic in Start method.

The recent changes to the Start method in the Bot struct, specifically the initialization of the screener client, are not covered by existing tests. Consider adding test cases to ensure this new logic is verified and robust.

Analysis chain

Updated Start method handles screener client initialization correctly.

The updates to the Start method for initializing the screener client are correctly implemented with appropriate error handling. However, the added lines are not covered by tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for the new logic in the `Start` method.

# Test: Search for test cases covering the new logic. Expect: At least one test case covering lines 94-99.
rg --type go -A 5 $'func Test.*Start.*'

Length of output: 391

Tools
GitHub Check: codecov/patch

[warning] 94-99: contrib/opbot/botmd/botmd.go#L94-L99
Added lines #L94 - L99 were 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 89871e9 and 8df64be.

Files selected for processing (7)
  • contrib/opbot/botmd/botmd.go (3 hunks)
  • contrib/opbot/botmd/commands.go (2 hunks)
  • contrib/opbot/cmd/commands.go (1 hunks)
  • contrib/opbot/config/config.go (1 hunks)
  • contrib/opbot/go.mod (2 hunks)
  • services/rfq/relayer/relapi/handler.go (2 hunks)
  • services/rfq/relayer/relapi/model.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • contrib/opbot/cmd/commands.go
Additional context used
GitHub Check: codecov/patch
contrib/opbot/botmd/botmd.go

[warning] 94-99: contrib/opbot/botmd/botmd.go#L94-L99
Added lines #L94 - L99 were not covered by tests

contrib/opbot/botmd/commands.go

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


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


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


[warning] 414-416: contrib/opbot/botmd/commands.go#L414-L416
Added lines #L414 - L416 were not covered by tests


[warning] 420-421: contrib/opbot/botmd/commands.go#L420-L421
Added lines #L420 - L421 were not covered by tests


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

GitHub Check: Lint (contrib/opbot)
contrib/opbot/botmd/commands.go

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

Additional comments not posted (6)
services/rfq/relayer/relapi/model.go (1)

20-20: Addition of Sender field is correctly implemented.

The new field Sender in the GetQuoteRequestResponse struct is correctly annotated with a JSON tag for serialization. This addition enhances the response structure by providing more contextual information.

contrib/opbot/config/config.go (1)

37-37: Addition of ScreenerURL field is correctly implemented.

The new field ScreenerURL in the Config struct is correctly annotated with a YAML tag for serialization. This addition enhances the configuration capabilities by allowing the storage of an additional parameter related to screening functionality.

contrib/opbot/botmd/botmd.go (1)

32-32: Addition of screener field is correctly implemented.

The new field screener in the Bot struct is correctly declared and is intended to enable interaction with the screener service. This addition expands the bot's capabilities significantly.

services/rfq/relayer/relapi/handler.go (2)

115-115: Addition of Sender field in GetQuoteRequestByTxID response.

The inclusion of the Sender field in the response is a useful enhancement for tracking purposes. Ensure that the Sender field is consistently populated across different scenarios and that error handling remains robust.

The code changes are approved.


145-145: Addition of Sender field in GetQuoteRequestByTxHash response.

The consistent addition of the Sender field across different retrieval functions is good for maintaining uniformity in the response structure. Verify that the Sender field is handled similarly in other related functions for consistency.

The code changes are approved.

contrib/opbot/go.mod (1)

25-25: Addition of screener-api dependency and local path replacement.

The inclusion of the screener-api module in the go.mod file is a significant change that supports the new functionality introduced in the rfqRefund function. The use of a local path replacement for this dependency suggests that the development is still in progress or that there is a need for customization that isn't addressed by the main repository.

The changes are logical and align with the functionality enhancements described in the PR. However, ensure that the local path is accessible and correctly set up in your development environment to avoid build issues.

Also applies to: 298-298

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

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

fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
log.Println(err)
}
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
})
return
}

canRefund, err := b.screener.ScreenAddress(ctx.Context(), rawRequest.Sender)
if err != nil {
_, err := ctx.Response().Reply("error screening address")
if err != nil {
log.Printf("error submitting refund: %v\n", err)
continue
log.Println(err)
}
return
}

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
if !canRefund {
_, err := ctx.Response().Reply("address cannot be refunded")
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)
return
}

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
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.

Refactor and enhance error handling in rfqRefund function.

The changes in the rfqRefund function improve the clarity and robustness of error handling by breaking out the error checks and using early returns. This makes the function easier to read and maintain. The addition of a check to see if an address can be refunded before proceeding with the transaction is a critical improvement that prevents unnecessary transactions.

However, there are several lines of code that are not covered by tests, specifically lines 326, 328, and 333. It's crucial to ensure that these lines are covered to maintain high code quality and avoid potential issues in production.

Consider adding unit tests for these lines to ensure they function as expected under various scenarios.

Tools
GitHub Check: codecov/patch

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


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


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

GitHub Check: Lint (contrib/opbot)

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

Comment on lines 414 to 424
func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (qr *relapi.GetQuoteRequestResponse, err error) {
if qr, err = client.GetQuoteRequestByTxHash(ctx, tx); err == nil {
return qr, nil
}

// look up quote request
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request: %w", err)
if qr, err = client.GetQuoteRequestByTXID(ctx, tx); err == nil {
return qr, nil
}

return qr, nil
return nil, fmt.Errorf("error fetching quote request: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify error handling in getQuoteRequest function.

The refactoring of the getQuoteRequest function to use named return values simplifies the function and makes the error handling more straightforward. This change aligns with the PR's goal to enhance readability and maintainability.

However, the new lines added in this function (414-416 and 420-421) are not covered by tests, which could lead to potential issues if edge cases are not properly handled.

It's recommended to add test coverage for these lines to ensure the function's reliability, especially since it plays a crucial role in fetching quote requests.

Tools
GitHub Check: codecov/patch

[warning] 414-416: contrib/opbot/botmd/commands.go#L414-L416
Added lines #L414 - L416 were not covered by tests


[warning] 420-421: contrib/opbot/botmd/commands.go#L420-L421
Added lines #L420 - L421 were not covered by tests


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

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8df64be and d5ad596.

Files selected for processing (1)
  • contrib/opbot/botmd/commands.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/opbot/botmd/commands.go

@trajan0x trajan0x merged commit c6953ed into master Aug 30, 2024
28 of 29 checks passed
@trajan0x trajan0x deleted the fix-refund-forever branch August 30, 2024 21:48
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.

2 participants