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

refactor: make mebibyte a constant #4225

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ZwangaMukwevho
Copy link

@ZwangaMukwevho ZwangaMukwevho commented Jan 14, 2025

Overview

This PR refactors the use of mebibyte by centralizing it as a constant to avoid redundant declarations and improve code maintainability. This aligns with DRY principles, ensuring consistency and simplifying future updates.

Issue: #4211

@ZwangaMukwevho ZwangaMukwevho requested a review from a team as a code owner January 14, 2025 22:37
@ZwangaMukwevho ZwangaMukwevho requested review from rach-id and ninabarbakadze and removed request for a team January 14, 2025 22:37
Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

📝 Walkthrough

Walkthrough

The pull request standardizes the usage of the Mebibyte constant across various files in the Celestia App project. It removes local definitions of the mebibyte constant and replaces them with a centralized app.Mebibyte or testnode.Mebibyte. This modification affects multiple test files and configuration settings, ensuring consistent representation of the value 1,048,576 bytes throughout the codebase. Additionally, some parameter names have been updated for clarity, while the overall logic and functionality remain unchanged.

Changes

File Change Summary
app/benchmarks/benchmark_msg_send_test.go Removed local mebibyte constant; updated block size calculation to use Mebibyte.
app/default_overrides.go Added new exported Mebibyte constant; updated configuration settings to use Mebibyte.
app/default_overrides_test.go Added app package import; replaced mebibyte with Mebibyte in test assertions.
app/test/big_blob_test.go Updated configuration parameters to use app.Mebibyte.
app/test/integration_test.go Modified maximum transaction size check to use app.Mebibyte.
app/test/unit_test.go Deleted mebibyte constant.
test/util/testnode/comet_node_test.go Renamed mebibyte to Mebibyte.
test/util/testnode/config.go Changed mebibyte constant to uppercase Mebibyte.
x/blob/ante/blob_share_decorator_test.go Updated comment for mebibyte constant.
x/blob/ante/max_total_blob_size_ante_test.go Updated blob size references to use Mebibyte.
pkg/da/data_availability_header.go Updated SquareSize parameter name from len to length.
test/txsim/blob.go Renamed NewRange parameters from min and max to minimum and maximum.
x/blob/ante/max_total_blob_size_ante.go Renamed variable max to maximum in AnteHandle method.
x/mint/types/minter_test.go Renamed parameters in randomBlockInterval and randInRange functions from min and max to minimum and maximum.

Possibly related PRs

  • test(e2e benchmark): introduces test manifest and its related utilities #3391: The changes in benchmark_msg_send_test.go and throughput.go both involve modifications related to benchmarking, specifically around constants for block sizes, indicating a potential connection in how benchmarks are structured.
  • feat: add multi-account support #3433: The introduction of the Mebibyte constant in multiple files, including big_blob_test.go, suggests a shared focus on standardizing block size calculations across tests, which aligns with the changes made in the main PR.
  • fix: export command #3450: While primarily focused on the export command, the adjustments in handling parameters and constants may relate to the overall consistency in how constants like Mebibyte are utilized across the codebase.

Suggested labels

WS: Big Blonks 🔭

Suggested reviewers

  • cmwaters
  • evan-forbes
  • rootulp
  • ninabarbakadze

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6116a94 and 1114ebe.

📒 Files selected for processing (2)
  • x/blob/ante/blob_share_decorator_test.go (4 hunks)
  • x/blob/ante/max_total_blob_size_ante_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • x/blob/ante/blob_share_decorator_test.go
  • x/blob/ante/max_total_blob_size_ante_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

🧹 Nitpick comments (2)
test/util/testnode/config.go (1)

25-25: Consider adding documentation for the exported constant.

The constant has been correctly exported. Consider adding a doc comment to describe its purpose and usage since it's now part of the package's public API.

+// Mebibyte represents the number of bytes in one mebibyte (1024 * 1024 bytes)
 Mebibyte                    = 1_048_576 // bytes
x/blob/ante/blob_share_decorator_test.go (1)

Line range hint 25-25: Great refactoring that aligns with DRY principles!

The centralization of the mebibyte constant improves code maintainability by:

  1. Eliminating redundant declarations
  2. Reducing the risk of inconsistencies
  3. Making future updates easier to manage

Consider documenting this constant in the package documentation to help other developers understand its purpose and proper usage.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d906c7 and 7cf298a.

📒 Files selected for processing (10)
  • app/benchmarks/benchmark_msg_send_test.go (1 hunks)
  • app/default_overrides.go (3 hunks)
  • app/default_overrides_test.go (3 hunks)
  • app/test/big_blob_test.go (1 hunks)
  • app/test/integration_test.go (1 hunks)
  • app/test/unit_test.go (0 hunks)
  • test/util/testnode/comet_node_test.go (1 hunks)
  • test/util/testnode/config.go (1 hunks)
  • x/blob/ante/blob_share_decorator_test.go (3 hunks)
  • x/blob/ante/max_total_blob_size_ante_test.go (3 hunks)
💤 Files with no reviewable changes (1)
  • app/test/unit_test.go
✅ Files skipped from review due to trivial changes (2)
  • test/util/testnode/comet_node_test.go
  • app/default_overrides.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (6)
app/default_overrides_test.go (1)

69-69: LGTM! Consistent usage of the centralized constant.

The test assertions have been correctly updated to use app.Mebibyte instead of the local constant.

Also applies to: 96-97

x/blob/ante/max_total_blob_size_ante_test.go (1)

47-47: LGTM! Consistent usage of the centralized constant.

The test cases have been correctly updated to use testnode.Mebibyte instead of the local constant.

Also applies to: 54-54, 72-72

x/blob/ante/blob_share_decorator_test.go (1)

44-44: LGTM! Consistent usage of the centralized constant.

The test cases have been correctly updated to use testnode.Mebibyte instead of the local constant.

Also applies to: 56-56, 62-62, 78-78

app/test/integration_test.go (1)

131-131: LGTM! Consistent usage of centralized constant.

The change correctly uses the centralized app.Mebibyte constant for checking transaction size against CometBFT's mempool limit.

app/benchmarks/benchmark_msg_send_test.go (1)

317-317: LGTM! Consistent usage of centralized constant.

The change correctly uses the centralized app.Mebibyte constant for calculating block size in megabytes.

app/test/big_blob_test.go (1)

42-42: LGTM! Consistent usage of centralized constant.

The changes correctly use the centralized app.Mebibyte constant for configuring:

  1. Mempool maximum transaction bytes
  2. Consensus parameters maximum block bytes

The multiplication factor of 10 is preserved, maintaining the original test parameters.

Also applies to: 45-45

rach-id
rach-id previously approved these changes Jan 15, 2025
Copy link
Member

@rach-id rach-id left a comment

Choose a reason for hiding this comment

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

Thanks a lot for helping with this. approving given CI passes.

Edit: apparently there are import cycles. Can you redefine the constant in those packages too to fix them?

@rach-id rach-id self-requested a review January 15, 2025 09:44
@rootulp rootulp marked this pull request as draft January 15, 2025 14:03
@ZwangaMukwevho ZwangaMukwevho marked this pull request as ready for review January 15, 2025 19:37
@ZwangaMukwevho
Copy link
Author

Thanks a lot for helping with this. approving given CI passes.

Edit: apparently there are import cycles. Can you redefine the constant in those packages too to fix them?

Addressed the import cycles, and other issues related to linting.

rach-id
rach-id previously approved these changes Jan 15, 2025
@celestia-bot celestia-bot requested a review from rootulp January 15, 2025 21:26
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

IMO it's fine to define it as an un-exported constant in all the packages it is used in. I'd slightly prefer that over exporting it from a package.

Not blocking on it.

Comment on lines -159 to +161
min := (14 * time.Second).Nanoseconds()
max := (16 * time.Second).Nanoseconds()
return time.Duration(randInRange(min, max))
minimum := (14 * time.Second).Nanoseconds()
maximum := (16 * time.Second).Nanoseconds()
return time.Duration(randInRange(minimum, maximum))
Copy link
Member

Choose a reason for hiding this comment

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

why were these also changed?

Comment on lines -165 to +166
func randInRange(min int64, max int64) int64 {
return rand.Int63n(max-min) + min
func randInRange(minimum int64, maximum int64) int64 {
return rand.Int63n(maximum-minimum) + minimum
Copy link
Member

Choose a reason for hiding this comment

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

same

@@ -36,6 +36,8 @@ import (
coretypes "github.com/tendermint/tendermint/types"
)

const Mebibyte = 1048576
Copy link
Member

Choose a reason for hiding this comment

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

if we want this to be a constant, then we might as well use a global constant in the constant package

Copy link
Member

Choose a reason for hiding this comment

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

that's a good idea. Where is the constant package? you mean the one in core

Copy link
Collaborator

@rootulp rootulp Jan 20, 2025

Choose a reason for hiding this comment

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

We have https://github.com/celestiaorg/celestia-app/tree/main/pkg/appconsts.

My uber nit is that we don't want Mebibyte part of the public API of any of our packages so seems fine to define it once per package as a private constant.

Copy link
Member

Choose a reason for hiding this comment

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

got you 👍 My initial motivation is just to stop writing that magic number everywhere and give it a name

Copy link
Member

Choose a reason for hiding this comment

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

My uber nit is that we don't want Mebibyte part of the public API of any of our packages so seems fine to define it once per package as a private constant.

I'm fine with whichever you prefer :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants