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

feat: add gas limit for sumitBridgeCall #843

Merged
merged 1 commit into from
Dec 28, 2024
Merged

feat: add gas limit for sumitBridgeCall #843

merged 1 commit into from
Dec 28, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Dec 27, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a gas_limit field for bridge calls, enhancing gas management.
    • Updated API documentation to include the new gas_limit parameter.
  • Bug Fixes

    • Improved validation for GasLimit to ensure it is non-negative and valid.
  • Documentation

    • Enhanced Swagger YAML documentation with the new gas_limit field across multiple definitions.
  • Tests

    • Updated tests to reflect the addition of the GasLimit field in the OutgoingBridgeCall structure.

Copy link

coderabbitai bot commented Dec 27, 2024

Walkthrough

This pull request introduces a comprehensive enhancement to the cross-chain bridge functionality by adding a gas_limit field across multiple components of the system. The changes span from protobuf definitions to Solidity contracts, Go implementations, and documentation, ensuring consistent gas limit handling for bridge calls. The modifications enable more precise control over gas consumption during cross-chain transactions by introducing a new parameter that can be specified and validated throughout the bridge call process.

Changes

File Change Summary
api/fx/gravity/crosschain/v1/types.pulsar.go Added gas_limit field to OutgoingBridgeCall message
contract/contract.go Updated PackBridgeCallCheckpoint function signature to include gasLimit parameter
contract/crosschain.go Added validation for GasLimit in BridgeCallArgs
contract/ifx_bridge_logic.sol.go Added GasLimit field to IFxBridgeLogicBridgeCallData struct and updated related methods
docs/swagger-ui/swagger.yaml Added gas_limit field with uint64 format in API documentation
proto/fx/gravity/crosschain/v1/types.proto Reordered OutgoingBridgeCall fields and added gas_limit
solidity/contracts/bridge/IFxBridgeLogic.sol Added gasLimit to BridgeCallData struct and bridgeCallCheckpoint function
x/crosschain/keeper/bridge_call_out.go Updated method signatures to include gasLimit parameter
x/crosschain/types/types.go Modified checkpoint generation and quote info to incorporate gas limit
x/crosschain/types/types_test.go Updated test cases to include GasLimit field

Sequence Diagram

sequenceDiagram
    participant Client
    participant BridgeContract
    participant Validator
    
    Client->>BridgeContract: bridgeCall(data, gasLimit)
    BridgeContract->>Validator: Validate gasLimit
    Validator-->>BridgeContract: Validation Result
    BridgeContract->>BridgeContract: Process Bridge Call
    BridgeContract-->>Client: Bridge Call Executed
Loading

Possibly related PRs

Poem

🐰 Hopping across the blockchain lane,
Gas limits now dance, no longer plain!
Bytes of freedom, limits so neat,
Bridge calls now have a rhythmic beat 🌉
Rabbit's code hops with precise delight! 🚀


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

@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: 1

🧹 Nitpick comments (5)
x/crosschain/keeper/bridge_call_out.go (1)

Line range hint 29-38: Validate gasLimit and eventNonce usage in AddOutgoingBridgeCall.
This method's signature has grown, now including gasLimit and eventNonce. It's advisable to validate gasLimit doesn't exceed any configured or recommended upper bound and confirm the correctness of eventNonce (e.g., verifying it's non-zero if required). This ensures tighter control over resource usage and consistency across the codebase.

contract/ifx_bridge_logic.sol.go (2)

63-63: ABI changes to include _gasLimit.
The updated ABI correctly reflects the new gas limit parameter in bridging methods. Ensure all dependent tools and deployments are updated (e.g., front-ends, off-chain signers, or UI components) to handle the new parameter.

Would you like help generating a migration checklist for dependencies that parse or interact with this ABI?


916-932: Extended SubmitBridgeCall with new BridgeCallData fields.
The structure _input now contains GasLimit. Confirm that all off-chain or on-chain logic employing SubmitBridgeCall is updated to supply or manage gas limit constraints. Failure to do so might result in unexpected reverts or partial success.

solidity/contracts/bridge/IFxBridgeLogic.sol (1)

59-59: Introducing gasLimit field in BridgeCallData struct.
This field aligns with the crosschain adjustments, but confirm any front-ends or services constructing BridgeCallData also provide a valid gas limit. If the contract logic allows a default or fallback, consider clarifying it in documentation.

docs/swagger-ui/swagger.yaml (1)

5834-5836: Add documentation for the gas_limit field.

Consider adding a description field to document:

  • The purpose of gas_limit
  • Any constraints or valid ranges
  • Example values

Add documentation like this:

   gas_limit:
     type: string
     format: uint64
+    description: Specifies the maximum amount of gas that can be used for the bridge call execution
+    example: "3000000"
+    minimum: "0"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 114f844 and 9298495.

⛔ Files ignored due to path filters (1)
  • x/crosschain/types/types.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (10)
  • api/fx/gravity/crosschain/v1/types.pulsar.go (16 hunks)
  • contract/contract.go (2 hunks)
  • contract/crosschain.go (1 hunks)
  • contract/ifx_bridge_logic.sol.go (9 hunks)
  • docs/swagger-ui/swagger.yaml (11 hunks)
  • proto/fx/gravity/crosschain/v1/types.proto (1 hunks)
  • solidity/contracts/bridge/IFxBridgeLogic.sol (2 hunks)
  • x/crosschain/keeper/bridge_call_out.go (5 hunks)
  • x/crosschain/types/types.go (1 hunks)
  • x/crosschain/types/types_test.go (1 hunks)
🔇 Additional comments (28)
x/crosschain/keeper/bridge_call_out.go (4)

41-41: Double-check success path handling after BuildOutgoingBridgeCall.
After building an outgoing bridge call, consider checking any additional invariants (e.g., verifying gasLimit again, if there's a maximum or re-check logic). Also, consider adding logs or metrics capturing the new gasLimit parameter for easier tracking.


Line range hint 79-95: Consistent usage of gasLimit in BuildOutgoingBridgeCall.
Here, the function includes a new gasLimit parameter. Be sure this is always aligned with other checks in the system (like max gas limit from parameters). The rest of the logic for constructing the OutgoingBridgeCall object looks consistent. Ensure any future changes in gasLimit validation are uniformly applied throughout this code path.


97-97: GasLimit assignment.
The assignment of GasLimit: gasLimit is straightforward. Just confirm that higher-level validation (e.g., in a Validate() method) or parameter constraints exist to catch any malformed or excessively large values.


292-292: Event nonce hard-coded to 0 in BridgeCallBaseCoin.
While passing gasLimit.Uint64() is correct, always hard-coding eventNonce to 0 might cause confusion or break event-order assumptions elsewhere. Verify whether this is intentional or if a real event nonce should be determined before invocation.

contract/ifx_bridge_logic.sol.go (3)

42-42: New GasLimit field in IFxBridgeLogicBridgeCallData.
This addition aligns with the bridging changes, enabling explicit gas allocation. Confirm that inbound calls properly set or clamp this value to reduce potential out-of-gas or exceeding-limit issues.


769-787: BridgeCallCheckpoint extended with _gasLimit.
Including _gasLimit in bridgeCallCheckpoint helps unify cross-chain message consistency. Verify that the new field is accounted for in the checkpoint logic (e.g., hashing/encoding). A mismatch in the checkpoint payload vs. contract expectation could break bridging.


Line range hint 1233-1313: Enhanced BridgeCallEvent logic for GasLimit.
Filtering and parsing now incorporate the _gasLimit index in the event. Ensure consistent indexing in event watchers or logs-based off-chain tooling. Missing or mismatched indexing typically leads to decoding failures or inaccurate metrics.

contract/crosschain.go (1)

73-75: GasLimit validation checks.
This validation guards against negative or overly large values (via IsUint64()). Consider also checking for zero if that's invalid in your context. This ensures bridging calls do not proceed with nonsensical or harmful gas limit values.

solidity/contracts/bridge/IFxBridgeLogic.sol (1)

194-194: bridgeCallCheckpoint gains _gasLimit.
Revisiting the architecture that calculates or references _gasLimit is essential to maintain bridging correctness. Ensure all references to this updated signature consistently pass the correct argument.

x/crosschain/types/types_test.go (2)

81-81: Consider verifying a more realistic GasLimit.
A gas limit of 1 might be too small to simulate real-world usage and could potentially mask out-of-gas scenarios in production-like scenarios.


87-87: Updated expected checkpoint looks good.
The new hash appears consistent with the inclusion of the GasLimit field in the checkpoint.

x/crosschain/types/types.go (1)

474-474: Be cautious with uint64 to int64 conversion.
Here, m.GasLimit is cast to int64. If GasLimit can exceed 2^63 - 1, this may cause an overflow. Consider validating the maximum allowable GasLimit before conversion.

 func (m *OutgoingBridgeCall) GetCheckpoint(gravityIDString string) ([]byte, error) {
     ...
-    big.NewInt(int64(m.GasLimit)),
+    if m.GasLimit > math.MaxInt64 {
+        return nil, fmt.Errorf("gas limit overflow: %d > MaxInt64", m.GasLimit)
+    }
+    gasLimitBigInt := big.NewInt(int64(m.GasLimit))
     ...
 }
contract/contract.go (2)

187-187: Signature update to include gasLimit is appropriate.
This reflects the new requirement to handle gas limits in the checkpoint. Ensure the caller provides a value that aligns with actual chain constraints.


200-200: Correctly forwarding the gasLimit parameter.
Passing gasLimit into the bridgeCallCheckpoint function ensures the encoded call accurately reflects the new feature.

api/fx/gravity/crosschain/v1/types.pulsar.go (13)

6745-6745: New field declarations added for OutgoingBridgeCall message

The code adds new field descriptors for gas_limit and event_nonce fields in the OutgoingBridgeCall message type.

Also applies to: 6761-6761


6884-6889: Gas limit field handling added to Range method

The Range method implementation is updated to handle the new gas_limit field for the OutgoingBridgeCall message type. The implementation correctly checks and returns the field value.


6929-6930: Gas limit field check added to Has method

The Has method is updated to check for the presence of the gas_limit field in the OutgoingBridgeCall message type.


6967-6968: Gas limit field clearing added to Clear method

The Clear method is updated to handle clearing of the gas_limit field in the OutgoingBridgeCall message type.


7017-7019: Gas limit field getter added to Get method

The Get method is updated to handle retrieving the value of the gas_limit field from the OutgoingBridgeCall message type.


7063-7064: Gas limit field setter added to Set method

The Set method is updated to handle setting the value of the gas_limit field in the OutgoingBridgeCall message type.


7109-7110: Gas limit field mutability check added to Mutable method

The Mutable method is updated to handle mutability checks for the gas_limit field in the OutgoingBridgeCall message type.


7145-7146: Gas limit field default value handling added to NewField method

The NewField method is updated to handle providing the default value for the gas_limit field in the OutgoingBridgeCall message type.


7253-7255: Gas limit field size calculation added to Size method

The Size method is updated to include the gas_limit field in the size calculation for the OutgoingBridgeCall message type.


7291-7295: Gas limit field marshaling added to Marshal method

The Marshal method is updated to handle serializing the gas_limit field for the OutgoingBridgeCall message type.


7665-7682: Gas limit field unmarshaling added to Unmarshal method

The Unmarshal method is updated to handle deserializing the gas_limit field for the OutgoingBridgeCall message type.


Line range hint 9548-9570: Updated message definition for OutgoingBridgeCall

The protobuf message definition for OutgoingBridgeCall is updated to include the new gas_limit field. The field is properly defined with the correct type and field number.


9565-9569: Gas limit field encoding added to protobuf definition

The protobuf encoding details for the gas_limit field are properly defined, including the field number and wire format encoding.

docs/swagger-ui/swagger.yaml (1)

5834-5836: LGTM! Consistent implementation of gas_limit field.

The gas_limit field has been consistently added across all relevant sections with appropriate type (string) and format (uint64), matching the pattern used for other numeric fields like block_height and event_nonce.

Also applies to: 6091-6093, 6813-6815, 7149-7151, 8365-8367, 42307-42309, 42527-42529, 42570-42572, 42655-42657, 42724-42726, 42977-42979

proto/fx/gravity/crosschain/v1/types.proto Show resolved Hide resolved
@fx0x55 fx0x55 merged commit 3fb7b35 into main Dec 28, 2024
19 checks passed
@fx0x55 fx0x55 deleted the zakir/gas-limit2 branch December 28, 2024 12:21
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