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

Set a non-zero BaseFeePerGas on block responses #648

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Nov 6, 2024

Closes: #647

Description

Also update the eth_maxPriorityFeePerGas to return the configured gas price.

Example usage of hardhat ignition deployment:

$ npx hardhat ignition deploy ./ignition/modules/Lock.ts  --network testnet --verbose --show-stack-traces

Hardhat Ignition 🚀

Deploying [ LockModule ]

Batch #1
  Executing LockModule#Lock...
Batch #1
  Executed LockModule#Lock

[ LockModule ] successfully deployed 🚀

Deployed Addresses

LockModule#Lock - 0x3d636a648df1964feE061AD7A89AacaDa1b0F728

Example usage of forge create:

$ forge create --rpc-url='http://localhost:8545' --private-key='0xc3a9ecb56c3ad2c5e3dc7b228f458f63c4a33de571317842d3e89f96b8e3901c' tests/fixtures/storage.sol:Storage

[⠊] Compiling...
[⠢] Compiling 1 files with Solc 0.8.26
[⠆] Solc 0.8.26 finished in 118.60ms
Compiler run successful with warnings:
Warning (5159): "selfdestruct" has been deprecated. Note that, starting from the Cancun hard fork, the underlying opcode no longer deletes the code and data associated with an account and only transfers its Ether to the beneficiary, unless executed in the same transaction in which the contract was created (see EIP-6780). Any use in newly deployed contracts is strongly discouraged even if the new behavior is taken into account. Future changes to the EVM might further reduce the functionality of the opcode.
  --> tests/fixtures/storage.sol:64:9:
   |
64 |         selfdestruct(payable(msg.sender));
   |         ^^^^^^^^^^^^

Deployer: 0x2502E08Ebb5375cdC1d64c68dA8aB38a27E76FFA
Deployed to: 0x3d636a648df1964feE061AD7A89AacaDa1b0F728
Transaction hash: 0x0eeaa0d7fc835818527ff6e7af28c19586ade9de61024d7a18bd807f8739ef1c

Example usage of cast send:

$ cast send 0x3d636a648df1964feE061AD7A89AacaDa1b0F728 --rpc-url='http://localhost:8545' --private-key='0xc3a9ecb56c3ad2c5e3dc7b228f458f63c4a33de571317842d3e89f96b8e3901c' "storeWithLog(uint256 num)" 42

blockHash               0xad9bedad5c92ead24951a732f4244fc32a89c56855b30ca4f18673638cb22703
blockNumber             4
contractAddress         
cumulativeGasUsed       28024
effectiveGasPrice       1000000000
from                    0x2502E08Ebb5375cdC1d64c68dA8aB38a27E76FFA
gasUsed                 28024
logs                    [{"address":"0x3d636a648df1964fee061ad7a89aacada1b0f728","topics":["0x043cc306157a91d747b36aba0e235bbbc5771d75aba162f6e5540767d22673c6","0x0000000000000000000000002502e08ebb5375cdc1d64c68da8ab38a27e76ffa","0x000000000000000000000000000000000000000000000000000000000000002a"],"data":"0x","blockHash":"0xad9bedad5c92ead24951a732f4244fc32a89c56855b30ca4f18673638cb22703","blockNumber":"0x4","transactionHash":"0xa051d40c1359bfceb9bb4b9168150b4c6baa15ae0bc8126245df2eff5a2d2209","transactionIndex":"0x0","logIndex":"0x0","removed":false}]
logsBloom               0x00000000000000000000200000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000080000080400000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000004000000000000000000000000001000000000000000000000000000800000000000000000000000000000000000000000000000000000000000100000000000000000000000000020000000000000000000000000000000000000
root                    
status                  1 (success)
transactionHash         0xa051d40c1359bfceb9bb4b9168150b4c6baa15ae0bc8126245df2eff5a2d2209
transactionIndex        0
type                    2
blobGasPrice            
blobGasUsed             
to                      0x3d636a648df1964feE061AD7A89AacaDa1b0F728

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features
    • Enhanced dynamic handling of gas fees in the API for more accurate fee calculations.
  • Bug Fixes
    • Updated tests for fetching fee history to reflect new base fee values.
  • Tests
    • Improved test cases in the Web3 API suite to validate various functionalities with updated fee expectations.

Also update the eth_maxPriorityFeePerGas to return the configured
gas price.
Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes in this pull request introduce a new variable baseFeesPerGas initialized to 1, replacing the hardcoded zero value in the FeeHistory method. The GetBlockByHash and GetBlockByNumber methods have been updated to use this variable for setting the BaseFeePerGas field in the Block struct. Additionally, the MaxPriorityFeePerGas method now returns a configured gas price instead of a fixed value. The test file eth_non_interactive_test.js has been updated to reflect these changes in expected values.

Changes

File Change Summary
api/api.go Added baseFeesPerGas variable; updated FeeHistory, GetBlockByHash, GetBlockByNumber, and MaxPriorityFeePerGas methods to use baseFeesPerGas instead of hardcoded values.
tests/web3js/eth_non_interactive_test.js Modified tests to expect baseFeePerGas values as ones instead of zeros in fee history tests.

Assessment against linked issues

Objective Addressed Explanation
Ensure non-zero gas prices are handled correctly in deployments (#647)

Possibly related PRs

Suggested reviewers

  • peterargue
  • sideninja

🐰 In the land of code where rabbits hop,
A base fee rises, never to stop.
From zero to one, a change so bright,
Gas fees now dance in the moonlight.
With tests that check and ensure the way,
Our API shines, come what may! 🌙✨


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.

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

🧹 Outside diff range and nitpick comments (2)
api/api.go (2)

35-35: Consider declaring as a constant.

While the implementation is correct, consider declaring this as a constant since it represents a fixed value that shouldn't change during runtime.

-var baseFeesPerGas = big.NewInt(1)
+const baseFeesPerGasValue = 1
+var baseFeesPerGas = big.NewInt(baseFeesPerGasValue)

1235-1235: Add documentation explaining the gas price usage.

While the implementation is correct, please add a comment explaining why we're using the configured gas price as the priority fee. This helps clarify the relationship between these two concepts for future maintainers.

 // MaxPriorityFeePerGas returns a suggestion for a gas tip cap for dynamic fee transactions.
+// We use the configured gas price as the priority fee to ensure consistency
+// across the API and to maintain compatibility with EIP-1559 transactions.
 func (b *BlockChainAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) {
 	return (*hexutil.Big)(b.config.GasPrice), nil
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6f350 and e8ae478.

📒 Files selected for processing (2)
  • api/api.go (4 hunks)
  • tests/web3js/eth_non_interactive_test.js (1 hunks)
🔇 Additional comments (4)
tests/web3js/eth_non_interactive_test.js (2)

382-382: LGTM! The updated test aligns with the non-zero BaseFeePerGas requirement.

The change from zero to non-zero (1n) values for baseFeePerGas correctly reflects the implementation of non-zero base fees in block responses, which addresses the Hardhat ignition deployment issues mentioned in #647.


379-384: Verify test coverage for gas fee calculations.

The test validates the basic fee history structure, but consider adding additional test cases to verify:

  1. The consistency of baseFeePerGas across different block ranges
  2. The interaction between baseFeePerGas and maxPriorityFeePerGas
  3. Edge cases with varying block numbers and percentiles

This would ensure robust validation of the gas fee calculation changes.

api/api.go (2)

942-942: LGTM!

The change correctly uses the non-zero baseFeesPerGas in fee history responses, ensuring consistency with block responses.


1058-1058: LGTM!

The change correctly sets a non-zero base fee in block responses, which directly addresses the issue with Hardhat ignition deployments.

@m-Peter m-Peter merged commit 8d71209 into main Nov 7, 2024
2 checks passed
@m-Peter m-Peter deleted the mpeter/fix-hardhat-ignition-deployment branch November 7, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Hardhat ignition deployments fail on testnet & mainnet
3 participants