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

refactor(evm): removed blockGasUsed transient variable #2167

Merged
merged 5 commits into from
Jan 17, 2025

Conversation

onikonychev
Copy link
Contributor

@onikonychev onikonychev commented Jan 15, 2025

  1. Got rid of the unnecessary EvmKeeper.EvmState.BlockGasUsed variable
  2. Added test for gas usage in case of multiple eth messages in one transaction
  3. Fixed evm tx indexer for the case of multiple eth messages in one transaction

Summary by CodeRabbit

Based on the comprehensive summary, here are the updated release notes:

  • New Features

    • Enhanced EVM event emissions and parsing capabilities.
    • Improved transaction gas usage tracking for multiple messages.
  • Bug Fixes

    • Refined gas consumption logic during Ethereum transaction processing.
    • Improved transaction event handling and indexing.
  • Refactoring

    • Simplified gas meter management across EVM modules.
    • Streamlined transaction and contract interaction testing.
    • Removed transient block gas tracking mechanisms.
  • Testing

    • Added new test cases for gas usage and transaction nonce increments.
    • Improved test coverage for EVM and precompile interactions.

The changes focus on optimizing the EVM's gas management and transaction processing infrastructure, with an emphasis on more efficient and accurate gas tracking.

@onikonychev onikonychev requested a review from a team as a code owner January 15, 2025 12:30
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Warning

Rate limit exceeded

@Unique-Divine has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 55 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

Reviewing files that changed from the base of the PR and between 4769ab0 and ad957e3.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)

Walkthrough

This pull request introduces significant changes to the Nibiru EVM project's gas management and transaction processing. The primary modification involves removing the transient blockGasUsed variable and associated methods across multiple files. The changes simplify gas tracking logic, streamline transaction processing, and remove redundant gas meter reset functionality. The modifications affect various components, including the EVM keeper, RPC backend, and test suites, with a focus on more direct gas consumption handling.

Changes

File Change Summary
CHANGELOG.md New entries documenting various fixes and features
x/evm/keeper/evm_state.go Removed BlockGasUsed field and ResetTransientGasUsed method
x/evm/keeper/keeper.go Deleted AddToBlockGasUsed method
x/evm/keeper/gas_fees.go Removed ResetGasMeterAndConsumeGas method
x/evm/keeper/msg_server.go Simplified gas consumption logic in EthereumTx and ConvertCoinToEvm methods
Multiple test files Removed deps.ResetGasMeter() calls across various test suites

Sequence Diagram

sequenceDiagram
    participant Client
    participant EVMKeeper
    participant GasMeter
    participant Transaction

    Client->>EVMKeeper: Execute Transaction
    EVMKeeper->>Transaction: Process Transaction
    Transaction->>GasMeter: Consume Gas Directly
    GasMeter-->>Transaction: Gas Consumption Tracked
    Transaction-->>EVMKeeper: Transaction Result
    EVMKeeper-->>Client: Transaction Response
Loading

Possibly related PRs

Suggested reviewers

  • Unique-Divine
  • k-yang

Poem

🐰 Hop, hop, through the EVM's maze,
Goodbye blockGasUsed, simplifying our ways!
Gas flows freely, no more reset's might,
Transactions dance with newfound light!
Code leaps forward, clean and bright! 🔥


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

🧹 Nitpick comments (2)
CHANGELOG.md (1)

80-80: Consider adding more context about gas tracking simplification.

While the entry is clear, consider expanding it to mention the impact on gas tracking logic as noted in the AI summary. This would provide better context for the change.

-refactor(evm): removed blockGasUsed transient variable
+refactor(evm): removed blockGasUsed transient variable to simplify gas tracking logic
eth/rpc/backend/backend_suite_test.go (1)

246-250: LGTM! Consider adding parameter validation.

The parameterization of gas limits and parameter reordering improves both flexibility and readability. Consider adding validation to ensure gasLimit is not zero.

 func (s *BackendSuite) buildContractCallTx(
 	contractAddr gethcommon.Address,
 	nonce uint64,
 	gasLimit uint64,
 ) gethcore.Transaction {
+	if gasLimit == 0 {
+		s.T().Fatal("gas limit cannot be zero")
+	}
 	// recipient := crypto.CreateAddress(s.fundedAccEthAddr, 29381)
 	transferAmount := big.NewInt(100)

Also applies to: 264-264

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8731a9e and 42b1104.

📒 Files selected for processing (19)
  • CHANGELOG.md (1 hunks)
  • app/evmante/evmante_setup_ctx.go (0 hunks)
  • app/evmante/evmante_setup_ctx_test.go (0 hunks)
  • eth/indexer/evm_tx_indexer_test.go (2 hunks)
  • eth/rpc/backend/backend_suite_test.go (3 hunks)
  • eth/rpc/backend/gas_used_test.go (1 hunks)
  • eth/rpc/backend/nonce_test.go (1 hunks)
  • eth/rpc/events_parser.go (1 hunks)
  • x/evm/evmtest/test_deps.go (0 hunks)
  • x/evm/keeper/evm_state.go (0 hunks)
  • x/evm/keeper/funtoken_from_coin.go (1 hunks)
  • x/evm/keeper/funtoken_from_coin_test.go (0 hunks)
  • x/evm/keeper/funtoken_from_erc20_test.go (0 hunks)
  • x/evm/keeper/gas_fees.go (0 hunks)
  • x/evm/keeper/keeper.go (0 hunks)
  • x/evm/keeper/msg_server.go (2 hunks)
  • x/evm/precompile/funtoken_test.go (0 hunks)
  • x/evm/precompile/test/export.go (0 hunks)
  • x/evm/precompile/wasm_test.go (0 hunks)
💤 Files with no reviewable changes (11)
  • app/evmante/evmante_setup_ctx.go
  • app/evmante/evmante_setup_ctx_test.go
  • x/evm/precompile/test/export.go
  • x/evm/keeper/evm_state.go
  • x/evm/keeper/keeper.go
  • x/evm/keeper/gas_fees.go
  • x/evm/evmtest/test_deps.go
  • x/evm/precompile/wasm_test.go
  • x/evm/precompile/funtoken_test.go
  • x/evm/keeper/funtoken_from_erc20_test.go
  • x/evm/keeper/funtoken_from_coin_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: integration-tests
🔇 Additional comments (12)
eth/indexer/evm_tx_indexer_test.go (2)

4-4: LGTM: Import addition is necessary.

The fmt package import is required for formatting the eth_hash attribute value.


113-113: LGTM: Enhanced event attribute verification.

The addition of the eth_hash attribute in the test case improves verification of transaction hash handling in Ethereum events, ensuring consistency between pending_ethereum_tx and EventEthereumTx events.

x/evm/keeper/msg_server.go (2)

83-83: LGTM! Gas consumption is now more direct and accurate.

The change simplifies gas tracking by directly consuming the actual gas used from the EVM response, removing the need for intermediate calculations.


564-564: LGTM! Consistent gas consumption pattern for ERC20 minting.

The change maintains consistency with the simplified gas tracking approach, directly consuming the actual gas used from the EVM response.

CHANGELOG.md (2)

80-80: LGTM! The changelog entry accurately reflects the PR objectives.

The entry "refactor(evm): removed blockGasUsed transient variable" clearly and concisely describes the change, following the conventional commit format with type(scope): description.


Line range hint 1-24: LGTM! The changelog follows best practices.

The changelog is well-structured following the Keep a Changelog format with:

  • Clear version headers and links
  • Proper categorization of changes
  • PR references
  • Semantic versioning
x/evm/keeper/funtoken_from_coin.go (2)

87-87: LGTM! Gas consumption is now handled more directly.

The simplified gas consumption logic aligns well with the PR objective of removing the blockGasUsed variable while maintaining proper gas tracking.


87-87: Verify gas consumption behavior with multiple messages.

Since this PR aims to improve handling of multiple Ethereum messages within a single transaction, let's verify that the gas consumption is correctly tracked in such scenarios.

✅ Verification successful

Gas consumption behavior is properly implemented for multiple messages

The gas consumption implementation correctly tracks and accumulates gas usage across multiple Ethereum messages within a single transaction. This is verified by:

  • Individual gas consumption tracking for each operation (deploy, mint, execute)
  • Proper gas metering implementation in the msg_server
  • Comprehensive test coverage in gas_used_test.go that verifies correct gas accounting across multiple messages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for test cases that verify gas consumption with multiple messages
# and check if the gas consumption is properly tracked.

# Look for test files containing multiple message tests
echo "Searching for relevant test files..."
rg -l "multiple|message.*transaction|gas.*consumption" --type go

# Look for specific gas consumption patterns in EVM calls
echo "Checking gas consumption patterns..."
ast-grep --pattern 'CallContractWithInput($$$)'

# Look for gas meter usage patterns
echo "Checking gas meter usage..."
rg -A 2 "GasMeter\(\).ConsumeGas"

Length of output: 1955


Script:

#!/bin/bash
# Search for test cases specifically handling multiple messages and gas tracking
echo "Searching test files for multiple message scenarios..."
rg -B 2 -A 5 "TestMultiple|TestGas.*Message" --type go

echo "Checking msg_server implementation for gas tracking..."
rg -B 2 -A 5 "func \(k Keeper\) (Eth|MsgEth).*Message" x/evm/keeper/msg_server.go

echo "Looking for gas tracking in tests..."
rg -B 2 -A 5 "GasMeter.*Assert" --type go

Length of output: 1535


Script:

#!/bin/bash
# Examine the multiple message gas usage test implementation
echo "Checking multiple messages gas usage test implementation..."
rg -B 10 -A 20 "TestMultipleMsgsTxGasUsage" eth/rpc/backend/gas_used_test.go

# Look for related gas tracking utilities
echo "Checking gas tracking utilities..."
rg -l "GasUsed.*multiple|gas.*tracking" --type go

Length of output: 1505

eth/rpc/events_parser.go (1)

89-92: Robust replacement of pending transactions using transaction hash

The updated logic replaces pending transactions by matching the transaction hash (EthHash), which is more reliable than relying solely on the message index (MsgIndex). This change enhances the robustness of the transaction parsing process and ensures accurate transaction mapping.

eth/rpc/backend/nonce_test.go (1)

23-25: ⚠️ Potential issue

Verify function parameter alignment for buildContractCallTx

The buildContractCallTx function's signature has been updated to include an additional parameter. Ensure that the argument 100_000 corresponds to the correct parameter in the updated function signature. There might be a mismatch between the expected gasLimit or amount parameter and the provided arguments.

eth/rpc/backend/gas_used_test.go (1)

191-234: Comprehensive test for gas usage with multiple messages

The TestMultipleMsgsTxGasUsage function is a valuable addition that effectively verifies gas consumption for each message within a single transaction. The test correctly asserts that the gas used is within expected limits and that the account balance reflects the total gas consumed. The implementation follows best practices and enhances test coverage.

eth/rpc/backend/backend_suite_test.go (1)

226-226: LGTM! Good improvement in test flexibility.

The parameterization of gas limits allows for more comprehensive testing of different gas usage scenarios, which aligns well with the PR's goal of improving gas usage tracking.

Also applies to: 234-234

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.13%. Comparing base (04bd7c2) to head (ad957e3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2167      +/-   ##
==========================================
- Coverage   65.14%   65.13%   -0.02%     
==========================================
  Files         277      277              
  Lines       22284    22238      -46     
==========================================
- Hits        14518    14485      -33     
+ Misses       6771     6762       -9     
+ Partials      995      991       -4     
Files with missing lines Coverage Δ
app/evmante/evmante_setup_ctx.go 66.66% <ø> (-4.77%) ⬇️
eth/rpc/events_parser.go 54.95% <100.00%> (ø)
x/evm/evmtest/test_deps.go 100.00% <ø> (+10.00%) ⬆️
x/evm/keeper/evm_state.go 84.52% <ø> (-1.20%) ⬇️
x/evm/keeper/funtoken_from_coin.go 78.94% <100.00%> (+4.75%) ⬆️
x/evm/keeper/gas_fees.go 64.42% <ø> (-1.32%) ⬇️
x/evm/keeper/keeper.go 64.28% <ø> (-4.24%) ⬇️
x/evm/keeper/msg_server.go 77.68% <100.00%> (+0.88%) ⬆️

... and 1 file with indirect coverage changes

@Unique-Divine Unique-Divine merged commit f3ca671 into main Jan 17, 2025
15 checks passed
@Unique-Divine Unique-Divine deleted the refactor/block-gas-used branch January 17, 2025 08:40
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