Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

protecccc validators bls #1473

Closed
wants to merge 16 commits into from
Closed

protecccc validators bls #1473

wants to merge 16 commits into from

Conversation

itsdevbear
Copy link
Member

@itsdevbear itsdevbear commented Jan 31, 2024

image

Summary by CodeRabbit

  • New Features

    • Introduced new configuration options for the Polaris module, including validator settings and transaction rechecking mechanisms.
    • Enhanced transaction handling in the network by adding conditions based on validator status and EVM transactions.
    • Improved transaction caching with the adoption of an LRU cache mechanism for better management of transaction states.
  • Bug Fixes

    • Removed unnecessary transaction drop call to streamline transaction processing flow.
  • Refactor

    • Updated various structs and functions across the system to incorporate new configuration options and logic related to validators and transaction handling.
    • Simplified the transaction removal process in the mempool.
  • Tests

    • Adjusted test setups to accommodate new logic and configuration parameters.

Copy link

coderabbitai bot commented Jan 31, 2024

Walkthrough

The recent updates introduce new configurations and logic related to validator operations and transaction handling in the Polaris module. Enhancements include the ability to specify a validator's JSON-RPC endpoint, identify if a node is a validator, and force recheck transactions. Changes to the runtime and transaction pool support these features, improving transaction management and validator functionality. Additionally, there's a shift towards using LRU cache for transaction tracking, refining the process of handling Ethereum transactions within the ecosystem.

Changes

File(s) Change Summary
cosmos/config/template.go
eth/polar/config.go
cosmos/config/config.go
cosmos/config/flags/flags.go
Added configurations for validator JSON-RPC endpoint, validator status, and transaction rechecking.
cosmos/runtime/ante/ante.go
cosmos/runtime/runtime.go
cosmos/runtime/txpool/mempool.go
cosmos/runtime/txpool/comet.go
Enhanced validator logic, transaction handling, and introduced LRU cache for transaction tracking.
e2e/testapp/app.go
cosmos/runtime/txpool/handler_test.go
Adjustments for testing and debugging, including print statements and test initialization changes.

"In the realm of code, where logic does play,
A rabbit hopped in, bringing updates today.
With tweaks and new features, so nimble and smart,
It crafted a world, where transactions are art. 🐰✨"

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>.
    • Generate unit-tests for this file.
  • 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.

Copy link

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6c003aa and a6378e0.
Files selected for processing (11)
  • cosmos/config/config.go (1 hunks)
  • cosmos/config/flags/flags.go (1 hunks)
  • cosmos/config/template.go (1 hunks)
  • cosmos/runtime/ante/ante.go (3 hunks)
  • cosmos/runtime/runtime.go (5 hunks)
  • cosmos/runtime/txpool/ante.go (1 hunks)
  • cosmos/runtime/txpool/comet.go (1 hunks)
  • cosmos/runtime/txpool/handler.go (2 hunks)
  • cosmos/runtime/txpool/handler_test.go (1 hunks)
  • cosmos/runtime/txpool/mempool.go (7 hunks)
  • eth/polar/config.go (1 hunks)
Additional comments: 30
cosmos/runtime/txpool/comet.go (7)
  • 27-27: The import of the lru package from github.com/ethereum/go-ethereum/common/lru is correctly added to support the LRU cache functionality.
  • 31-31: The defaultCacheSize constant is set to 100000. Ensure this size is appropriate for the expected transaction volume and available memory resources to avoid potential performance issues.
  • 44-44: The cometRemoteCache struct now uses an LRU cache for timeInserted, which is a significant improvement over a simple map for managing the time of insertion of transactions, especially in terms of memory efficiency and eviction of old entries.
  • 50-50: Initialization of the timeInserted LRU cache with defaultCacheSize ensures that the cache size is controlled, preventing unbounded growth which could lead to memory issues.
  • 55-55: The IsRemoteTx method correctly checks for the presence of a transaction hash in the LRU cache, which is an efficient way to determine if a transaction was added remotely.
  • 59-64: The MarkRemoteSeen method now correctly adds a transaction hash to the LRU cache with the current Unix timestamp and returns a boolean indicating success. This change enhances the method's functionality by providing feedback on whether the operation was successful.
  • 68-69: The TimeFirstSeen method is simplified to directly retrieve the time from the LRU cache, which is a more efficient approach than the previous implementation.
cosmos/runtime/txpool/handler_test.go (1)
  • 63-63: The addition of false as an argument to newHandler in the test setup indicates a modification in the newHandler function's signature to possibly include a new boolean parameter. This change suggests an enhancement or a new feature related to the handler's functionality.
eth/polar/config.go (1)
  • 106-107: The addition of ValidatorJSONRPCEndpoint and IsValidator fields to the Config struct introduces new configuration options for validators. This change is crucial for enabling or identifying validator nodes and specifying their JSON-RPC endpoints, which could be essential for network operations and security.
cosmos/runtime/ante/ante.go (3)
  • 42-42: The addition of the isValidator boolean field to the Provider struct allows for conditional logic based on whether the current node is a validator. This is a significant change that could affect transaction processing and validation logic.
  • 59-59: Initializing the isValidator field in the NewAnteHandler function ensures that the new configuration is correctly passed through and used within the ante handler logic.
  • 72-74: The conditional check using isValidator to potentially return an error if a validator node attempts to process an EVM transaction from comet introduces a new validation layer. This change could have implications on the network's transaction processing rules and should be carefully reviewed for its impact on network functionality.
cosmos/runtime/txpool/ante.go (1)
  • 53-58: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [193-193]

The simplification of the Remove function to no longer handle specific Ethereum transactions and become a no-op indicates a design decision to delegate transaction removal logic elsewhere, possibly to improve modularity or due to changes in how transactions are managed within the system.

cosmos/runtime/txpool/mempool.go (5)
  • 75-77: The addition of isValidator, validatorJsonRPC, and ethclient fields to the Mempool struct introduces new functionalities and dependencies, particularly for validator nodes. This change suggests a more complex transaction handling process that may involve external validation or additional network interactions.
  • 133-135: The early return in the Insert method for validator nodes, preventing them from inserting transactions into the mempool from comet, aligns with the new logic introduced for handling validator-specific behavior. This ensures that validator nodes adhere to the intended network rules and transaction processing logic.
  • 152-157: The optimistic sending of transactions to the validator via ethclient when the node is not a validator and ethclient is initialized introduces an external network interaction that could have implications for network traffic and transaction propagation. Ensure this behavior is intended and tested for potential edge cases or failure modes.
  • 176-176: The call to MarkRemoteSeen for adding the Ethereum transaction hash to the remote cache is a necessary step to track transactions seen by the node. This inclusion ensures that the mempool's state is accurately maintained.
  • 193-193: The simplification of the Remove method to a no-op indicates a design decision to handle transaction removals elsewhere, possibly within the Ethereum transaction pool directly. This change could simplify the mempool's interface by relying on the underlying Ethereum transaction pool for more complex operations.
cosmos/config/flags/flags.go (1)
  • 30-31: The addition of IsValidator and ValidatorJSONRPCEndpoint constants to the flags package introduces new configuration flags for the Polaris module. These flags are essential for configuring validator-specific settings, enhancing the flexibility and control over validator node behavior.
cosmos/runtime/txpool/handler.go (4)
  • 100-100: The addition of the isValidator boolean field to the handler struct introduces a mechanism to differentiate behavior based on whether the node is operating as a validator. This change could impact how transactions are handled and propagated within the network.
  • 106-106: The update to the newHandler function to accept an isValidator boolean parameter reflects the structural change in the handler struct. This modification allows the handler to be initialized with knowledge of the node's role, potentially altering its behavior accordingly.
  • 124-126: The conditional return in the Start method based on the isValidator flag prevents the handler from starting if the node is a validator. This decision likely relates to specific network roles and responsibilities, ensuring that validator nodes do not perform certain actions that are not within their purview.
  • 139-141: Similarly, the conditional return in the Stop method based on the isValidator flag ensures that the handler's stop logic is only executed when necessary. This approach maintains consistency with the start logic and further delineates the operational differences between validator and non-validator nodes.
cosmos/runtime/runtime.go (5)
  • 96-96: The inclusion of the cfg field of type *eth.Config in the Polaris struct introduces a direct reference to the Ethereum configuration within the Polaris runtime. This change facilitates access to Ethereum-specific configurations, potentially affecting how the Polaris runtime initializes and interacts with Ethereum components.
  • 110-110: Initializing the cfg field in the New function ensures that the Ethereum configuration is correctly passed and stored within the Polaris runtime. This setup is crucial for subsequent operations that rely on Ethereum-specific settings.
  • 135-136: The use of cfg.Polar.IsValidator and cfg.Polar.ValidatorJSONRPCEndpoint when initializing the WrappedTxPool indicates that these configuration values directly influence the behavior of the transaction pool, particularly in relation to validator-specific logic.
  • 171-171: Passing cfg.Polar.IsValidator to NewAnteHandler when setting the ante handler in the Build function demonstrates how the new configuration fields are utilized to tailor the runtime behavior based on the node's role as a validator.
  • 186-186: Similarly, passing cfg.Polar.IsValidator to the Init method of WrappedTxPool in the SetupServices function shows the pervasive use of the new configuration options throughout the Polaris runtime, affecting various components and their initialization logic.
cosmos/config/template.go (1)
  • 43-44: The addition of validator-json-rpc-endpoint and is-validator configurations in the PolarisConfigTemplate constant is correctly implemented. These configurations are essential for setting up validator-specific settings, enhancing the flexibility and control over validator operations within the Polaris module.
cosmos/config/config.go (1)
  • 97-104: The implementation for parsing IsValidator and ValidatorJSONRPCEndpoint from the application options is correctly done. This ensures that the new validator configurations are properly integrated into the system's configuration, allowing for dynamic adjustments based on runtime parameters. It's important to ensure that these new configurations are documented and tested thoroughly to prevent any runtime issues.

cosmos/runtime/txpool/mempool.go Outdated Show resolved Hide resolved
Copy link

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a6378e0 and 9c10313.
Files selected for processing (3)
  • cosmos/config/template.go (1 hunks)
  • cosmos/runtime/txpool/mempool.go (6 hunks)
  • e2e/testapp/app.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • cosmos/config/template.go
  • cosmos/runtime/txpool/mempool.go
Additional comments: 1
e2e/testapp/app.go (1)
  • 24-24: The import of the "fmt" package is appropriate for the added print statements. This change is correctly implemented.

e2e/testapp/app.go Outdated Show resolved Hide resolved
Copy link

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

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9c10313 and 4751e4e.
Files selected for processing (4)
  • cosmos/runtime/ante/ante.go (3 hunks)
  • cosmos/runtime/runtime.go (5 hunks)
  • cosmos/runtime/txpool/handler_test.go (1 hunks)
  • cosmos/runtime/txpool/mempool.go (5 hunks)
Files skipped from review as they are similar to previous changes (3)
  • cosmos/runtime/ante/ante.go
  • cosmos/runtime/runtime.go
  • cosmos/runtime/txpool/handler_test.go
Additional comments: 1
cosmos/runtime/txpool/mempool.go (1)
  • 170-187: > 📝 NOTE

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

The logic for inserting transactions into the txpool and handling errors, especially the ErrAlreadyKnown case, is well-implemented. However, the use of errs[0] assumes that the Add method always returns a slice of errors with at least one element. Ensure this assumption is always valid or add a check to prevent potential panics if the slice is empty.

cosmos/runtime/txpool/mempool.go Outdated Show resolved Hide resolved
cosmos/runtime/txpool/mempool.go Show resolved Hide resolved
cosmos/runtime/txpool/mempool.go Show resolved Hide resolved
cosmos/runtime/txpool/mempool.go Outdated Show resolved Hide resolved
Copy link

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

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4751e4e and 1f5b812.
Files selected for processing (7)
  • cosmos/config/config.go (1 hunks)
  • cosmos/config/flags/flags.go (1 hunks)
  • cosmos/config/template.go (1 hunks)
  • cosmos/runtime/runtime.go (5 hunks)
  • cosmos/runtime/txpool/ante.go (2 hunks)
  • cosmos/runtime/txpool/mempool.go (6 hunks)
  • eth/polar/config.go (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • cosmos/config/config.go
  • cosmos/config/template.go
  • cosmos/runtime/runtime.go
  • cosmos/runtime/txpool/ante.go
  • cosmos/runtime/txpool/mempool.go
Additional comments: 2
eth/polar/config.go (1)
  • 102-116: > 📝 NOTE

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

Ensure that the new fields ValidatorJSONRPCEndpoint, IsValidator, and ForceForwardReCheckTxs are properly integrated into any functions or methods that instantiate, modify, or utilize the Config struct. This includes serialization/deserialization routines, configuration loading, and any logging or debugging output that might benefit from including these new fields. If such integrations are missing or incomplete, it could lead to issues with the new validator configuration features not functioning as expected.

cosmos/config/flags/flags.go (1)
  • 27-32: Verify that the new flags IsValidator, ValidatorJSONRPCEndpoint, and ForceForwardReCheckTxs are properly integrated into the command-line parsing logic, including validation of input values where applicable (e.g., ensuring ValidatorJSONRPCEndpoint is a valid URL). Missing or incorrect integration could lead to configuration errors or unexpected behavior.

Comment on lines +106 to +115
// ValidatorJSONRPCEndpoint is the JSON-RPC endpoint of a validator, you
// want to forward transactions to.
ValidatorJSONRPCEndpoint string

// IsValidator is a flag to indicate if the node is a validator.
IsValidator bool

// ForceForwardReCheckTxs is a flag to indicate if the node should forward
// transactions on recheck.
ForceForwardReCheckTxs bool
Copy link

Choose a reason for hiding this comment

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

The addition of ValidatorJSONRPCEndpoint, IsValidator, and ForceForwardReCheckTxs fields to the Config struct aligns with the PR's objectives to enhance validator configurations. However, consider adding comments to describe the purpose and expected values for these new fields, especially ValidatorJSONRPCEndpoint and ForceForwardReCheckTxs, to improve code maintainability and clarity for future developers.


While the new fields ValidatorJSONRPCEndpoint, IsValidator, and ForceForwardReCheckTxs are crucial for enhancing validator configurations, it's important to ensure that their usage does not introduce security vulnerabilities (e.g., unvalidated input for ValidatorJSONRPCEndpoint could lead to SSRF attacks) or performance issues (e.g., excessive rechecking of transactions). Conduct thorough testing and validation to mitigate these risks.

cosmos/config/flags/flags.go Show resolved Hide resolved
Copy link

@cyka-bera cyka-bera left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1f5b812 and b06f21c.
Files selected for processing (1)
  • cosmos/runtime/runtime.go (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cosmos/runtime/runtime.go

Copy link

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1f5b812 and 46fa37a.
Files selected for processing (4)
  • cosmos/runtime/runtime.go (5 hunks)
  • cosmos/runtime/txpool/ante.go (3 hunks)
  • cosmos/runtime/txpool/comet.go (2 hunks)
  • cosmos/runtime/txpool/mempool.go (6 hunks)
Files skipped from review as they are similar to previous changes (4)
  • cosmos/runtime/runtime.go
  • cosmos/runtime/txpool/ante.go
  • cosmos/runtime/txpool/comet.go
  • cosmos/runtime/txpool/mempool.go

Copy link

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 46fa37a and 60a34da.
Files selected for processing (3)
  • cosmos/config/template.go (1 hunks)
  • cosmos/runtime/txpool/ante.go (3 hunks)
  • cosmos/runtime/txpool/comet.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • cosmos/config/template.go
  • cosmos/runtime/txpool/ante.go
  • cosmos/runtime/txpool/comet.go

Copy link

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 60a34da and 2100f45.
Files selected for processing (2)
  • cosmos/config/template.go (1 hunks)
  • cosmos/runtime/txpool/ante.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cosmos/config/template.go
Additional comments: 3
cosmos/runtime/txpool/ante.go (3)
  • 49-54: The addition of a conditional block to force a re-broadcast of transactions during a recheck is a logical enhancement. However, ensure that m.forceBroadcastOnRecheck is properly set from configuration to avoid unintended behavior.

Ensure m.forceBroadcastOnRecheck is configurable and verify its default value aligns with expected behavior.

  • 41-54: The removal of m.crc.DropRemoteTx(ethTx.Hash()) within this context implies a strategic change in transaction handling. It's crucial to ensure that this does not lead to unintended retention of transactions that should be dropped, potentially causing mempool bloat.

Cross-check with the transaction pool management logic to confirm that transactions are still being managed efficiently without leading to unnecessary retention.

  • 70-102: The logic for determining whether a transaction should be ejected from the CometBFT mempool appears well-structured, focusing on gas price limits, transaction lifetime, and inclusion in the canonical chain. It's important to ensure these criteria are aligned with the network's operational expectations and security considerations.

The enhancements to transaction ejection criteria are logical and seem to be aligned with the objectives of optimizing transaction pool management.

@itsdevbear itsdevbear closed this Mar 15, 2024
@github-actions github-actions bot deleted the zaki-hack branch May 3, 2024 06:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants