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

chore: move v2 consts to v2 directory #3040

Merged
merged 6 commits into from
Jan 24, 2024

Conversation

ninabarbakadze
Copy link
Member

@ninabarbakadze ninabarbakadze commented Jan 24, 2024

Overview

moving GlobalMinGasPrice constant under v2

Fixes - #3035

@ninabarbakadze ninabarbakadze marked this pull request as ready for review January 24, 2024 17:44
Copy link
Contributor

coderabbitai bot commented Jan 24, 2024

Warning

Rate Limit Exceeded

@ninabarbakadze has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 6 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 28d04e9 and acf523f.

Walkthrough

The codebase has undergone a refactoring process that affects how the global minimum gas price is handled. The GlobalMinGasPrice constant has been moved from its initial location to a new versioned package, v2. All references to this constant have been updated across various files to reflect its new location. Additionally, the original declaration has been replaced with a new default value where it was previously used. A new variable appVersion has been introduced to store the application version obtained from the context's block header.

Changes

File(s) Change Summary
app/ante/fee_checker.go
app/ante/min_fee_test.go
Imported v2 of appconsts and updated reference to GlobalMinGasPrice. Replaced references to GlobalMinGasPrice with v2.GlobalMinGasPrice.
pkg/appconsts/initial_consts.go Removed GlobalMinGasPrice and replaced its usage with DefaultMinGasPrice.
pkg/appconsts/v2/app_consts.go Introduced new GlobalMinGasPrice constant with a value of 0.002 to enforce a minimum gas price for transactions.
pkg/appconsts/versioned_consts.go Modified to include a new function GlobalMinGasPrice that returns a float value and an error based on the input version. Imported the fmt package.

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 comments 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

pkg/appconsts/v2/app_consts.go Outdated Show resolved Hide resolved
app/ante/fee_checker.go Outdated Show resolved Hide resolved
rootulp
rootulp previously approved these changes Jan 24, 2024
@@ -29,7 +30,7 @@ func CheckTxFeeWithGlobalMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, in
// global minimum fee only applies to app versions greater than one
if ctx.BlockHeader().Version.App > v1.Version {
// convert the global minimum gas price to a big.Int
globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", appconsts.GlobalMinGasPrice))
globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice))
Copy link
Collaborator

Choose a reason for hiding this comment

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

[not blocking][question] if the constant is now app version specific, should we define a getter like this in versioned_consts.go:

func GlobalMinGasPrice(version uint64) (float64, error) {
	switch version {
	case v2.Version:
		return v2.GlobalMinGasPrice, nil
	default:
		return 0, fmt.Errorf("global min gas price not defined for version %d", version)
	}
}

and then use here

	// global minimum fee only applies to app versions greater than one
	if ctx.BlockHeader().Version.App > v1.Version {
		gmgp, err := appconsts.GlobalMinGasPrice(ctx.BlockHeader().Version.App)
		if err != nil {
			return nil, 0, errors.Wrap(err, "invalid GlobalMinGasPrice")
		}

		// convert the global minimum gas price to a big.Int
		globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", gmgp))
		if err != nil {
			return nil, 0, errors.Wrap(err, "invalid GlobalMinGasPrice")
		}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Feel free to rename variables, add godocs, etc. Mostly for illustrative purposes ^

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks for the review and suggestions! I completely missed the versioned_consts.go file 🤦🏻‍♀️ updated now

Copy link
Collaborator

Choose a reason for hiding this comment

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

No problemo. I wonder if the appconsts in v1 and v2 should actually be un-exported so that consumers are forced to use the getters rather than hard-coding a particular versioned constant.

I know Callum found a few instances where code was relying on a default or a particular versioned constant rather than querying for a versioned constant based on app version. Can discuss more outside this PR if maintainers think we should pursue this idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I think making them unexported makes sense. we should probably go through the app and replace all hardcoded values with getters+constants based on app version as you suggested. cc @cmwaters @evan-forbes

Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

Looks good to me! I've added a suggestion to consider treating the GlobalMinGasPrice in a manner similar to other versioned constants.

app/ante/fee_checker.go Outdated Show resolved Hide resolved
rootulp
rootulp previously approved these changes Jan 24, 2024
app/ante/min_fee_test.go Outdated Show resolved Hide resolved
Comment on lines +27 to +36
// GlobalMinGasPrice is used in the processProposal to ensure
// that all transactions have a gas price greater than or equal to this value.
func GlobalMinGasPrice(version uint64) (float64, error) {
switch version {
case v2.Version:
return v2.GlobalMinGasPrice, nil
default:
return 0, fmt.Errorf("global min gas price not defined for version %d", version)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] add tests in versioned_consts_test.go. The unit test may look crazy simple for now but I expect it may be more helpful down the line when we introduce new app versions.

Copy link
Member Author

Choose a reason for hiding this comment

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

sanaz already approved the changes but I'm almost done and will push it in another pr

Co-authored-by: Rootul P <[email protected]>
@ninabarbakadze ninabarbakadze merged commit b1592c3 into celestiaorg:main Jan 24, 2024
28 of 29 checks passed
@ninabarbakadze ninabarbakadze deleted the nina/v2-constants branch January 24, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants