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

Submitter: setGasPrice() refactor #2462

Merged

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Apr 5, 2024

Summary by CodeRabbit

  • New Features

    • Improved handling of gas price settings to support dynamic pricing, including EIP-1559 transactions.
    • Added functionality to adjust gas prices based on market conditions and transaction types.
  • Bug Fixes

    • Fixed a potential issue where nil gas prices could cause errors by adding a nil check.
  • Refactor

    • Renamed BaseGasPrice to MinGasPrice across several files for clarity.
    • Updated method names and comments in the IConfig interface to reflect the new gas price terminology.
  • Tests

    • Enhanced testing for dynamic and legacy transaction gas pricing scenarios.

@dwasse dwasse requested a review from trajan0x as a code owner April 5, 2024 16:51
Copy link
Contributor

coderabbitai bot commented Apr 5, 2024

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The recent updates focus on enhancing gas price handling in the EthErgo project. Key changes include safeguarding against nil values in gas price computations, refining gas price terminology within the configuration, and improving dynamic gas price setting mechanisms. These modifications aim to provide clearer, more efficient, and flexible gas price management, especially with the incorporation of EIP-1559 support, ensuring transactions are processed smoothly across different chain types.

Changes

Files Change Summary
.../chain/gas/cmp.go Added nil check for gasPrice in BumpByPercent
.../config/config.go Renamed BaseGasPrice to MinGasPrice and updated related functions
.../config/iconfig_generated.go Updated method names and comments to reflect the new gas price terminology
.../submitter/submitter.go Enhanced setGasPrice method for dynamic/configured values and EIP-1559 support
.../submitter/submitter_test.go Updated tests for dynamic gas pricing, including new parameters and transaction handling scenarios

🐰✨

In the land of code and byte,
A rabbit hopped with all its might.
"Let's fix the gas," it said with glee,
"For smoother transactions, you and me."
With names and checks all polished bright,
Our transactions soar, a delightful sight.
🚀🌕

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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/coderabbit-overrides.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 Apr 5, 2024
@dwasse dwasse marked this pull request as draft April 5, 2024 16:51
Copy link

cloudflare-workers-and-pages bot commented Apr 5, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: a4057c5
Status:🚫  Build failed.

View logs

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 80.83333% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 47.09232%. Comparing base (412adc9) to head (a4057c5).

Files Patch % Lines
ethergo/submitter/submitter.go 88.99083% 8 Missing and 4 partials ⚠️
ethergo/submitter/config/config.go 0.00000% 8 Missing ⚠️
ethergo/chain/gas/cmp.go 0.00000% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@                         Coverage Diff                         @@
##           submitter/dynamic-tx-fees       #2462         +/-   ##
===================================================================
+ Coverage                   46.86050%   47.09232%   +0.23181%     
===================================================================
  Files                            400         400                 
  Lines                          30610       30729        +119     
  Branches                          83          83                 
===================================================================
+ Hits                           14344       14471        +127     
+ Misses                         14731       14722          -9     
- Partials                        1535        1536          +1     
Flag Coverage Δ
cctp-relayer 43.53414% <ø> (ø)
committee 63.75176% <ø> (+1.55147%) ⬆️
ethergo 61.10105% <80.83333%> (+0.65315%) ⬆️
explorer 24.80122% <ø> (ø)
omnirpc 53.23194% <ø> (+0.07605%) ⬆️
promexporter 75.91241% <ø> (ø)
rfq 29.02134% <ø> (ø)
sin-executor 61.57635% <ø> (+0.98521%) ⬆️
stiprelayer 3.33333% <ø> (ø)

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.

@dwasse dwasse marked this pull request as ready for review April 5, 2024 18:08
@github-actions github-actions bot added size/m and removed size/s labels Apr 5, 2024
@dwasse dwasse changed the title Submitter: dynamic tx fees refactor Submitter: setGasPrice() refactor Apr 5, 2024
// DefaultBaseGasPrice is the default max price of a tx.
var DefaultBaseGasPrice = big.NewInt(1 * params.GWei)
// DefaultMinGasPrice is the default min price of a tx.
var DefaultMinGasPrice = big.NewInt(10 * params.GWei)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Min gas price of 10 Gwei is an overshoot.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This makes sense- I'm confused of the intention here though in the base PR?

https://github.com/synapsecns/sanguine/pull/2432/files#diff-9cb5c46a90d8a5d8f06ab1c53594fbc934b93eaf5131c538424f0c4666f94f49R429

To me this seems like we will never set gas price below 10 gwei if no prevTx is supplied

Copy link
Contributor

Choose a reason for hiding this comment

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

The unit there is in wei

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's introduce a min value for GasPrice/GasFeeCap (DefaultMinGasPrice) and a separate one for GasTipCap. The latter one is set to 10 Wei (aka just 10) in the base PR.

@ChiTimesChi
Copy link
Collaborator

@coderabbitai review

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

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 412adc9 and 3cb6dae.
Files selected for processing (5)
  • ethergo/chain/gas/cmp.go (1 hunks)
  • ethergo/submitter/config/config.go (4 hunks)
  • ethergo/submitter/config/iconfig_generated.go (2 hunks)
  • ethergo/submitter/submitter.go (1 hunks)
  • ethergo/submitter/submitter_test.go (2 hunks)
Additional Context Used
GitHub Check Runs (1)
codecov/patch success (9)

ethergo/chain/gas/cmp.go: [warning] 110-111: ethergo/chain/gas/cmp.go#L110-L111
Added lines #L110 - L111 were not covered by tests


ethergo/submitter/config/config.go: [warning] 114-115: ethergo/submitter/config/config.go#L114-L115
Added lines #L114 - L115 were not covered by tests


ethergo/submitter/config/config.go: [warning] 118-119: ethergo/submitter/config/config.go#L118-L119
Added lines #L118 - L119 were not covered by tests


ethergo/submitter/config/config.go: [warning] 122-123: ethergo/submitter/config/config.go#L122-L123
Added lines #L122 - L123 were not covered by tests


ethergo/submitter/config/config.go: [warning] 221-222: ethergo/submitter/config/config.go#L221-L222
Added lines #L221 - L222 were not covered by tests


ethergo/submitter/submitter.go: [warning] 375-376: ethergo/submitter/submitter.go#L375-L376
Added lines #L375 - L376 were not covered by tests


ethergo/submitter/submitter.go: [warning] 466-467: ethergo/submitter/submitter.go#L466-L467
Added lines #L466 - L467 were not covered by tests


ethergo/submitter/submitter.go: [warning] 511-512: ethergo/submitter/submitter.go#L511-L512
Added lines #L511 - L512 were not covered by tests


ethergo/submitter/submitter.go: [warning] 527-528: ethergo/submitter/submitter.go#L527-L528
Added lines #L527 - L528 were not covered by tests

Additional comments not posted (4)
ethergo/submitter/config/config.go (1)

31-38: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [34-56]

Please ensure that the renaming from BaseGasPrice to MinGasPrice is covered by unit tests, particularly for the GetMinGasPrice and SetMinGasPrice methods.

Would you like assistance in creating or updating the tests to cover these changes?

ethergo/submitter/submitter_test.go (1)

30-208: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [9-205]

Ensure comprehensive test coverage for the new gas pricing logic, including scenarios for legacy and dynamic transactions, to validate the changes thoroughly.

ethergo/submitter/submitter.go (2)

391-424: Ensure null safety for prevTx.GasPrice(), prevTx.GasFeeCap(), and prevTx.GasTipCap() in bumpGasFromPrevTx.

Consider adding null checks for prevTx.GasPrice(), prevTx.GasFeeCap(), and prevTx.GasTipCap() before using them to prevent potential null pointer dereferences.


494-519: Verify the logic in applyGasCeil for handling gas tip cap exceeding gas fee cap.

Ensure that the logic in applyGasCeil correctly handles scenarios where the gas tip cap exceeds the gas fee cap, especially in dynamic transactions. This is crucial for maintaining transaction validity and preventing unexpected costs.

ethergo/submitter/submitter.go Outdated Show resolved Hide resolved
ethergo/submitter/submitter.go Show resolved Hide resolved
ethergo/submitter/submitter.go Show resolved Hide resolved
ethergo/submitter/config/iconfig_generated.go Show resolved Hide resolved
ethergo/chain/gas/cmp.go Show resolved Hide resolved
// GetBaseGasPrice returns the maximum gas price to use for transactions.
func (c *Config) GetBaseGasPrice(chainID int) (basePrice *big.Int) {
basePrice = c.BaseGasPrice
// GetMinGasPrice returns the maximum gas price to use for transactions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// GetMinGasPrice returns the maximum gas price to use for transactions.
// GetMinGasPrice returns the minimum gas price to use for transactions.

@aureliusbtc aureliusbtc merged commit ba5f437 into submitter/dynamic-tx-fees Apr 6, 2024
55 of 57 checks passed
@aureliusbtc aureliusbtc deleted the submitter/dynamic-tx-fees-refactor branch April 6, 2024 01:08
aureliusbtc added a commit that referenced this pull request Apr 6, 2024
* attempt to fix dynamic gas fees bumping

* [goreleaser]

* metrics sync

* [goreleaser]

* allow zero gas tip cap [goreleaser]

* fix errors [goreleaser]

* [goreleaser] fix interface

* fix [goreleaser]

* [goreleaser] fix tx

* 1 wei->10 wei [goreleaser]

* Revert "1 wei->10 wei [goreleaser]"

This reverts commit 21abb18.

* Revert "[goreleaser] fix tx"

This reverts commit 94d3d6d.

* revert bumpDynamicTxFees to master

* newFeeCap [goreleaser]

* f

* [goreleaser] revert me extremely, extremely aggressive printing

* [goreleaser]

* [goreleaser]

* Revert "[goreleaser] revert me extremely, extremely aggressive printing"

This reverts commit e961d54.

* return nil a

* [goreleaser]

* Fix: check for eip1559 before flooring GasTipCap

* [goreleaser]

* Submitter: setGasPrice() refactor (#2462)

* Feat: initial refactor of setGasPrice()

* Feat: add more tracing

* Cleanup: comments

* Feat: BaseGasPrice -> MinGasPrice

* Cleanup: remove applyMinGasPrice()

* Feat: initial test cases

* Feat: add WithOracleOverride cases

* Feat: add PrevTx cases

* Feat: add assertGasValues() helper

* Cleanup: pass useDynamic to applyGasFloor()

* Feat: remove old submitter test

* Cleanup: lint

* [goreleaser]

* Cleanup: populateFromPrevTx() -> bumpFromPrevTx()

* Feat: cap GasTipCap by GasFeeCap

* [goreleaser]

* Feat: default min gas price to 1 gwei

* [goreleaser]

* Feat: add minTipCap var

* Fix: minTipCap = 10 wei

* Cleanup: comment

* [goreleaser]

* Fix: test

---------

Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com>
Co-authored-by: Daniel Wasserman <wassermandaniel8@gmail.com>
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 needs-go-generate-ethergo size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants