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

Problem: cometbft rpc is more efficient to broadcast tx #1651

Merged
merged 5 commits into from
Oct 18, 2024

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Oct 18, 2024

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Summary by CodeRabbit

  • New Features

    • Added functionality for generating Cosmos transactions.
    • Introduced a new benchmark for Cosmos broadcast RPC.
  • Bug Fixes

    • Fixed issues with running a single validator benchmark locally.
    • Resolved a problem preventing node shutdown via signal.
  • Improvements

    • Enhanced transaction handling with parallel test transaction generation.
    • Updated load generator to retry with backoff on errors.
    • Added abort operation in the PrepareProposal process.
  • Documentation

    • Updated CHANGELOG.md with new entries for bug fixes and improvements.

@yihuang yihuang requested a review from a team as a code owner October 18, 2024 09:00
@yihuang yihuang requested review from devashishdxt and leejw51crypto and removed request for a team October 18, 2024 09:00
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The changes encompass updates to the CHANGELOG.md file, introducing new entries for bug fixes and improvements, including enhancements to transaction handling and the addition of a new file for protocol buffer entities. Notable changes include the introduction of constants for default denominations, modifications to transaction processing, and updates to build configurations. These changes aim to improve functionality and maintainability across various components of the project.

Changes

File Path Change Summary
CHANGELOG.md Updated with entries for bug fixes and improvements, including validator benchmark fixes and transaction enhancements.
testground/benchmark/benchmark/cosmostx.py New file defining classes and functions for protocol buffer entities related to transactions.
testground/benchmark/benchmark/peer.py Added DEFAULT_DENOM constant to replace hardcoded strings for balance definitions.
testground/benchmark/benchmark/transaction.py Added build_cosmos_tx function for constructing Cosmos transactions and updated transaction sending logic.
testground/benchmark/benchmark/utils.py Added DEFAULT_DENOM constant with value "basecro".
testground/benchmark/overlay.nix Added cprotobuf entry to buildSystems in the overrides function for package building.
testground/benchmark/pyproject.toml Added cprotobuf dependency and adjusted formatting for existing dependencies.

Possibly related PRs

Suggested reviewers

  • devashishdxt
  • calvinaco
  • mmsqe

Poem

🐰 In the meadow, changes bloom,
With fixes bright, we sweep the gloom.
New transactions dance with glee,
Cosmos whispers, "Come, run with me!"
Default values, constants clear,
In our code, we hold them dear! 🌼


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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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.

CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: yihuang <huang@crypto.com>
Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.64%. Comparing base (85ca58b) to head (6b307da).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1651   +/-   ##
=======================================
  Coverage   16.64%   16.64%           
=======================================
  Files          72       72           
  Lines        6212     6212           
=======================================
  Hits         1034     1034           
  Misses       5055     5055           
  Partials      123      123           

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

🧹 Outside diff range and nitpick comments (6)
testground/benchmark/benchmark/peer.py (1)

Line range hint 153-153: Consider updating minimum-gas-prices to use DEFAULT_DENOM

While the changes to use DEFAULT_DENOM are generally good, there's a potential inconsistency in the default_app_patch dictionary. The minimum-gas-prices is still set to "0basecro", which may not be consistent with the new DEFAULT_DENOM.

Consider updating this line to use DEFAULT_DENOM:

"minimum-gas-prices": f"0{DEFAULT_DENOM}",

This will ensure that the minimum gas price denomination is consistent with the rest of the changes.

CHANGELOG.md (1)

Line range hint 57-196: Comprehensive changelog with multiple significant releases.

The changelog covers several major and minor releases, including v1.1.0-rc0, v1.0.7, v1.0.6, and earlier versions. Key points:

  1. Multiple state machine breaking changes across versions.
  2. Significant improvements in performance, especially with memiavl and versiondb.
  3. Integration of new modules and features like ICA and IBC fee middleware.
  4. Numerous bug fixes addressing issues in JSON-RPC, EVM compatibility, and IBC functionality.
  5. Regular updates to dependencies like Cosmos SDK, IBC-go, and Ethermint.

The frequent releases and ongoing improvements indicate active development and maintenance of the project. However, the number of breaking changes suggests that users need to be cautious when upgrading between versions.

Consider implementing a more robust upgrade path for users, possibly including:

  1. Detailed upgrade guides for each breaking change.
  2. Automated upgrade scripts where possible.
  3. A longer-term roadmap to stabilize the state machine and reduce the frequency of breaking changes.
🧰 Tools
🪛 Markdownlint

17-17: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

testground/benchmark/benchmark/cosmostx.py (4)

81-81: Avoid using reserved keywords with trailing underscores.

The field name from_ in line 81 uses a trailing underscore to avoid clashing with the reserved keyword from. While this is acceptable, it may lead to confusion. Consider using a more descriptive field name like from_address for clarity.

Apply this diff if you decide to rename the field:

-    from_ = Field("bytes", 5)
+    from_address = Field("bytes", 5)

85-86: Consider adding documentation for the empty class ExtensionOptionsEthereumTx.

The class ExtensionOptionsEthereumTx is currently empty. Adding a docstring can clarify its purpose and future implementation plans, which improves maintainability and readability.

Example:

 class ExtensionOptionsEthereumTx(ProtoEntity):
+    """Placeholder for Ethereum transaction extension options."""
     pass

1-3: Group import statements together.

The import statements in lines 1 and 3 are separated by a blank line. Grouping them together improves code readability and adheres to PEP 8 style guidelines.

Apply this diff to group the imports:

-from typing import Optional
-
-from cprotobuf import Field, ProtoEntity
+from typing import Optional
+from cprotobuf import Field, ProtoEntity

18-86: Consider adding unit tests for the new classes.

The classes defined in this file are crucial for handling transaction-related data. Adding unit tests ensures that they work as expected and helps prevent future regressions.

Do you want assistance in generating unit tests for these classes or opening a GitHub issue to track this task?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 85ca58b and 57fd9d6.

⛔ Files ignored due to path filters (1)
  • testground/benchmark/poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • testground/benchmark/benchmark/cosmostx.py (1 hunks)
  • testground/benchmark/benchmark/peer.py (1 hunks)
  • testground/benchmark/benchmark/transaction.py (4 hunks)
  • testground/benchmark/benchmark/utils.py (1 hunks)
  • testground/benchmark/overlay.nix (1 hunks)
  • testground/benchmark/pyproject.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • testground/benchmark/benchmark/utils.py
🧰 Additional context used
🔇 Additional comments (15)
testground/benchmark/pyproject.toml (2)

22-22: Minor formatting adjustment

The space before jsonmerge = "^1.9.2" has been removed, aligning it with other dependencies in the file. This change improves consistency in the file formatting.


23-23: New dependency added: cprotobuf

The addition of cprotobuf = "^0.1.11" as a new dependency is noted. This library is likely being introduced to handle Protocol Buffers in Python, which aligns with the PR objective of improving efficiency in transaction broadcasting.

However, there are a few points to consider:

  1. The version constraint ^0.1.11 allows for compatible updates but may include breaking changes as it's a pre-1.0 version. Consider if a stricter version constraint is necessary for stability.
  2. It's important to ensure that this dependency is actually used in the project code. If it's not yet utilized, it might be premature to add it to the dependencies.

To confirm the usage of this new dependency, please run the following script:

If the script doesn't return any results, consider removing this dependency until it's actually needed in the code.

✅ Verification successful

Adjusting Search for cprotobuf Usage

The previous attempt to search for cprotobuf usage encountered an issue because rg does not recognize python as a valid file type. To accurately verify the usage of cprotobuf, please run the following corrected script:


Dependency cprotobuf is correctly utilized

The cprotobuf dependency is imported in the following files:

  • testground/benchmark/benchmark/cosmostx.py
  • integration_tests/test_streamer.py
  • integration_tests/ibc_utils.py

This confirms that the dependency is in use and necessary for the project.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for imports or usage of cprotobuf in Python files
rg --type python 'import\s+cprotobuf|from\s+cprotobuf\s+import'

Length of output: 96


Script:

# 
#!/bin/bash
# Search for imports or usage of cprotobuf in Python files
rg -g "*.py" 'import\s+cprotobuf|from\s+cprotobuf\s+import'

Length of output: 311

testground/benchmark/overlay.nix (1)

13-13: Addition of cprotobuf to buildSystems looks appropriate.

The addition of cprotobuf = [ "setuptools" ]; to the buildSystems attribute set is consistent with the existing structure and purpose of this configuration. This change indicates that the cprotobuf package will use the setuptools build system, which is a common choice for Python packages.

A few points to consider:

  1. This change aligns with the PR objectives of improving efficiency, as it may be related to the integration of new protocol buffer entities mentioned in the AI-generated summary.
  2. The modification is minimal and follows the established pattern in the file, which suggests it's a low-risk change.
  3. It's worth verifying that the cprotobuf package is indeed compatible with setuptools and that this configuration is necessary for the project.

To ensure this change is justified and correctly implemented, please run the following verification script:

This script will help confirm the necessity of adding cprotobuf to the buildSystems and ensure it's being used in the project as expected.

testground/benchmark/benchmark/peer.py (5)

14-14: LGTM: Import of DEFAULT_DENOM

The addition of DEFAULT_DENOM to the import list from utils is appropriate and consistent with its usage throughout the file. This change centralizes the denomination definition, which is a good practice for maintainability.


Line range hint 20-22: LGTM: Updated balance definitions using DEFAULT_DENOM

The changes to VAL_INITIAL_AMOUNT, VAL_STAKED_AMOUNT, and ACC_INITIAL_AMOUNT to use DEFAULT_DENOM instead of the hardcoded "basecro" are appropriate. This improves maintainability and consistency throughout the file while preserving the existing amount values.


Line range hint 47-51: LGTM: Updated init command with DEFAULT_DENOM

The use of DEFAULT_DENOM as the default_denom parameter in the init command call is appropriate. This change ensures consistency with the globally defined denomination and improves maintainability.


Line range hint 127-131: LGTM: Updated genesis configuration with DEFAULT_DENOM

The use of DEFAULT_DENOM in the evm parameters of the genesis patch is appropriate. This change ensures consistency with the globally defined denomination and improves maintainability of the genesis configuration.


Line range hint 1-238: Overall assessment: Good changes with one minor suggestion

The changes in this file consistently introduce and use the DEFAULT_DENOM constant, which improves maintainability and consistency. The modifications to balance definitions, node initialization, and genesis configuration all align well with this goal.

However, there's one minor suggestion to consider:

  • Update the minimum-gas-prices in the default_app_patch to use DEFAULT_DENOM for complete consistency.

Once this small change is addressed, the modifications will fully achieve the goal of centralizing and standardizing the denomination usage throughout the file.

CHANGELOG.md (3)

15-15: New feature added: Cosmos broadcast RPC benchmark.

A new benchmark for using Cosmos broadcast RPC has been added. This is likely an improvement to measure and potentially optimize the performance of RPC calls.


Line range hint 3-13: Multiple bug fixes and improvements in the unreleased version.

The unreleased version includes several bug fixes and improvements:

  1. Fixed running single validator benchmark locally.
  2. Fixed an issue where the node couldn't shut down by signal.
  3. Improved test transaction generation in parallel for single node setups.
  4. Enhanced load generator with backoff retry on errors.
  5. Added abort operation in PrepareProposal function.

These changes appear to address stability issues and improve testing capabilities.

🧰 Tools
🪛 Markdownlint

17-17: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


Line range hint 17-55: Significant updates in v1.1.0-rc1 release.

This release candidate includes several important changes:

  1. State machine breaking change in memiavl's initial version logic.
  2. Multiple improvements, including changes to block-stm parallelism, Ethermint updates, and IBC channel upgrade support.
  3. Several bug fixes, including query fixes and updates to Ethermint and Cosmos SDK.

These changes seem to focus on performance improvements and bug fixes. The state machine breaking change should be carefully considered during upgrades.

To verify the impact of the state machine breaking change, we should check for any migration scripts or upgrade handlers. Run the following:

🧰 Tools
🪛 Markdownlint

17-17: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

testground/benchmark/benchmark/transaction.py (4)

2-2: Imports updated appropriately to support new functionality

The added imports for base64, HexBytes, and modules cosmostx, DEFAULT_DENOM, and LOCAL_RPC are necessary and correctly included to support the new transaction construction and broadcasting logic.

Also applies to: 13-13, 15-15, 17-17


69-71: Transaction signing and Cosmos transaction building are correctly implemented

The modifications in the _do_job function to sign transactions and build Cosmos transactions using build_cosmos_tx are appropriate. The use of HexBytes(acct.address) ensures that the sender's address is correctly formatted as bytes.


Line range hint 145-161: Confirm the correct usage of broadcast_tx_async in JSON-RPC call

In the async_sendtx function, the JSON-RPC method broadcast_tx_async is used with parameters { "tx": raw }. Verify that this matches the expected format for the CometBFT (Tendermint) RPC API and that the raw transaction is correctly encoded as a base64 string. Incorrect parameters or encoding may result in transaction broadcast failures.

To confirm the correct usage, you can run the following script:

#!/bin/bash
# Description: Verify that the JSON-RPC call to broadcast transactions is correctly formed.

# Test: Search for all usages of 'broadcast_tx_async' to ensure consistency.
rg --type python -A 5 '"broadcast_tx_async"'

# Additionally, compare the parameters with the official CometBFT RPC documentation.

126-138: Verify the correctness of fee calculation and denomination

Ensure that the fee calculation fee = tx["gas"] * tx["gasPrice"] accurately represents the transaction fee within the Cosmos SDK context. Also, confirm that DEFAULT_DENOM corresponds to the correct denomination used by the network for fee payments and that no unit conversions are necessary.

To verify the fee calculation and denomination, run the following script:

✅ Verification successful

Fee Calculation and Denomination Verified

The fee calculation fee = tx["gas"] * tx["gasPrice"] is correctly implemented, and DEFAULT_DENOM is consistently set to "basecro", aligning with the network's fee denomination. No unit conversions are necessary.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that DEFAULT_DENOM is correctly used and fee calculations are consistent.

# Test 1: Check where DEFAULT_DENOM is defined and its usage.
rg --type python 'DEFAULT_DENOM'

# Test 2: Ensure fee calculation patterns are consistent across the codebase.
rg --type python 'fee\s*=\s*tx\["gas"\]\s*\*\s*tx\["gasPrice"\]'

Length of output: 171


Script:

#!/bin/bash
# Description: Verify that DEFAULT_DENOM is correctly used and fee calculations are consistent.

# Test 1: Check where DEFAULT_DENOM is defined and its usage.
rg --type py 'DEFAULT_DENOM'

# Test 2: Ensure fee calculation patterns are consistent across the codebase.
rg --type py 'fee\s*=\s*tx\["gas"\]\s*\*\s*tx\["gasPrice"\]'

Length of output: 1073

testground/benchmark/benchmark/cosmostx.py Outdated Show resolved Hide resolved
testground/benchmark/benchmark/cosmostx.py Show resolved Hide resolved
testground/benchmark/benchmark/cosmostx.py Outdated Show resolved Hide resolved
testground/benchmark/benchmark/transaction.py Show resolved Hide resolved
yihuang and others added 3 commits October 18, 2024 17:09
Signed-off-by: yihuang <huang@crypto.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: yihuang <huang@crypto.com>
@yihuang yihuang added this pull request to the merge queue Oct 18, 2024
Merged via the queue into crypto-org-chain:main with commit 3303077 Oct 18, 2024
35 checks passed
@yihuang yihuang deleted the use-cosmos-tx branch October 18, 2024 10:31
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.

2 participants