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: require gas in relayer precompile is higher than consumed #1232

Merged
merged 10 commits into from
Nov 6, 2023

Conversation

mmsqe
Copy link
Collaborator

@mmsqe mmsqe commented Oct 31, 2023

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

  • Bug Fixes

    • Fixed a memory store issue improving overall performance.
    • Adjusted the required gas in the relayer precompile for accurate gas consumption.
  • New Features

    • Added a new chain 'chainmain-1' with two validators in the integration tests.
    • Introduced a method for transaction search based on given criteria.
    • Added a function for token transfer between two chains using the command-line tool.
    • Implemented a new test function to test Inter-Blockchain Communication (IBC) functionality.
  • Refactor

    • Updated the NewRelayerContract function to require a logger as an argument.
    • Modified the RelayerContract struct and its associated functions for better gas usage calculation.
    • Added new functions to the IbcKeeper interface.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2023

Walkthrough

This update brings a series of changes to the Cronos project, primarily focusing on improving the IBC functionality and gas usage calculation. The changes include fixing a memory store issue, re-emitting logs in the callback contract, adjusting the required gas in the relayer precompile to match the actual consumed gas, adding new chains in the integration tests, and modifying the logic of several test functions. The update also introduces new functions to the IbcKeeper interface and modifies the RelayerContract struct and its associated functions.

Changes

File(s) Summary
CHANGELOG.md Fixes memory store issue, re-emits logs, and adjusts gas in the relayer precompile.
app/app.go Modifies the New function to include a logger as an argument in the NewRelayerContract function.
integration_tests/configs/ibc_rly.jsonnet, integration_tests/configs/ibc_rly_evm.jsonnet Adds a new chain and modifies the relayer object in the integration tests.
integration_tests/cosmoscli.py, integration_tests/ibc_utils.py Adds new functions for RPC calls, token transfers, and retrieving gas usage records.
integration_tests/test_ibc_rly.py, integration_tests/test_ibc_rly_gas.py, integration_tests/test_ibc_timeout.py, integration_tests/test_ica_precompile.py Modifies the logic of several test functions, adds a new test function, and makes changes to fixtures and utility functions.
x/cronos/keeper/precompiles/relayer.go Updates the RelayerContract struct and its associated functions, including changes to gas calculation logic and handling for new prefixes.
x/cronos/types/interfaces.go Adds new functions to the IbcKeeper interface.

🐇🍂
As autumn leaves fall, we code and tweak,
Fixing bugs, making the system sleek.
Gas calculations now more precise,
IBC transfers, oh so nice!
New chains added, tests refined,
In every line of code, improvements you'll find.
So here's to the devs, working day and night,
Making sure every bit is just right! 🍁🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

CHANGELOG.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Merging #1232 (e5a4713) into main (394bce5) will decrease coverage by 0.04%.
The diff coverage is 45.94%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1232      +/-   ##
==========================================
- Coverage   36.93%   36.89%   -0.04%     
==========================================
  Files         115      115              
  Lines       10239    10255      +16     
==========================================
+ Hits         3782     3784       +2     
- Misses       6083     6097      +14     
  Partials      374      374              
Files Coverage Δ
x/cronos/keeper/precompiles/relayer.go 23.85% <45.94%> (-1.96%) ⬇️

@mmsqe mmsqe force-pushed the adjust_rly_gas branch 2 times, most recently from d20c56b to 2d0354f Compare November 2, 2023 10:20
@mmsqe mmsqe marked this pull request as ready for review November 6, 2023 01:54
@mmsqe mmsqe requested a review from a team as a code owner November 6, 2023 01:54
@mmsqe mmsqe requested review from yihuang and leejw51crypto and removed request for a team November 6, 2023 01:54
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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 394bce5 and ab069ac.
Files selected for processing (12)
  • CHANGELOG.md (1 hunks)
  • app/app.go (1 hunks)
  • integration_tests/configs/ibc_rly.jsonnet (1 hunks)
  • integration_tests/configs/ibc_rly_evm.jsonnet (1 hunks)
  • integration_tests/cosmoscli.py (4 hunks)
  • integration_tests/ibc_utils.py (2 hunks)
  • integration_tests/test_ibc_rly.py (4 hunks)
  • integration_tests/test_ibc_rly_gas.py (1 hunks)
  • integration_tests/test_ibc_timeout.py (1 hunks)
  • integration_tests/test_ica_precompile.py (13 hunks)
  • x/cronos/keeper/precompiles/relayer.go (4 hunks)
  • x/cronos/types/interfaces.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • integration_tests/configs/ibc_rly_evm.jsonnet
Additional comments: 23
integration_tests/configs/ibc_rly.jsonnet (1)
  • 1-24: The new chain configuration and relayer settings look good. Ensure that the environment variables VALIDATOR1_MNEMONIC and VALIDATOR2_MNEMONIC are set correctly in the test environment.
integration_tests/test_ibc_rly.py (2)
  • 13-17: The rly_transfer function is no longer imported. Ensure that this function is not used elsewhere in the codebase or that it has been replaced appropriately.

  • 44-48: The name variable in the ibc fixture has been changed from "ibc_rly" to "ibc_rly_evm". Ensure that this change does not affect other parts of the codebase that may be using this fixture.

app/app.go (1)
  • 539-539: Ensure that the NewRelayerContract function has been updated to accept a logger as an argument and that the logger is being used appropriately within the function. Also, verify that all calls to NewRelayerContract throughout the codebase have been updated to match the new signature.
- cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec),
+ cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec, app.Logger()),
x/cronos/types/interfaces.go (1)
  • 109-116: The addition of ChannelCloseInit and ChannelCloseConfirm methods to the IbcKeeper interface is a significant change. Ensure that all implementations of this interface have been updated to include these new methods. Also, verify that these methods are being used correctly in the codebase.
ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgChannelCloseInit) (*channeltypes.MsgChannelCloseInitResponse, error)
ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.MsgChannelCloseConfirm) (*channeltypes.MsgChannelCloseConfirmResponse, error)
integration_tests/test_ibc_rly_gas.py (3)
  • 1-3: The import statements are correct and necessary for the test.

  • 4-5: These import statements are also correct and necessary for the test.

  • 8-13: The pytest fixture ibc is correctly defined and will be used in the test_ibc function.

CHANGELOG.md (2)
  • 12-14: The changes to the plot_data function look good. It now includes labels for the x and y axes and a title for the plot, which will improve the readability of the plot.

  • 19-19: The change to the main part of the script is also good. It now filters the data based on the 'Category' column value of 'Electronics' before plotting. This will ensure that only relevant data is plotted.

x/cronos/keeper/precompiles/relayer.go (4)
  • 24-43: The init function has been updated to include gas requirements for two new methods: prefixChannelCloseInit and prefixChannelCloseConfirm. Ensure that these values are accurate and have been tested thoroughly.

  • 53-60: The NewRelayerContract function now requires a log.Logger as an argument. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 66-92: The RequiredGas function has been updated to calculate gas usage based on the intrinsic gas cost and the gas required by the specific method. The gas calculation logic has been updated to use the authtypes.DefaultTxSizeCostPerByte constant. Ensure that this new calculation logic is accurate and has been tested thoroughly.

  • 164-173: The Run function has been updated to include handling for two new prefixes: prefixChannelCloseInit and prefixChannelCloseConfirm. Ensure that these new cases are handled correctly and have been tested thoroughly.

integration_tests/test_ica_precompile.py (6)
  • 41-47: The fixture ibc has been renamed to ibc_rly_evm. Ensure that all references to this fixture in the test suite have been updated accordingly.

  • 74-80: The submit_msgs function now accepts an event parameter. This change improves the function's flexibility by allowing it to handle different types of events. However, ensure that all calls to this function have been updated to include this new argument.

  • 105-110: The get_logs_since function has been replaced with event.getLogs(). This change simplifies the code and reduces the need for maintaining a start variable. However, ensure that the event object is always properly initialized before this function is called.

  • 115-123: The assertion for checking logs and event arguments has been modified. Ensure that this new assertion is correct and that it does not introduce any false positives or negatives in your tests.

  • 129-135: The get_method_map and get_topic_data functions have been removed. Ensure that these functions were not used elsewhere in the codebase.

  • 309-314: The submit_msgs function is now called with the new event argument. Ensure that the passed event is the correct one for each test case.

integration_tests/cosmoscli.py (3)
  • 12-12: The requests module is imported, which is a popular Python library for making HTTP requests. It abstracts the complexities of making requests behind a beautiful, simple API so that you can focus on interacting with services and consuming data in your application.

  • 225-234: A new method tx_search_rpc is added. This method performs an RPC call to search for transactions based on the given criteria. It constructs the HTTP URL for the RPC call, sends a GET request with the search criteria as a parameter, and returns the transactions found. It also checks if there is an error in the response and raises an assertion error if there is.

  • 1267-1269: The transfer_tokens method now makes an additional call to event_query_tx_for if the transaction code is 0. This is likely to fetch and return more detailed information about the transaction. Ensure that the event_query_tx_for method is implemented and works as expected.

integration_tests/test_ibc_timeout.py Show resolved Hide resolved
integration_tests/test_ibc_rly_gas.py Show resolved Hide resolved
integration_tests/test_ibc_rly_gas.py Show resolved Hide resolved
integration_tests/ibc_utils.py Show resolved Hide resolved
integration_tests/ibc_utils.py Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ab069ac and 7b3c0f4.
Files selected for processing (1)
  • x/cronos/keeper/precompiles/relayer.go (4 hunks)
Additional comments: 3
x/cronos/keeper/precompiles/relayer.go (3)
  • 45-60: The RelayerContract struct now includes a logger field. Ensure that all instances of RelayerContract are updated to include this field.

  • 68-93: The RequiredGas function now calculates the gas usage based on the input size, intrinsic gas, and a gas table. This is a more accurate way of calculating gas usage than a flat rate, but it might be more complex and slower. Consider benchmarking this function to ensure it doesn't become a performance bottleneck.

  • 165-171: New cases for prefixChannelCloseInit and prefixChannelCloseConfirm have been added to the Run function. These cases call the corresponding functions in ibcKeeper. Ensure that these functions are implemented and work as expected.

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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7b3c0f4 and 5eefb77.
Files selected for processing (1)
  • x/cronos/keeper/precompiles/relayer.go (4 hunks)
Additional comments: 1
x/cronos/keeper/precompiles/relayer.go (1)
  • 72-72: The intrinsic gas is calculated using the Ethereum's core.IntrinsicGas function. This might not be the best approach as the gas cost should be related to the Cosmos cost (i.e., storage operations), not the Ethereum one. Please verify if this is the intended behavior.

x/cronos/keeper/precompiles/relayer.go Show resolved Hide resolved
x/cronos/keeper/precompiles/relayer.go Show resolved Hide resolved
x/cronos/keeper/precompiles/relayer.go Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5eefb77 and e5a4713.
Files selected for processing (1)
  • x/cronos/keeper/precompiles/relayer.go (4 hunks)
Additional comments: 2
x/cronos/keeper/precompiles/relayer.go (2)
  • 45-60: The RelayerContract struct now includes a logger field of type log.Logger. The NewRelayerContract function has been modified to require a logger. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 163-172: The Run function has been updated to include handling for the prefixChannelCloseInit and prefixChannelCloseConfirm methods. Ensure that these methods are implemented correctly and that they are being called with the correct arguments.

x/cronos/keeper/precompiles/relayer.go Show resolved Hide resolved
x/cronos/keeper/precompiles/relayer.go Show resolved Hide resolved
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.

3 participants