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

RFQ Relayer: support pointers for config values #2913

Merged
merged 7 commits into from
Jul 28, 2024
Merged

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Jul 24, 2024

If a zero value is specified in a config field, it won't be overridden as a base or default value (assuming the field is a pointer).

Summary by CodeRabbit

  • New Features

    • Enhanced configuration management by allowing certain fields to accept pointer types, enabling the representation of uninitialized states.
    • Introduced a new helper function to facilitate pointer handling for configuration values.
  • Bug Fixes

    • Updated test cases to ensure proper validation of configuration parameters with the new pointer-based approach.
  • Refactor

    • Streamlined logic for configuration handling by replacing outdated functions with clearer alternatives focused on pointer dereferencing.

Copy link
Contributor

coderabbitai bot commented Jul 24, 2024

Warning

Rate limit exceeded

@trajan0x has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 56 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 756fcc3 and e178edb.

Walkthrough

The recent changes enhance the configuration management in the ChainConfig structure by converting certain float64 fields to pointer types (*float64). This adjustment allows for better handling of optional values by enabling the representation of nil, which indicates unset or absent values. Alongside these structural changes, the test cases and getter functions have been updated to support pointer dereferencing, improving the robustness and clarity of the configuration logic.

Changes

Files Change Summary
.../relayer/relconfig/config.go Updated ChainConfig struct fields from float64 to *float64 to allow nil values.
.../relayer/relconfig/config_test.go Adjusted test cases to utilize *float64 pointers, replacing direct float values and updating assertions.
.../relayer/relconfig/getters.go Introduced NewFloatPtr function; replaced isNonZero with isNilOrZero for better nil checks.
.../relayer/pricer/fee_pricer_test.go Modified tests to use relconfig.NewFloatPtr() for fixed fee multipliers, enhancing pointer handling.
.../relayer/quoter/quoter_test.go Updated QuotePct in tests to use a pointer, improving configuration management.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Config
    participant Getter

    Client->>Getter: Request Configuration
    Getter->>Config: Retrieve ChainConfig
    Config->>Getter: Return ChainConfig
    Getter->>Client: Provide Configuration
Loading

🐇 In the garden, changes bloom,
Fields now point to values' room.
Nil can dance where none exists,
A pointer's grace, the code insists.
Celebrate with hops and cheer,
Robust configs, we hold dear! 🌸


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.

@github-actions github-actions bot added go Pull requests that update Go code size/s labels Jul 24, 2024
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

Support for pointers in config values has been added to prevent zero values from being overridden by default values.

  • Updated services/rfq/relayer/relconfig/config.go to use pointers for QuotePct, QuoteFixedFeeMultiplier, and RelayFixedFeeMultiplier fields.
  • Modified services/rfq/relayer/relconfig/config_test.go to align test cases with pointer-based config fields.
  • Enhanced services/rfq/relayer/relconfig/getters.go with NewFloatPtr function and updated utility functions for pointer handling.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ebf43d and aa87eab.

Files selected for processing (3)
  • services/rfq/relayer/relconfig/config.go (1 hunks)
  • services/rfq/relayer/relconfig/config_test.go (7 hunks)
  • services/rfq/relayer/relconfig/getters.go (4 hunks)
Additional comments not posted (11)
services/rfq/relayer/relconfig/config.go (3)

93-93: Approved: Change QuotePct to *float64.

Changing QuotePct to a pointer type allows for better handling of optional values by enabling the representation of nil, indicating unset or absent values.


98-98: Approved: Change QuoteFixedFeeMultiplier to *float64.

Changing QuoteFixedFeeMultiplier to a pointer type allows for better handling of optional values by enabling the representation of nil, indicating unset or absent values.


100-100: Approved: Change RelayFixedFeeMultiplier to *float64.

Changing RelayFixedFeeMultiplier to a pointer type allows for better handling of optional values by enabling the representation of nil, indicating unset or absent values.

services/rfq/relayer/relconfig/config_test.go (3)

34-34: Approved: Utilize relconfig.NewFloatPtr for QuotePct.

Using relconfig.NewFloatPtr to create a pointer to a float64 value ensures that the test cases correctly validate the new pointer-based structure of the configuration.


36-36: Approved: Utilize relconfig.NewFloatPtr for QuoteFixedFeeMultiplier.

Using relconfig.NewFloatPtr to create a pointer to a float64 value ensures that the test cases correctly validate the new pointer-based structure of the configuration.


285-293: Approved: Dereference pointer values in GetQuoteFixedFeeMultiplier assertions.

Dereferencing pointer values in the assertions ensures that the tests correctly validate the new pointer-based structure of the configuration.

services/rfq/relayer/relconfig/getters.go (5)

27-29: Approved: Add NewFloatPtr function.

The NewFloatPtr function is straightforward and correctly implemented, returning a pointer to a float64 value.


101-106: Approved: Add isNilOrZero function.

The isNilOrZero function correctly handles both nil and zero checks, replacing the previous isNonZero function.


93-99: Approved: Add derefPointer function.

The derefPointer function is correctly implemented, ensuring that the correct underlying value is accessed if the pointer is not nil.


42-59: Approved: Update getChainConfigValue function.

The updates to the getChainConfigValue function ensure that it can handle cases where configuration values are not set, providing a more accurate representation of the configuration state.


347-347: Approved: Update GetQuoteFixedFeeMultiplier function.

The updates to the GetQuoteFixedFeeMultiplier function ensure that it correctly handles the new pointer-based structure and provides a default value if the configuration value is not set.

Copy link

cloudflare-workers-and-pages bot commented Jul 24, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: e178edb
Status: ✅  Deploy successful!
Preview URL: https://dc4e4d26.sanguine-fe.pages.dev
Branch Preview URL: https://feat-config-zero.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Jul 24, 2024

Codecov Report

Attention: Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 25.72432%. Comparing base (bda3181) to head (e178edb).
Report is 9 commits behind head on master.

Files Patch % Lines
services/rfq/relayer/relconfig/getters.go 95.00000% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2913         +/-   ##
===================================================
+ Coverage   25.71336%   25.72432%   +0.01095%     
===================================================
  Files            770         770                 
  Lines          55512       55535         +23     
  Branches          80          80                 
===================================================
+ Hits           14274       14286         +12     
- Misses         39760       39771         +11     
  Partials        1478        1478                 
Flag Coverage Δ
opbot 0.48900% <ø> (ø)
rfq 24.86275% <95.00000%> (+0.09889%) ⬆️

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

@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)

Recent changes enhance configuration management by supporting pointer types for certain fields, ensuring zero values are not overridden by defaults.

  • Updated services/rfq/relayer/pricer/fee_pricer_test.go to use pointer-based configuration for QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier.
  • Modified services/rfq/relayer/quoter/quoter_test.go to validate the new pointer-based configuration approach.
  • Ensured test cases reflect the new pointer-based configuration handling, particularly for fields that can represent uninitialized states.

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

Outside diff range, codebase verification and nitpick comments (1)
services/rfq/relayer/pricer/fee_pricer_test.go (1)

265-266: Ensure proper handling of nil pointers for fixed fee multipliers.

The fixed fee multipliers are now pointers. Ensure that the code correctly handles nil values to avoid potential nil pointer dereference errors.

  • In services/rfq/relayer/relconfig/getters.go, both GetQuoteFixedFeeMultiplier and GetRelayFixedFeeMultiplier functions dereference the default multiplier without checking for nil. This could lead to nil pointer dereference errors if DefaultChainConfig.QuoteFixedFeeMultiplier is nil.
  • In services/rfq/relayer/pricer/fee_pricer.go, the multipliers are used directly after being fetched, but the nil check is implicit through error handling from the getter functions.

Recommendations:

  • Add nil checks before dereferencing DefaultChainConfig.QuoteFixedFeeMultiplier and DefaultChainConfig.RelayFixedFeeMultiplier in the getter functions.
  • Ensure that any default values set in the configuration are not nil.

Code Locations:

  • services/rfq/relayer/relconfig/getters.go:
    • func (c Config) GetQuoteFixedFeeMultiplier(chainID int) (value float64, err error) { (line 336)
    • func (c Config) GetRelayFixedFeeMultiplier(chainID int) (value float64, err error) { (line 353)
Analysis chain

Ensure proper handling of nil pointers for fixed fee multipliers.

The fixed fee multipliers are now pointers. Ensure that the code correctly handles nil values to avoid potential nil pointer dereference errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of fixed fee multipliers handle nil values correctly.

# Test: Search for usages of `QuoteFixedFeeMultiplier` and `RelayFixedFeeMultiplier`. Expect: Proper nil checks.
rg --type go 'QuoteFixedFeeMultiplier|RelayFixedFeeMultiplier'

Length of output: 3862


Script:

#!/bin/bash
# Extract the implementations of functions using QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier to verify nil pointer handling.

# Get the implementation of GetQuoteFixedFeeMultiplier function
ast-grep --lang go --pattern 'func (c Config) GetQuoteFixedFeeMultiplier($_) ($_, $_) {
  $$$
}' services/rfq/relayer/relconfig/getters.go

# Get the implementation of GetRelayFixedFeeMultiplier function
ast-grep --lang go --pattern 'func (c Config) GetRelayFixedFeeMultiplier($_) ($_, $_) {
  $$$
}' services/rfq/relayer/relconfig/getters.go

# Get the usage of multipliers in fee_pricer.go
rg -A 10 'GetQuoteFixedFeeMultiplier|GetRelayFixedFeeMultiplier' services/rfq/relayer/pricer/fee_pricer.go

Length of output: 3583

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aa87eab and 756fcc3.

Files selected for processing (2)
  • services/rfq/relayer/pricer/fee_pricer_test.go (4 hunks)
  • services/rfq/relayer/quoter/quoter_test.go (1 hunks)
Additional comments not posted (3)
services/rfq/relayer/quoter/quoter_test.go (1)

168-168: Ensure proper handling of nil pointers for QuotePct.

The QuotePct parameter is now a pointer. Ensure that the code correctly handles nil values to avoid potential nil pointer dereference errors.

services/rfq/relayer/pricer/fee_pricer_test.go (2)

318-318: Ensure proper handling of zero values for fixed fee multipliers.

The fixed fee multipliers are set to 0. Ensure that the code correctly handles zero values and defaults to 1 as expected.

Verification successful

Zero values for fixed fee multipliers are handled correctly.

The code ensures that when a zero or negative value is encountered for QuoteFixedFeeMultiplier or RelayFixedFeeMultiplier, it defaults to a predefined value, ensuring proper handling.

  • services/rfq/relayer/relconfig/getters.go:
    • GetQuoteFixedFeeMultiplier
    • GetRelayFixedFeeMultiplier
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of fixed fee multipliers handle zero values correctly.

# Test: Search for usages of `QuoteFixedFeeMultiplier` and `RelayFixedFeeMultiplier`. Expect: Proper handling of zero values.
rg --type go 'QuoteFixedFeeMultiplier|RelayFixedFeeMultiplier'

Length of output: 3862


Script:

#!/bin/bash
# Extract relevant code blocks from fee_pricer.go and getters.go to check handling of zero values for fixed fee multipliers.

# Extract code from fee_pricer.go where QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier are used
rg --type go -A 10 'QuoteFixedFeeMultiplier|RelayFixedFeeMultiplier' services/rfq/relayer/pricer/fee_pricer.go

# Extract code from getters.go where QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier are used
rg --type go -A 10 'QuoteFixedFeeMultiplier|RelayFixedFeeMultiplier' services/rfq/relayer/relconfig/getters.go

Length of output: 2608


299-299: Ensure proper handling of negative values for fixed fee multipliers.

The fixed fee multipliers are set to -1. Ensure that the code correctly handles negative values and defaults to 1 as expected.

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)

Recent changes enhance configuration management by supporting pointer types for certain fields, ensuring zero values are not overridden by defaults.

  • Updated services/rfq/relayer/relconfig/getters.go to handle pointer dereferencing for configuration values.
  • Introduced core.PtrTo in NewFloatPtr for creating float64 pointers.
  • Enhanced getChainConfigValue to differentiate between zero values and uninitialized states.
  • Thorough testing is essential to ensure the new pointer-based approach does not introduce bugs or unexpected behavior.

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

@dwasse dwasse merged commit 1c862e4 into master Jul 28, 2024
30 checks passed
@dwasse dwasse deleted the feat/config-zero branch July 28, 2024 15:47
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.

3 participants