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

fix: remove tx option defaults #193

Merged
merged 1 commit into from
Nov 8, 2024
Merged

fix: remove tx option defaults #193

merged 1 commit into from
Nov 8, 2024

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Nov 7, 2024

Each chain has its own gas limit and price and having defaults prevents hardhat from inheriting these values from config. This resulted in tx broadcasting being stuck.

Summary by CodeRabbit

  • New Features

    • Updated the evmDepositAndCall task to allow for more flexible gas settings by removing default values for gasPrice and gasLimit.
  • Bug Fixes

    • Enhanced the handling of optional parameters for improved clarity and usability.

@fadeev fadeev requested review from andresaiello and a team as code owners November 7, 2024 16:23
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

📝 Walkthrough

Walkthrough

The changes in the pull request focus on the evmDepositAndCall task within the packages/tasks/src/evmDepositAndCall.ts file. Specifically, the default values for the optional parameters gasPrice and gasLimit have been removed. This adjustment simplifies the parameter definitions, while all other parameters and the overall functionality of the task remain unchanged.

Changes

File Path Change Summary
packages/tasks/src/evmDepositAndCall.ts Removed default values for optional parameters gasPrice and gasLimit.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EVMTask

    User->>EVMTask: Call evmDepositAndCall(gasPrice, gasLimit, ...)
    EVMTask-->>User: Execute transaction with provided parameters
Loading

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.

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 (1)
packages/tasks/src/evmDepositAndCall.ts (1)

Line range hint 8-31: Improve error handling and type validation.

The current error handling could be enhanced to provide better debugging information and prevent potential issues:

  1. The generic error handling masks specific issues
  2. JSON parsing of types could fail silently
  3. No validation between parsed types and provided values

Consider this improvement:

 export const evmDepositAndCall = async (
   args: any,
   hre: HardhatRuntimeEnvironment
 ) => {
+  let parsedTypes;
   try {
+    parsedTypes = JSON.parse(args.types);
+    if (!Array.isArray(parsedTypes) || parsedTypes.length !== args.values.length) {
+      throw new Error("Types array length must match values array length");
+    }
     const [signer] = await hre.ethers.getSigners();
     const client = new ZetaChainClient({ network: "testnet", signer });
     const tx = await client.evmDepositAndCall({
       amount: args.amount,
       erc20: args.erc20,
       gatewayEvm: args.gatewayEvm,
       receiver: args.receiver,
       revertOptions: {
         callOnRevert: args.callOnRevert,
         onRevertGasLimit: args.onRevertGasLimit,
         revertAddress: args.revertAddress,
         revertMessage: args.revertMessage,
       },
       txOptions: {
         gasLimit: args.gasLimit,
         gasPrice: args.gasPrice,
       },
-      types: JSON.parse(args.types),
+      types: parsedTypes,
       values: args.values,
     });
     if (tx) {
       const receipt = await tx.wait();
       console.log("Transaction hash:", receipt.transactionHash);
     }
   } catch (e) {
-    console.error("Transaction error:", e);
+    if (e instanceof SyntaxError) {
+      console.error("Invalid JSON format for types:", e.message);
+    } else {
+      console.error("Transaction failed:", e instanceof Error ? e.message : String(e));
+    }
+    process.exit(1);
   }
 };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f0b0244 and e8a76c0.

📒 Files selected for processing (1)
  • packages/tasks/src/evmDepositAndCall.ts (1 hunks)
🔇 Additional comments (1)
packages/tasks/src/evmDepositAndCall.ts (1)

54-55: LGTM! Removing default gas values is a good practice.

Removing hardcoded defaults for gasPrice and gasLimit is the right approach as these values should be network-specific and determined at runtime. This change helps prevent potential issues with inappropriate gas values across different networks.

Let's verify the error handling when these values are not provided:

Consider adding JSDoc comments to these parameters to document:

  1. That these values are required
  2. The expected format (e.g., wei for gasPrice)
  3. Recommendations for obtaining appropriate values
✅ Verification successful

The previous search showed that gas parameters are used across the codebase, but we need to verify specifically how the evmDepositAndCall function handles missing gas values to ensure removing defaults is safe.


We need to verify how transaction options are validated before being used in the client implementation to ensure removing defaults is safe.


We need to understand how the transaction options are defined and validated in the client implementation to ensure removing defaults is safe.


Removing default gas values is safe and recommended

The code inspection confirms that:

  1. Gas values are passed through from task arguments to the client implementation without modification
  2. The client implementation expects these values in the txOptions type and uses them directly
  3. There's no fallback logic or default values in the client implementation

This validates that removing hardcoded defaults from the task is the correct approach as it:

  • Forces users to provide appropriate network-specific gas values
  • Aligns with the client implementation's expectations
  • Prevents potential issues from using inappropriate default values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there's proper error handling or documentation for missing gas values

# Test 1: Look for error handling related to missing gas values
rg -A 5 "gasLimit|gasPrice" --type ts

# Test 2: Check for related documentation
fd -e md -e txt . -x grep -l "gasLimit|gasPrice"

Length of output: 53598


Script:

#!/bin/bash
# Let's check how the gas values are handled in the evmDepositAndCall task implementation

# Check the implementation of evmDepositAndCall function in the client
rg -A 10 "export const evmDepositAndCall" packages/client/src/evmDepositAndCall.ts

# Check if there's error handling for missing gas values
rg -A 5 "if \(!.*gas.*\)" packages/client/src/

Length of output: 403


Script:

#!/bin/bash
# Let's check how the client validates and handles transaction options

# Check the txOptions type definition and usage
rg -A 5 "txOptions.*{" packages/client/src/

# Check if there's validation in the evmDepositAndCall implementation
ast-grep --pattern 'export const evmDepositAndCall = async function ($_, $_) {
  $$$
  const tx = await $$$
  $$$
}'

Length of output: 252


Script:

#!/bin/bash
# Let's check the type definitions and validation

# Check type definitions
rg "type txOptions" packages/client/src/

# Check how evmDepositAndCall is implemented
rg -l "evmDepositAndCall" packages/client/src/
rg -A 20 "evmDepositAndCall.*=" packages/client/src/evmDepositAndCall.ts

# Check if there's any validation before using txOptions
rg -B 5 -A 10 "txOptions\." packages/client/src/evmDepositAndCall.ts

Length of output: 1458

@fadeev fadeev merged commit 3caf26b into main Nov 8, 2024
5 checks passed
@fadeev fadeev deleted the tx-options-remove-defaults branch November 8, 2024 06:49
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