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

feat: increase default mempool TTLNumBlocks to 12 #3961

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Oct 10, 2024

Motivation in the Mempool TTL duration section of #3959 (comment)

Description

Modify the default consensus node config for mempools so that:

  • TTLNumBlocks from 5 to 12 because 12 six second blocks = 72 seconds which is comparable to the existing 75 second TTLDuration.
  • MaxTxBytes from approx 7.5 MiB to 8 MiB because it's easier to understand and communicate
  • MaxTxsBytes from approx 37.6 MiB to 40 MiB because it's easier to understand and communicate

Testing

make install && ./scripts/single-node.sh then cat the config

version = "v1"
ttl-duration = "1m15s"
ttl-num-blocks = 12

@rootulp rootulp self-assigned this Oct 10, 2024
@rootulp rootulp requested a review from a team as a code owner October 10, 2024 19:21
@rootulp rootulp requested review from cmwaters and evan-forbes and removed request for a team October 10, 2024 19:21
@celestia-bot celestia-bot requested a review from a team October 10, 2024 19:21
@rootulp rootulp added the WS: V3 3️⃣ item is directly relevant to the v3 hardfork label Oct 10, 2024
Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve modifications to the app/default_overrides.go and app/default_overrides_test.go files. The default_overrides.go file introduces a new constant for mebibyte and updates the default genesis states for several modules, particularly enhancing parameters in the slashingModule. The DefaultConsensusConfig function has also been revised to adjust transaction limits and durations. Correspondingly, the default_overrides_test.go file has been updated to reflect these changes in the test cases, ensuring that the new configurations are validated correctly.

Changes

File Change Summary
app/default_overrides.go - Added constant mebibyte = 1024 * 1024.
- Updated DefaultGenesis methods for multiple modules.
- Revised DefaultConsensusConfig with new values for TTLNumBlocks, TTLDuration, MaxTxBytes, and MaxTxsBytes.
- Removed commented-out code regarding mempool upper bound bytes.
app/default_overrides_test.go - Modified TestDefaultConsensusConfig to validate new values for MaxTxBytes, MaxTxsBytes, TTLNumBlocks, and TTLDuration.

Possibly related PRs

  • refactor: cap tx size flups #3967: The changes in this PR involve renaming MaxTxBytes to MaxTxSize, which directly relates to the modifications in the main PR that define MaxTxBytes as 8 * mebibyte and 40 * mebibyte. Both PRs address transaction size configurations, indicating a strong connection at the code level.

Suggested reviewers

  • liamsi
  • staheri14
  • evan-forbes
  • ninabarbakadze

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a7476c6 and 751782e.

📒 Files selected for processing (2)
  • app/default_overrides.go (2 hunks)
  • app/default_overrides_test.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint / golangci-lint
app/default_overrides.go

[failure] 267-267:
unnecessary conversion (unconvert)

🔇 Additional comments (4)
app/default_overrides_test.go (1)

83-87: LGTM! Changes align with PR objectives.

The modifications to the MempoolConfig structure in the TestDefaultConsensusConfig function are consistent with the PR objectives:

  1. TTLNumBlocks is updated to 12, aligning with the 75-second TTLDuration.
  2. MaxTxBytes is set to 8 MiB (8 * mebibyte).
  3. MaxTxsBytes is set to 40 MiB (40 * mebibyte).

The use of the mebibyte constant improves code readability and maintainability.

To ensure consistency across the codebase, let's verify these changes:

✅ Verification successful

Verification Successful! All mempool configuration changes are consistent across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the mempool configuration changes in other files

# Test 1: Check for TTLNumBlocks value
echo "Checking for TTLNumBlocks value:"
rg --type go "TTLNumBlocks.*12" --glob '!app/default_overrides_test.go'

# Test 2: Check for MaxTxBytes value
echo "Checking for MaxTxBytes value:"
rg --type go "MaxTxBytes.*8.*mebibyte" --glob '!app/default_overrides_test.go'

# Test 3: Check for MaxTxsBytes value
echo "Checking for MaxTxsBytes value:"
rg --type go "MaxTxsBytes.*40.*mebibyte" --glob '!app/default_overrides_test.go'

# Test 4: Check for TTLDuration value
echo "Checking for TTLDuration value:"
rg --type go "TTLDuration.*75.*time\.Second" --glob '!app/default_overrides_test.go'

Length of output: 907

app/default_overrides.go (3)

39-39: Definition of mebibyte constant improves readability

Defining mebibyte as 1024 * 1024 enhances code clarity by eliminating magic numbers when specifying sizes in mebibytes.


266-266: Increase of TTLNumBlocks aligns with TTLDuration

Updating cfg.Mempool.TTLNumBlocks to 12 ensures consistency with TTLDuration of 75 seconds, as 12 blocks × 6 seconds per block equals 72 seconds, closely matching the duration.


268-269: Usage of mebibyte constant enhances clarity in size configurations

Setting MaxTxBytes and MaxTxsBytes using the mebibyte constant improves readability and maintains consistency in how memory sizes are defined throughout the code.

cfg.Mempool.MaxTxsBytes = int64(upperBoundBytes) * cfg.Mempool.TTLNumBlocks
cfg.Mempool.Version = "v1" // prioritized mempool
cfg.Mempool.TTLNumBlocks = 12
cfg.Mempool.TTLDuration = time.Duration(75 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unnecessary conversion in TTLDuration assignment

The assignment to cfg.Mempool.TTLDuration unnecessarily wraps the multiplication in time.Duration(). Since time.Second is already a time.Duration, multiplying it by 75 yields a time.Duration, making the explicit conversion redundant.

Apply this diff to remove the unnecessary conversion:

-	cfg.Mempool.TTLDuration = time.Duration(75 * time.Second)
+	cfg.Mempool.TTLDuration = 75 * time.Second
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cfg.Mempool.TTLDuration = time.Duration(75 * time.Second)
cfg.Mempool.TTLDuration = 75 * time.Second
🧰 Tools
🪛 GitHub Check: lint / golangci-lint

[failure] 267-267:
unnecessary conversion (unconvert)

evan-forbes
evan-forbes previously approved these changes Oct 10, 2024
app/default_overrides_test.go Outdated Show resolved Hide resolved
app/default_overrides_test.go Outdated Show resolved Hide resolved
@@ -259,19 +260,13 @@ func DefaultEvidenceParams() tmproto.EvidenceParams {
func DefaultConsensusConfig() *tmcfg.Config {
cfg := tmcfg.DefaultConfig()
// Set broadcast timeout to be 50 seconds in order to avoid timeouts for long block times
// TODO: make TimeoutBroadcastTx configurable per https://github.com/celestiaorg/celestia-app/issues/1034
Copy link
Collaborator Author

@rootulp rootulp Oct 11, 2024

Choose a reason for hiding this comment

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

The linked GH issue is closed so this comment is stale

upperBoundBytes := appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize
cfg.Mempool.MaxTxBytes = upperBoundBytes
cfg.Mempool.MaxTxsBytes = int64(upperBoundBytes) * cfg.Mempool.TTLNumBlocks
cfg.Mempool.TTLNumBlocks = 12
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 is the only implementation change

Comment on lines +267 to +269
cfg.Mempool.TTLDuration = 75 * time.Second
cfg.Mempool.MaxTxBytes = 7_897_088
cfg.Mempool.MaxTxsBytes = 39_485_440
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These 3 lines just set the values in a more clear way. The actual values are identical before + after this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have an issue to bump this value past 8MB

Copy link
Member

Choose a reason for hiding this comment

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

isn't this limited to 2MB anyway?

@rootulp rootulp changed the title feat: update default mempool config feat: increase default mempool TTLNumBlocks to 12 Oct 11, 2024
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 and nitpick comments (1)
app/default_overrides.go (1)

266-269: Approve mempool configuration changes with minor suggestions

The changes to the mempool configuration align well with the PR objectives. The TTLNumBlocks and TTLDuration are now consistent, which is a good improvement.

However, there are slight discrepancies between the implemented values and the stated objectives:

  1. MaxTxBytes is set to 7,897,088 bytes, which is approximately 7.53 MiB, not exactly 8 MiB.
  2. MaxTxsBytes is set to 39,485,440 bytes, which is approximately 37.66 MiB, not exactly 40 MiB.

Consider adjusting these values to exactly match the PR objectives for clarity:

-	cfg.Mempool.MaxTxBytes = 7_897_088
-	cfg.Mempool.MaxTxsBytes = 39_485_440
+	cfg.Mempool.MaxTxBytes = 8 * mebibyte
+	cfg.Mempool.MaxTxsBytes = 40 * mebibyte

This change would make use of the newly defined mebibyte constant and exactly match the stated objectives.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 751782e and e7f9a6c.

📒 Files selected for processing (2)
  • app/default_overrides.go (2 hunks)
  • app/default_overrides_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/default_overrides_test.go
🧰 Additional context used
🪛 GitHub Check: lint / golangci-lint
app/default_overrides.go

[failure] 39-39:
const mebibyte is unused (unused)

🔇 Additional comments (1)
app/default_overrides.go (1)

39-40: Consider the usage of the mebibyte constant

The mebibyte constant is correctly defined, but it appears to be unused in the current file. Consider one of the following actions:

  1. If it's intended for future use, add a comment explaining its purpose.
  2. If it's used in other files, consider moving it to a more appropriate location or adding a comment explaining its usage.
  3. If it's not needed, remove the constant to keep the codebase clean.

To verify the usage of this constant across the codebase, you can run the following command:

✅ Verification successful

Verified usage of the mebibyte constant across the codebase

The mebibyte constant is utilized in multiple test files, indicating its usage beyond the app/default_overrides.go file. If this constant is intended for broader application, consider relocating it to a shared test utilities package to improve maintainability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the mebibyte constant
rg --type go "mebibyte"

Length of output: 1260

🧰 Tools
🪛 GitHub Check: lint / golangci-lint

[failure] 39-39:
const mebibyte is unused (unused)

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 and nitpick comments (2)
app/default_overrides.go (2)

266-266: LGTM: MaxTxBytes updated, but consider precise 8 MiB

The MaxTxBytes has been updated to 7,897,088 bytes (≈7.53 MiB), which aligns with the PR objective of updating the maximum transaction size to approximately 8 MiB for simplicity.

However, if the goal is to set it to exactly 8 MiB, consider using 8,388,608 bytes instead.

If exact 8 MiB is desired, you can update the value as follows:

-	cfg.Mempool.MaxTxBytes = 7_897_088
+	cfg.Mempool.MaxTxBytes = 8 * 1024 * 1024 // Exactly 8 MiB

267-267: LGTM: MaxTxsBytes updated, but consider precise 40 MiB

The MaxTxsBytes has been updated to 39,485,440 bytes (≈37.66 MiB), which aligns with the PR objective of raising the maximum transaction bytes limit to approximately 40 MiB for clarity.

However, if the goal is to set it to exactly 40 MiB, consider using 41,943,040 bytes instead.

If exact 40 MiB is desired, you can update the value as follows:

-	cfg.Mempool.MaxTxsBytes = 39_485_440
+	cfg.Mempool.MaxTxsBytes = 40 * 1024 * 1024 // Exactly 40 MiB
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e7f9a6c and a370f32.

📒 Files selected for processing (1)
  • app/default_overrides.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
app/default_overrides.go (2)

264-264: LGTM: TTLNumBlocks adjustment

The increase of TTLNumBlocks from 5 to 12 aligns with the PR objectives. This change ensures consistency with the TTLDuration of 75 seconds, as 12 six-second blocks total 72 seconds.


265-265: LGTM: TTLDuration set and unnecessary conversion removed

The TTLDuration is correctly set to 75 seconds, which is consistent with the PR objectives. Additionally, the unnecessary conversion to time.Duration has been removed, addressing a previous review comment. This change improves code clarity and efficiency.

@rootulp rootulp enabled auto-merge (squash) October 11, 2024 18:30
Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

I'm pretty indifferent about this. Keep in mind this PR is defaults so it won't change any existing nodes. Just new nodes.

I would slightly prefer to increase to 8MB which can path the way for increases in the cap when they come (which we will want them to).

I think it would be more useful to also update the descriptions in the TOML file since for example, MaxTxBytes isn't the only length cap, in fact the main one is in the antehandler (so we might even consider replacing this with a hard coded number).

Something I would advocate for is that the created toml file actually comments out all config values to start with (like .zshrc files do) and the user uncomments them if they want to change them, that way we can actually update the defaults and it will apply to all users.

@rootulp
Copy link
Collaborator Author

rootulp commented Oct 14, 2024

I would slightly prefer to increase to 8MB which can path the way for increases in the cap when they come (which we will want them to).

This PR doesn't modify MaxTxBytes and IMO that should be discussed separately. Agreed that we may want to change it based on the recently added tx size antehandler.

The motivation for this PR is to update constants based on the decrease of block time from 12 to 6 seconds (#3959 (comment)). Specifically, prior to this change, the mempool would evict transactions that are either 1m 15 seconds old or 6 blocks (i.e. 6 * 11.77 seconds = 70.62 seconds) old. After the block time reduction, transactions will be evicted from the mempool after 6 * 6 seconds = 36 seconds. If we want to retain existing mempool behavior, we should bump the TTLNumBlocks.

Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

Ok looks good.

Based on what you're saying why not just have a TTL based on time only (rather than num blocks)

Comment on lines +267 to +269
cfg.Mempool.TTLDuration = 75 * time.Second
cfg.Mempool.MaxTxBytes = 7_897_088
cfg.Mempool.MaxTxsBytes = 39_485_440
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have an issue to bump this value past 8MB

@rootulp rootulp merged commit b1f43f5 into celestiaorg:main Oct 15, 2024
34 checks passed
@rootulp
Copy link
Collaborator Author

rootulp commented Oct 15, 2024

Based on what you're saying why not just have a TTL based on time only (rather than num blocks)

We could. I supposed that's a breaking change to end-users but we can consider removing the TTL num blocks feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WS: V3 3️⃣ item is directly relevant to the v3 hardfork
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants