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(server/v2/cometbft): wire mempool config #21741

Merged
merged 3 commits into from
Sep 16, 2024
Merged

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Sep 16, 2024

Description

Closes: #21733

  • Wires mempool config
  • Make mempool and snapshots options able to get config
  • Demonstrate how to override config.toml config and set good defaults

Note, that the sdkmempool interface vs the cometbft server mempool interface differs.
Meaning, we cannot use directly the SDK mempool in the new cometbft server.

types/mempool

type Mempool interface {
	// Insert attempts to insert a Tx into the app-side mempool returning
	// an error upon failure.
	Insert(context.Context, sdk.Tx) error

	// Select returns an Iterator over the app-side mempool. If txs are specified,
	// then they shall be incorporated into the Iterator. The Iterator is not thread-safe to use.
	Select(context.Context, [][]byte) Iterator

	// SelectBy use callback to iterate over the mempool, it's thread-safe to use.
	SelectBy(context.Context, [][]byte, func(sdk.Tx) bool)

	// CountTx returns the number of transactions currently in the mempool.
	CountTx() int

	// Remove attempts to remove a transaction from the mempool, returning an error
	// upon failure.
	Remove(sdk.Tx) error
}

server/v2/cometbft/mempool

// Mempool defines the required methods of an application's mempool.
type Mempool[T transaction.Tx] interface {
	// Insert attempts to insert a Tx into the app-side mempool returning
	// an error upon failure.
	Insert(context.Context, T) error

	// Select returns an Iterator over the app-side mempool. If txs are specified,
	// then they shall be incorporated into the Iterator. The Iterator must be
	// closed by the caller.
	Select(context.Context, []T) Iterator[T]

	// Remove attempts to remove a transaction from the mempool, returning an error
	// upon failure.
	Remove([]T) error
}

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration option for mempool functionality, enhancing application configurability.
    • Added functions to customize default CometBFT configuration, including logging levels and timeout settings.
  • Refactor

    • Updated server options to allow dynamic processing of configuration settings.

These changes improve the flexibility and configurability of the application, allowing users to tailor settings to their needs.

Copy link
Contributor

@julienrbrt your pull request is missing a changelog!

Copy link
Contributor

coderabbitai bot commented Sep 16, 2024

Walkthrough

Walkthrough

The changes introduced in this pull request enhance the configuration options for the CometBFT server, particularly focusing on the mempool functionality. New configuration fields have been added, and server options have been refactored to support dynamic configuration management. Additionally, new functions for initializing server configurations have been implemented, allowing for specific adjustments to logging, timeout settings, and server options.

Changes

File Path Change Summary
server/v2/cometbft/config.go Added a new Mempool field in AppTomlConfig struct and updated DefaultAppTomlConfig to include mempool configuration.
server/v2/cometbft/options.go Refactored Mempool and SnapshotOptions fields in ServerOptions struct to use functions for dynamic configuration.
simapp/v2/simdv2/cmd/config.go Added initCometConfig and initCometOptions functions for customizing CometBFT server configuration and options.

Assessment against linked issues

Objective Addressed Explanation
Wire Mempool config in server/v2/cometbft

Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 55edf6c and 6c1ca6d.

Files selected for processing (1)
  • server/v2/cometbft/options.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • server/v2/cometbft/options.go

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>, please review it.
    -- 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 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.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Sep 16, 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)
server/v2/cometbft/flags.go (1)

54-60: LGTM! The new server flag enhances configurability.

The addition of the FlagMempoolMaxTxs server flag is a good practice to allow configuring the maximum number of transactions in the mempool. The flag is properly prefixed with the server name using the prefix function, which is consistent with the existing flags.

Suggestions for further improvement:

  • Consider adding a comment to describe the purpose of the flag, e.g., // FlagMempoolMaxTxs sets the maximum number of transactions in the mempool.
  • Consider adding a default value for the flag to provide a sensible default configuration.
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0147347 and 741842f.

Files selected for processing (9)
  • server/v2/cometbft/config.go (3 hunks)
  • server/v2/cometbft/flags.go (1 hunks)
  • server/v2/cometbft/mempool/config.go (1 hunks)
  • server/v2/cometbft/mempool/doc.go (1 hunks)
  • server/v2/cometbft/options.go (2 hunks)
  • server/v2/cometbft/server.go (4 hunks)
  • server/v2/commands.go (1 hunks)
  • simapp/v2/simdv2/cmd/commands.go (1 hunks)
  • simapp/v2/simdv2/cmd/config.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • server/v2/cometbft/mempool/doc.go
Additional context used
Path-based instructions (8)
server/v2/cometbft/mempool/config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/cometbft/options.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/cometbft/flags.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/cometbft/config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/simdv2/cmd/config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/simdv2/cmd/commands.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/commands.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/cometbft/server.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (20)
server/v2/cometbft/mempool/config.go (3)

3-3: LGTM!

The declaration of the DefaultMaxTx variable with a value of -1 is clear and appropriate. It serves as a well-defined default value for the maximum number of transactions in the mempool.


7-8: Excellent documentation!

The updated comment for the MaxTxs field provides clear and comprehensive information about its behavior. It covers all possible scenarios and helps users understand how to configure the mempool effectively.


11-15: Great addition!

The DefaultConfig() function is a valuable addition to the package. It provides a convenient way to obtain a default configuration for the mempool, enhancing usability and reducing the chances of misconfiguration.

server/v2/cometbft/options.go (4)

12-12: LGTM!

The comment provides a clear and concise explanation of the purpose and functionality of the ServerOptions struct fields.


14-14: Excellent change to improve configurability!

The modification of the Mempool field to be a function that accepts a configuration map enhances the flexibility and adaptability of the server. By allowing dynamic configuration based on runtime settings, the server can cater to various use cases and requirements. The use of the any type for the configuration values further increases the versatility of the configuration options.


20-20: Great change to enhance snapshot configurability!

The modification of the SnapshotOptions field to be a function that accepts a configuration map is a positive change that improves the flexibility and adaptability of the server's snapshot functionality. By allowing dynamic configuration based on runtime settings, the server can accommodate different snapshot requirements and scenarios. The use of the any type for the configuration values further enhances the versatility of the configuration options.


30-35: Updates to DefaultServerOptions function are consistent and maintain defaults!

The changes made to the DefaultServerOptions function accurately reflect the modifications made to the ServerOptions struct. By initializing the Mempool and SnapshotOptions fields with anonymous functions that return the default implementations, the function maintains consistency with the new field types. This approach ensures that the server can operate with minimal configuration if needed, while still allowing for flexibility when custom configurations are provided.

server/v2/cometbft/config.go (4)

4-5: LGTM!

The import statement for the mempool package is correct and necessary for utilizing the default mempool configurations.


25-25: LGTM!

The modification to the DefaultAppTomlConfig function, which initializes the Mempool field with the default mempool configuration, is correct and aligns with the objective of integrating mempool settings into the application's configuration structure.


38-40: LGTM!

The addition of the Mempool field to the AppTomlConfig struct, along with the appropriate TOML configuration mapping annotation and comments, is correct and enhances the application's configurability by integrating mempool settings into its configuration structure.


Line range hint 1-60: Code conforms to the Uber Golang style guide.

The file adheres to the Uber Golang style guide, following the recommended naming conventions, formatting, and commenting practices. No deviations were found.

simapp/v2/simdv2/cmd/config.go (2)

78-89: LGTM!

The initCometConfig function correctly customizes the default CometBFT configuration by modifying the logging levels, block timeout, and pprof listener address. The changes are clear and do not introduce any apparent issues.


91-104: Provide more details about the mempool interface mismatch and the plans for the maximum transactions option.

The initCometOptions function currently does not make any modifications to the default server options. There is a TODO comment indicating a mismatch between the mempool interfaces, but no further details are provided.

Additionally, there is a commented-out code block that suggests an intention to overwrite the application mempool using a maximum transactions option, but it is currently not implemented.

Could you please provide more information about the following:

  1. The specific nature of the mempool interface mismatch and how it affects the integration with the CometBFT server.
  2. The plans and timeline for implementing the maximum transactions option and any potential challenges or considerations.

This will help in understanding the current state of the code and the future direction of the mempool configuration.

simapp/v2/simdv2/cmd/commands.go (1)

77-81: LGTM! The changes enhance the customizability of the CometBFT component.

The modifications to the cometbft.New function call introduce new parameters initCometOptions[T]() and initCometConfig(), replacing the default server options. This change suggests a shift towards a more flexible and customizable configuration for the CometBFT component, allowing for tailored options and settings during initialization.

The updated implementation aligns with the PR objectives of wiring the mempool configuration in the server component and potentially improves the overall functionality by providing more control over the CometBFT configuration.

The changes do not introduce any apparent correctness, performance, or security issues.

server/v2/commands.go (2)

48-48: LGTM!

The NewServer function is correctly using the globalServerCfg parameter, which aligns with the previous change.


41-41: Verify the initialization and usage of globalServerCfg across the codebase.

The renaming of the parameter from serverCfg to globalServerCfg suggests a shift in the intended scope of the configuration. Ensure that globalServerCfg is properly initialized and contains the necessary settings for the server to function correctly.

Run the following script to verify the usage of globalServerCfg:

Verification successful

Renaming to globalServerCfg is appropriate and consistent with codebase usage

The change from serverCfg to globalServerCfg accurately reflects its usage in the codebase. The ServerConfig struct is defined in server/v2/config.go and contains settings for minimum gas prices. The parameter is correctly used in the AddCommands function and passed to NewServer.

While the config is not initialized within the function, this is expected as it's likely passed in from a higher level, allowing for flexible configuration management.

  • The usage is limited to server/v2/commands.go, which is appropriate for its purpose.
  • The "global" prefix clarifies its scope of use across different server components.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization and usage of `globalServerCfg` across the codebase.

# Test: Search for the initialization of `globalServerCfg`. Expect: At least one occurrence.
rg --type go $'globalServerCfg\s*:?=\s*\S+'

# Test: Search for the usage of `globalServerCfg`. Expect: Multiple occurrences.
rg --type go -w globalServerCfg

Length of output: 214


Script:

#!/bin/bash
# Description: Further investigation of `globalServerCfg` initialization and usage

# Test 1: Search for any assignments to globalServerCfg with a more flexible pattern
echo "=== Searching for globalServerCfg assignments ==="
rg --type go -i 'globalServerCfg.*='

# Test 2: Look for the definition of ServerConfig type
echo "=== Searching for ServerConfig type definition ==="
ast-grep --lang go --pattern 'type ServerConfig struct { $$$ }'

# Test 3: Perform a case-insensitive search for globalServerCfg
echo "=== Performing case-insensitive search for globalServerCfg ==="
rg --type go -i globalservercfg

Length of output: 1046

server/v2/cometbft/server.go (4)

27-27: LGTM!

The import statement for the mempool package is valid and relevant to the mempool functionality being implemented.


109-109: Looks good!

The modification to pass the cfg map to s.serverOptions.Mempool enhances the configurability of the mempool, aligning with the PR objective. The change is clean and localized.


131-131: Looks good!

The modification to pass the cfg map to s.serverOptions.SnapshotOptions enhances the configurability of the snapshot manager, following a pattern similar to the mempool configuration change. The change is clean and localized.


244-244: Looks good!

The addition of the FlagMempoolMaxTxs flag allows users to configure the maximum transaction count for the application-side mempool. The flag is added correctly to the StartCmdFlags function, uses a sensible default value, and follows the existing flag declaration pattern.

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

let recreate the same interface. Les breakage and some teams then don't need to rewrite the api

@julienrbrt
Copy link
Member Author

let recreate the same interface. Les breakage and some teams then don't need to rewrite the api

Doing this in a follow-up to keep this PR focused.

@julienrbrt julienrbrt added this pull request to the merge queue Sep 16, 2024
Merged via the queue into main with commit 52ba264 Sep 16, 2024
71 checks passed
@julienrbrt julienrbrt deleted the julien/wire-mempool branch September 16, 2024 18:50
mergify bot pushed a commit that referenced this pull request Sep 16, 2024
(cherry picked from commit 52ba264)

# Conflicts:
#	server/v2/commands.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wire Mempool config in server/v2/cometbft
5 participants