Skip to content

Problem: testground test case not fast enough#1495

Merged
yihuang merged 4 commits intocrypto-org-chain:mainfrom
yihuang:optimize-test
Jun 28, 2024
Merged

Problem: testground test case not fast enough#1495
yihuang merged 4 commits intocrypto-org-chain:mainfrom
yihuang:optimize-test

Conversation

@yihuang
Copy link
Contributor

@yihuang yihuang commented Jun 28, 2024

Solution:

Benchmark Results

Can record 360 tps on a local m3 mac laptop, 3 validators + 5 full nodes + load generators all running in local docker containers in the same Linux VM, 63 blocks, each has around 1k transactions, 2.9s avg block time.

EDIT: by allocate all 16 cpus to the VM, it can reach 849 tps (2292 transactions per block and 2.7 block time on avg).

👮🏻👮🏻👮🏻 !!!! 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

  • Dependencies

    • Updated the version of github.com/evmos/ethermint to improve performance and stability.
  • Refactor

    • Renamed various properties and variables for clarity and consistency.
    • Consolidated configuration updates in config.toml and app.toml.
  • New Features

    • Added properties to check if a node is a fullnode or validator leader.
    • Introduced new functions for funding test accounts and exporting Ethereum accounts.
  • Bug Fixes

    • Improved handling of transaction errors and connection checks.
  • Configuration

    • Adjusted test parameters for better performance and accuracy.

Solution:
- patch cronosd temporarily to disable nonce checking
- optimise the load generator
@yihuang yihuang requested a review from a team as a code owner June 28, 2024 06:16
@yihuang yihuang requested review from calvinaco and mmsqe and removed request for a team June 28, 2024 06:16
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Warning

Rate limit exceeded

@yihuang has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 28 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between ac947d4 and 116a032.

Walkthrough

This update primarily focuses on version upgrades, code refactoring, and functionality enhancements across various files. Key areas of improvement include updating dependencies in go.mod and gomod2nix.toml, enhancing the transaction handling logic, renaming and introducing new variables, and configuring patched versions for testing. These changes aim to improve system robustness, enhance feature capabilities, and streamline testing processes.

Changes

File/Path Summary of Changes
go.mod Updated the github.com/evmos/ethermint dependency version in the replace section.
gomod2nix.toml Updated version and hash for github.com/evmos/ethermint module.
nix/testground-cronosd.patch Added UnsafeUnorderedTx field to options struct in setAnteHandler method.
nix/testground-image.nix Introduced patched-cronosd for Docker image build overrides.
testground/benchmark/.../context.py Renamed LEADER_GLOBAL_SEQUENCE to LEADER_SEQUENCE; Added is_fullnode_leader and is_validator_leader.
testground/benchmark/.../main.py Refactored imports and functions for Ethereum interaction, including fund_test_accounts.
testground/benchmark/.../params.py Renamed halt_height to num_accounts; Added num_txs property.
testground/benchmark/.../peer.py Refactored PeerPacket creation and configuration updates; added consolidated patch updates.
testground/benchmark/.../sendtx.py Renamed and refactored functions for handling test account funding and transactions.
testground/benchmark/.../sync.py Added a None response check in _request function.
testground/benchmark/.../utils.py Introduced export_eth_account function.
testground/benchmark/.../local.toml Updated test parameters: increased number of accounts and transactions per account.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant TxHandler as TransactionHandler
    participant EthAccount as EthereumAccountManager

    User ->> App: Initiate Transfer
    App ->> TxHandler: Process Transaction
    TxHandler ->> EthAccount: Validate Account
    EthAccount -->> TxHandler: Account Validated
    TxHandler -->> App: Transaction Processed
    App -->> User: Transfer Complete
Loading

Poem

Ode to Code Transformations
Beneath the code, where logic streams,
I've altered flows and chased new dreams.
Transactions hum, accounts align,
With changes made in perfect time.
Dependencies now fresh and strong,
We stride ahead, where bytes belong!

  \  (\_/)  
   (='.'=)   
   (")_(")   
  - Rabbit the Coder 🐇

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 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 show all the console.log statements in this repository.
    • @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 as 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.

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

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

Outside diff range and nitpick comments (3)
testground/benchmark/benchmark/utils.py (2)

Line range hint 47-48: Use modern string formatting in wait_for_port.

Replace the format call with an f-string for better readability and performance.

-                    "Waited too long for the port {} on host {} to start accepting "
-                    "connections.".format(port, host)
+                    f"Waited too long for the port {port} on host {host} to start accepting connections."

Line range hint 54-54: Refactor loop control variable in wait_for_block.

The loop variable i is unused within the loop body. Consider renaming it to _i to indicate it is intentionally unused.

-    for i in range(timeout):
+    for _i in range(timeout):
testground/benchmark/benchmark/main.py (1)

Line range hint 73-76: Improve timeout handling in subprocess management.

Replace the existing try-except block with contextlib.suppress for handling the TimeoutExpired exception from subprocesses. This results in cleaner and more readable code.

-    try:
-        proc.wait(5)
-    except subprocess.TimeoutExpired:
-        pass
+    with contextlib.suppress(subprocess.TimeoutExpired):
+        proc.wait(5)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47fb783 and ac947d4.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (12)
  • go.mod (1 hunks)
  • gomod2nix.toml (1 hunks)
  • nix/testground-cronosd.patch (1 hunks)
  • nix/testground-image.nix (1 hunks)
  • testground/benchmark/benchmark/context.py (2 hunks)
  • testground/benchmark/benchmark/main.py (3 hunks)
  • testground/benchmark/benchmark/params.py (1 hunks)
  • testground/benchmark/benchmark/peer.py (3 hunks)
  • testground/benchmark/benchmark/sendtx.py (1 hunks)
  • testground/benchmark/benchmark/sync.py (1 hunks)
  • testground/benchmark/benchmark/utils.py (2 hunks)
  • testground/benchmark/compositions/local.toml (1 hunks)
Additional context used
Ruff
testground/benchmark/benchmark/sendtx.py

14-14: Loop control variable i not used within loop body

Rename unused i to _i

(B007)

testground/benchmark/benchmark/utils.py

47-48: Use f-string instead of format call

Convert to f-string

(UP032)


54-54: Loop control variable i not used within loop body

Rename unused i to _i

(B007)

testground/benchmark/benchmark/main.py

33-33: Use context handler for opening files

(SIM115)


73-76: Use contextlib.suppress(subprocess.TimeoutExpired) instead of try-except-pass

Replace with contextlib.suppress(subprocess.TimeoutExpired)

(SIM105)

Additional comments not posted (16)
nix/testground-cronosd.patch (1)

9-9: Verify the security implications of enabling UnsafeUnorderedTx.

Adding UnsafeUnorderedTx: true potentially affects the transaction handling logic, which could have security implications. Please ensure this change aligns with the application's security model and is thoroughly tested.

nix/testground-image.nix (1)

3-7: Ensure the patch is applied correctly in the Docker image configuration.

The patched-cronosd definition applies the testground-cronosd.patch. Verify that the patch is correctly integrated and does not introduce any issues in the Docker image.

testground/benchmark/compositions/local.toml (1)

16-18: Verify the appropriateness of the test configuration changes.

The configuration for num_accounts and num_txs has been updated. Please verify that these changes align with the intended test scenarios and do not introduce any performance or scalability issues.

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

3-6: Add new imports for concurrency, file path handling, and Ethereum web3 interactions.

These additions support the new functionalities introduced in the file, specifically for handling multiple transactions concurrently, managing file paths more robustly, and interacting with Ethereum. Ensure these libraries are included in the project's dependencies.


11-12: Introduction of new functions from sendtx module.

The introduction of fund_test_accounts and sendtx functions from the sendtx module aligns with the PR's objective to optimize the load generator. This change should improve the performance of the test cases by enabling more efficient management of transactions.
[APROVED]


27-34: Refactor node startup process to use the Path class for log file management.

Using Path from the pathlib module for handling file paths is a more modern and robust approach compared to traditional string-based paths. This change enhances the readability and maintainability of the code.

Tools
Ruff

33-33: Use context handler for opening files

(SIM115)


40-60: Enhanced transaction handling and concurrency using ThreadPoolExecutor.

This block introduces concurrent transaction submissions using a thread pool, which is crucial for performance testing. However, ensure that the exception handling within the thread pool's tasks is robust enough to not crash the entire application.

testground/benchmark/benchmark/context.py (2)

7-7: Rename global sequence constant for clarity.

Renaming LEADER_GLOBAL_SEQUENCE to LEADER_SEQUENCE simplifies the terminology and aligns with the other naming conventions in the project. This change should make the codebase easier to understand for new contributors.


108-114: Add properties to determine leadership roles.

The addition of is_fullnode_leader and is_validator_leader properties helps in determining the specific roles of nodes in the network, which is crucial for managing different behaviors during tests. This change enhances the control flow and decision-making in test scenarios.

testground/benchmark/benchmark/params.py (1)

110-115: Add properties for managing accounts and transactions.

The addition of num_accounts and num_txs properties supports the PR's objective to optimize the load generator by allowing dynamic configuration of the number of accounts and transactions. This is crucial for scalability and flexibility in performance testing.

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

33-39: Refactor peer packet creation process.

The changes in peer packet creation, including the introduction of GenesisAccount instances, enhance the clarity and modularity of the code. This refactoring helps in managing network configurations more effectively.


77-94: Update network configurations and toml patches.

The extensive modifications to the config.toml and app.toml files, including settings for persistent peers, mempool, and indexer configurations, are critical for the correct operation of the network under test conditions. Ensure these configurations are thoroughly tested to prevent runtime issues.

testground/benchmark/benchmark/sync.py (1)

73-75: Improve error handling in synchronization service.

Adding a check for a None response in the _request function is a defensive programming practice that helps in handling unexpected disconnections more gracefully. This change enhances the robustness of the network synchronization services.

go.mod (2)

279-279: Confirm the correctness of replace directives.

The replace directives have been modified to point to specific versions or local paths. Please confirm that these changes are intentional and correctly align with the project's dependency management strategy.


279-279: Verify the updated dependency for potential issues.

The dependency github.com/evmos/ethermint has been updated to a specific commit. Please ensure that this version has been tested thoroughly for stability and does not introduce any known vulnerabilities.

gomod2nix.toml (1)

265-266: Dependency Update Approved

The version and hash for github.com/evmos/ethermint have been updated. This change is consistent with the PR's objectives to optimize a test case by updating dependencies.

However, ensure that this new version does not introduce any known vulnerabilities.

@yihuang yihuang enabled auto-merge June 28, 2024 07:03
@yihuang yihuang added this pull request to the merge queue Jun 28, 2024
Merged via the queue into crypto-org-chain:main with commit 0b0d9db Jun 28, 2024
@yihuang yihuang deleted the optimize-test branch June 28, 2024 08:06
@coderabbitai coderabbitai bot mentioned this pull request Jul 22, 2025
13 tasks
@coderabbitai coderabbitai bot mentioned this pull request Aug 8, 2025
13 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 11, 2025
13 tasks
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