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(contract): IBridgeCallback to IBridgeCallContext #830

Merged
merged 1 commit into from
Dec 25, 2024

Conversation

zakir-code
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features

    • Introduced a new contract interface IBridgeCallContext with methods for handling bridge calls and revert scenarios.
    • Added functionality for managing bridge call contexts and associated operations.
  • Bug Fixes

    • Improved error handling and control flow in bridge call processing.
  • Documentation

    • Updated test cases to reflect changes in contract naming and functionality.
  • Chores

    • Removed obsolete contracts and bindings related to IBridgeCallback.
    • Streamlined the testing setup by consolidating contract interactions under the new context.

Copy link

coderabbitai bot commented Dec 25, 2024

Walkthrough

This pull request introduces a comprehensive refactoring of bridge-related contracts and interfaces, primarily focusing on renaming and restructuring the bridge callback mechanism. The changes involve updating contract names, modifying interface definitions, and replacing the existing IBridgeCallback with a new IBridgeCallContext interface. The modifications span multiple files across the contract, Solidity, and testing directories, ensuring consistent implementation of the new bridge call context approach.

Changes

File Change Summary
contract/compile.sh Updated contract list, removed FIP20Upgradable, replaced IBridgeCallback with IBridgeCallContext
contract/contract.go Renamed bridgeCallbackABI to bridgeCallContextABI, updated PackBridgeCallback to PackOnBridgeCall
solidity/contracts/bridge/FxBridgeLogic.sol Replaced IBridgeCallback import with IBridgeCallContext
solidity/contracts/bridge/IBridgeCallContext.sol Renamed interface, updated method names, added onRevert method
solidity/test/ Updated test files to use new BridgeCallContextTest contract and related method names

Sequence Diagram

sequenceDiagram
    participant Sender
    participant Bridge
    participant BridgeCallContext
    
    Sender->>Bridge: Initiate Bridge Call
    Bridge->>BridgeCallContext: onBridgeCall(sender, tokens, amounts)
    alt Call Successful
        BridgeCallContext-->>Bridge: Process Tokens
    else Call Failed
        BridgeCallContext->>Bridge: onRevert(error message)
    end
Loading

Possibly related PRs

Poem

🐰 Hop, hop, bridge call's new dance!
Callbacks transformed with a glance
Context replaces the old way
Interfaces shimmer and sway
Bridge logic leaps with rabbit's grace! 🌉

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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: 0

🧹 Nitpick comments (3)
solidity/contracts/bridge/FxBridgeLogic.sol (1)

597-597: Calling onBridgeCall
Implementation matches the new interface. Consider returning a status or data to confirm the call outcome if needed.

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

4-14: Renamed interface and new onRevert method
The interface rename from IBridgeCallback to IBridgeCallContext is clear. The addition of onRevert(bytes memory _msg) is a straightforward approach for revert handling. As a minor nitpick, consider renaming _msg to _reason for clarity.

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

Line range hint 627-639: LGTM! Bridge callback implementation with suggested improvements.

The implementation correctly handles both the new onRevert and onBridgeCall methods from the IBridgeCallContext interface. The control flow is logical, first checking eventNonce to determine which callback to execute.

Consider these improvements:

  1. Validate and handle the return values from callback methods
  2. Add specific events for callback results
  3. Use more specific error messages
 if (_input.to.isContract()) {
     if (_input.eventNonce > 0) {
-        IBridgeCallContext(_input.to).onRevert(_input.data);
+        bool success = IBridgeCallContext(_input.to).onRevert(_input.data);
+        require(success, "Bridge callback onRevert failed");
         return;
     }

-    IBridgeCallContext(_input.to).onBridgeCall(
+    bool success = IBridgeCallContext(_input.to).onBridgeCall(
         _input.sender,
         _input.refund,
         _input.tokens,
         _input.amounts,
         _input.data,
         _input.memo
     );
+    require(success, "Bridge callback onBridgeCall failed");
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 03dc380 and 448727c.

📒 Files selected for processing (13)
  • contract/compile.sh (1 hunks)
  • contract/contract.go (2 hunks)
  • contract/contract_test.go (1 hunks)
  • contract/ibridge_call_context.sol.go (1 hunks)
  • contract/ibridge_callback.sol.go (0 hunks)
  • solidity/contracts/bridge/BridgeCallFee.sol (0 hunks)
  • solidity/contracts/bridge/FxBridgeLogic.sol (2 hunks)
  • solidity/contracts/bridge/FxBridgeLogicETH.sol (2 hunks)
  • solidity/contracts/bridge/IBridgeCallContext.sol (1 hunks)
  • solidity/contracts/test/BridgeCallContextTest.sol (2 hunks)
  • solidity/test/bridge_fee.ts (6 hunks)
  • solidity/test/submit_bridge_call.ts (5 hunks)
  • x/crosschain/keeper/bridge_call_in.go (1 hunks)
💤 Files with no reviewable changes (2)
  • solidity/contracts/bridge/BridgeCallFee.sol
  • contract/ibridge_callback.sol.go
✅ Files skipped from review due to trivial changes (1)
  • contract/ibridge_call_context.sol.go
🔇 Additional comments (34)
solidity/contracts/bridge/FxBridgeLogic.sol (4)

15-15: Renamed import aligns with new interface scheme
This import reflects the updated IBridgeCallContext interface, replacing IBridgeCallback. The naming looks consistent and clear.


589-589: Irrelevant closing brace
No functional or logical changes are introduced here.


591-591: Conditional check for contract
Checking _input.to.isContract() before the callback is a good safeguard against unintended calls to EOA addresses.


593-593: New onRevert callback
Ensure the data being passed here is the intended payload to handle revert logic. Consider clarifying if _input.data includes or excludes revert reason information.

x/crosschain/keeper/bridge_call_in.go (1)

111-111: Refactor to PackOnBridgeCall
The rename from PackBridgeCallback to PackOnBridgeCall aligns with the new interface and naming convention. Verify that any tests have been updated accordingly.

solidity/test/bridge_fee.ts (9)

7-7: Importing BridgeCallContextTest
Import is consistent with the newly introduced contract.


18-18: Declare bridgeCallContextTest
Naming follows the new interface.


94-97: Contract deployment
Deploying BridgeCallContextTest and passing in fxBridge for context is aligned with the updated architecture.


134-134: Fetching contract address
Retrieving the address for subsequent checks is correct.


145-145: Memo references
Embedding bridgeCallContextTest address into memo looks intentional for bridging logic.


148-149: Balance and flag checks
Good approach verifying the token balance and the contract’s internal state (callFlag).


153-153: Final flag verification
Ensuring the callback logic toggles the flag as expected is a solid test.


167-167: Additional balance check
Again verifying the token movement for bridging.


169-169: Repeated call flag verification
Ensuring consistency of the bridging.

solidity/test/submit_bridge_call.ts (8)

7-7: Importing BridgeCallContextTest
The import is aligned with overall refactor to IBridgeCallContext.


18-18: Declare bridgeCallContextTest
References the new test contract that implements the updated interface.


91-94: Instantiating factory for BridgeCallContextTest
Deployment references the correct contract name.


122-122: Updated test description
Renaming suits the updated approach for bridging calls.


126-126: bridgeCallContextAddress
Gathering the deployed address for next steps.


134-138: Calling submitBridgeCall with new references
Ensures bridging logic is tested against bridgeCallContextTest.


150-154: Post-call checks
Validating callFlag and revertFlag to ensure the correct callback workflow.


156-187: Revert testing
These lines confirm that tokens are refunded and onRevert is triggered when the specified condition is met (eventNonce > 0). Good coverage of the new logic branch.

contract/contract.go (2)

73-75: Use consistent naming for ABIs with the new interface.
Renaming bridgeCallbackABI to bridgeCallContextABI aligns with the newly introduced IBridgeCallContext. Ensure references in other files are updated accordingly to avoid confusion or misuse.


139-140: Validate usage of the renamed PackOnBridgeCall.
Renaming from PackBridgeCallback to PackOnBridgeCall is a clear improvement for clarity. Confirm that all callers to this function across the codebase have been updated to the new signature.

contract/contract_test.go (2)

51-51: Confirm that the new expected data matches the updated function signature.
Renaming the function to PackOnBridgeCall may influence the encoded data. Validate that the “expected” string aligns with the new ABI.


57-57: Good consistency with the refactored function name.
Replacing PackBridgeCallback with PackOnBridgeCall ensures the test remains consistent with the updated contract logic.

solidity/contracts/test/BridgeCallContextTest.sol (6)

4-4: Import aligns with the refactored interface name.
Renaming to IBridgeCallContext.sol reflects the updated contract logic.


8-8: Renamed contract inheriting the correct interface.
Switching from BridgeCallbackTest implementing IBridgeCallback to BridgeCallContextTest implementing IBridgeCallContext matches the new nomenclature.


11-11: New revert flag for extended state tracking.
The introduction of revertFlag broadens the contract’s functionality, providing an additional state check for revert callbacks.


16-16: Initialize revertFlag safely.
Default setting to false is clear and supports reliable toggling in the new onRevert method.


19-19: Renaming bridgeCallback to onBridgeCall clarifies semantics.
The method name now better describes the action taken when a bridge call occurs.


30-32: New onRevert method toggles revertFlag.
This addition provides a structured mechanism for handling revert scenarios, enhancing the contract’s extensibility.

contract/compile.sh (1)

34-34: Reflect updated contract list in the compilation process.
Adding IBridgeCallContext ensures the correct ABI and bytecode are generated for the renamed interface, consistent with the refactoring across the codebase.

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

15-15: LGTM! Import statement updated correctly.

The import statement has been updated to use the new IBridgeCallContext interface, which is consistent with the PR's refactoring objectives.

@zakir-code zakir-code merged commit 21eb67f into main Dec 25, 2024
18 checks passed
@zakir-code zakir-code deleted the todd/bridge-call branch December 25, 2024 09:22
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