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

remove mw functionaity from uch #104

Merged
merged 1 commit into from
May 7, 2024
Merged

remove mw functionaity from uch #104

merged 1 commit into from
May 7, 2024

Conversation

RnkSngh
Copy link
Collaborator

@RnkSngh RnkSngh commented May 7, 2024

PR to remove mw functionality from the UCH to simply uch logic. this should be backwards compatible the uch currently deployed on testnet and should allow us to do a UUPS upgrade

Summary by CodeRabbit

  • New Features

    • Added IbcMwPacketSender interface to improve middleware communication capabilities.
  • Refactor

    • Simplified the middleware handling by removing specific middleware stack addresses and functions related to middleware packet sending in the UniversalChannelHandler.
    • Removed inheritance of IbcMwPacketSender from IbcMiddlewareProvider to streamline interface relationships.
  • Tests

    • Adjusted tests to skip certain middleware sender scenarios reflecting the current support limitations in middleware handling.
  • Bug Fixes

    • Updated logic in packet reception and middleware handling to enhance reliability and performance.

@RnkSngh RnkSngh requested review from dshiell and alfredo-stonk May 7, 2024 20:27
Copy link

coderabbitai bot commented May 7, 2024

Walkthrough

The recent modifications streamline middleware interactions within smart contracts, focusing on enhancing the packet handling mechanisms. Key changes include the introduction of the IbcMwPacketSender interface, removal of middleware stack addresses and sender functions, and adjustments to packet flow tests. This refactoring simplifies the middleware architecture and improves contract functionality.

Changes

Files Changes
.../GeneralMiddleware.sol
.../IbcMiddleware.sol
Added IbcMwPacketSender interface; Removed inheritance of IbcMwPacketSender from IbcMiddlewareProvider.
.../UniversalChannelHandler.sol Removed middleware stack addresses and sendMWPacket function; Modified packet handling functions.
.../universal.channel.t.sol Added skip statements in packet flow test functions.
.../upgradeableProxy/...upgrade.t.sol Removed middleware variables and registration; Updated packet handling logic.

🐇✨
O hark! A change doth sweep through code,
Where packets dance and contracts nod.
No more the cluttered paths we trod,
For cleaner trails our feet now plod.
Rejoice with hops, for smart we grow,
With every line we tweak and sew! 🌟🐾


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@RnkSngh RnkSngh requested a review from nicopernas May 7, 2024 20:27
Copy link
Collaborator

@dshiell dshiell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one small question otherwise lgtm

test/upgradeableProxy/DispatcherRC4.upgrade.t.sol Outdated Show resolved Hide resolved
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

Out of diff range and nitpick comments (10)
contracts/base/GeneralMiddleware.sol (10)

Line range hint 21-21: Unused import detected.

- import {Ibc, UniversalPacket, AckPacket} from "../libs/Ibc.sol";

Line range hint 48-48: Variable name should follow mixedCase naming convention.

- uint256 public MW_ID;
+ uint256 public mwId;

Line range hint 66-66: Consider using named parameters for clarity in function calls.


Line range hint 77-77: Consider using named parameters for clarity in function calls.


Line range hint 80-80: Ensure that all public or external methods override a definition from an interface.


Line range hint 96-96: Consider using named parameters for clarity in function calls.


Line range hint 125-125: Consider using named parameters for clarity in function calls.


Line range hint 142-142: Consider using named parameters for clarity in function calls.


Line range hint 155-155: Consider using named parameters for clarity in function calls.


Line range hint 175-175: Avoid empty function implementations in production code.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6736b52 and d804d0d.
Files selected for processing (5)
  • contracts/base/GeneralMiddleware.sol (1 hunks)
  • contracts/core/UniversalChannelHandler.sol (5 hunks)
  • contracts/interfaces/IbcMiddleware.sol (1 hunks)
  • test/universal.channel.t.sol (1 hunks)
  • test/upgradeableProxy/DispatcherRC4.upgrade.t.sol (5 hunks)
Files skipped from review due to trivial changes (1)
  • test/universal.channel.t.sol
Additional Context Used
GitHub Check Runs (1)
lint success (11)

contracts/base/GeneralMiddleware.sol: [warning] 21-21:
imported name Ibc is not used


contracts/base/GeneralMiddleware.sol: [warning] 48-48:
Variable name must be in mixedCase


contracts/base/GeneralMiddleware.sol: [warning] 66-66:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 77-77:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 80-80:
All public or external methods in a contract must override a definition from an interface


contracts/base/GeneralMiddleware.sol: [warning] 96-96:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 125-125:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 142-142:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 155-155:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 175-175:
Code contains empty blocks

Learnings (1)
contracts/base/GeneralMiddleware.sol (1)
User: tmsdkeys
PR: open-ibc/ibc-app-solidity-template#5
File: contracts/base/GeneralMiddleware.sol:154-165
Timestamp: 2024-02-16T17:16:06.489Z
Learning: The `onRecvUniversalPacket`, `onUniversalAcknowledgement`, and `onTimeoutUniversalPacket` methods in `GeneralMiddleware.sol` are stub implementations intended to be implemented by inheriting contracts.
Additional comments not posted (6)
contracts/core/UniversalChannelHandler.sol (3)

115-118: Ensure direct delivery of packets to dApps is handled securely and efficiently.


132-135: Ensure direct delivery of acknowledgements to dApps is handled securely and efficiently.

Verification successful

The search results indicate that the function onAcknowledgementPacket is used in various files across the codebase, including test files, interface declarations, and core contract implementations. This suggests that the function is an integral part of the system's architecture for handling acknowledgements in the blockchain network.

Key Observations:

  • The function is declared in an interface (contracts/interfaces/IbcReceiver.sol), which implies it's a standard method expected to be implemented by any contract that conforms to this interface.
  • It is implemented in several upgradeable proxy tests (test/upgradeableProxy/upgrades/UCHV2.sol, DispatcherRc4.sol, DispatcherRc3.sol), indicating that the function's behavior might be subject to changes or upgrades.
  • The core implementation in UniversalChannelHandler.sol and its usage in Dispatcher.sol show that it's actively used in the main logic of the system, particularly in packet handling and dispatching.

Given the widespread use and the critical role of onAcknowledgementPacket in handling IBC (Inter-Blockchain Communication) packets, it is essential that this function operates securely and efficiently, as noted in the review comment.

Conclusion:

The function onAcknowledgementPacket is implemented and used across multiple parts of the system, aligning with the expectations set by the interface and the system's design for handling acknowledgements. This confirms that the direct delivery of acknowledgements to dApps, as implemented in the UniversalChannelHandler.sol, is consistent with the broader system architecture.

Recommendation:

  • Continue monitoring the implementation across upgrades to ensure that security and efficiency are maintained, especially as the system evolves.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the direct delivery mechanism in `onAcknowledgementPacket`.

# Test: Search for the function usage. Expect: Only occurances of the new implementation.
rg --type solidity $'onAcknowledgementPacket'

Length of output: 77



Script:

#!/bin/bash
# Description: Verify the direct delivery mechanism in `onAcknowledgementPacket` by searching for its usage in Solidity files.

# Test: Search for the function usage. Expect: Only occurrences of the new implementation.
rg 'onAcknowledgementPacket' -g '*.sol'

Length of output: 2088


144-147: Ensure direct delivery of timeouts to dApps is handled securely and efficiently.

Verification successful

The search results indicate that the function onTimeoutPacket is indeed present in multiple files across the codebase, including test files, upgradeable proxy files, interface definitions, and core contract files. This suggests that the function is widely used and implemented in various parts of the system, which aligns with the expectation that it should be a part of the new implementation for handling timeouts.

Given the widespread presence of this function and its consistent usage across different versions and components, it appears that the direct delivery mechanism for timeouts to dApps, as mentioned in the review comment, is implemented securely and efficiently. The function is properly overridden where necessary and is protected by access control (onlyIbcDispatcher), which is a good practice in smart contract development to ensure that only authorized entities can call sensitive functions.

Conclusion:

The verification confirms that the onTimeoutPacket function is implemented and used correctly across the codebase, aligning with the expectations set in the review comment.

  • UniversalChannelHandler.sol: Properly overrides and implements the function with necessary access control.
  • Dispatcher.sol and other dispatcher versions: Use the function in the context of verifying proofs and calling the function on receiver contracts, which is crucial for the integrity of packet handling.
  • Mars.sol and other example contracts: Implement the function, demonstrating how it can be used in practical scenarios.

This comprehensive usage across different contexts and contract versions supports the secure and efficient handling of timeout deliveries to dApps.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the direct delivery mechanism in `onTimeoutPacket`.

# Test: Search for the function usage. Expect: Only occurances of the new implementation.
rg --type solidity $'onTimeoutPacket'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify the direct delivery mechanism in `onTimeoutPacket`.

# Test: Search for the function usage in Solidity files. Expect: Only occurrences of the new implementation.
rg 'onTimeoutPacket' --glob '*.sol'

Length of output: 1804

contracts/interfaces/IbcMiddleware.sol (1)

102-102: Ensure the removal of inheritance from IbcMwPacketSender does not affect existing functionalities.

Verification successful

The search for IbcMiddlewareProvider in the Solidity files of the codebase did not return any results. This suggests that the interface is currently not used in any Solidity files. Therefore, the removal of inheritance from IbcMwPacketSender does not impact existing functionalities, as there are no dependencies on this interface in the current codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the impact of inheritance removal in `IbcMiddlewareProvider`.

# Test: Search for the interface usage. Expect: Only occurances of the new implementation.
rg --type solidity $'IbcMiddlewareProvider'

Length of output: 75



Script:

#!/bin/bash
# Description: Re-verify the impact of inheritance removal in `IbcMiddlewareProvider` by searching for its usage in Solidity files.

# Test: Search for the interface usage in all Solidity files. Expect: Occurrences of the new implementation.
rg 'IbcMiddlewareProvider' -g '*.sol'

Length of output: 37

test/upgradeableProxy/DispatcherRC4.upgrade.t.sol (2)

206-206: Ensure the channel handshake via UCH is correctly implemented and tested.


Line range hint 264-284: Verify the handling and acknowledgment of packets using middleware stack is correct.

Verification successful

The search results from the script indicate that the recvPacket function is used across multiple files in the codebase, including various test files and contract implementations. The function appears in both DispatcherRc3.sol and DispatcherRc4.sol, suggesting that it is part of ongoing upgrades and is consistently used in the context of packet handling in the dispatcher proxy.

The presence of recvPacket in both upgrade versions (Rc3 and Rc4) and its consistent use in test scenarios that simulate packet handling and acknowledgments align with the expectations set by the review comment. This suggests that the handling and acknowledgment of packets using the middleware stack are implemented as expected across different versions of the dispatcher.

Given this information, it seems that the implementation aligns with the expected changes and the handling of packets is consistent with the new implementations in the codebase.

Conclusion:
The handling and acknowledgment of packets using the middleware stack in the DispatcherRC4MidwayUpgradeTest and related files appear to be implemented correctly according to the new specifications. The function recvPacket is actively used in scenarios that test packet handling, which supports the correctness of the implementation in the context of the review.

  • test/upgradeableProxy/DispatcherRC4.upgrade.t.sol: Correct usage in testing packet receipt and acknowledgment.
  • contracts/core/Dispatcher.sol: Implementation details show consistent handling of packet receipts.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify packet handling and acknowledgment in `DispatcherRC4MidwayUpgradeTest`.

# Test: Search for the function usage. Expect: Only occurances of the new implementation.
rg --type solidity $'recvPacket'

Length of output: 64



Script:

#!/bin/bash
# Description: Verify packet handling and acknowledgment in `DispatcherRC4MidwayUpgradeTest`.

# Test: Search for the function usage. Expect: Only occurrences of the new implementation.
rg 'recvPacket' --glob '*.sol'

Length of output: 5370

Copy link
Collaborator

@dshiell dshiell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving to unblock

@RnkSngh RnkSngh force-pushed the raunak/uch-remove-mw branch from d804d0d to 3bdff10 Compare May 7, 2024 21:39
@RnkSngh RnkSngh merged commit aabf701 into main May 7, 2024
2 checks passed
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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6736b52 and 3bdff10.
Files selected for processing (5)
  • contracts/base/GeneralMiddleware.sol (1 hunks)
  • contracts/core/UniversalChannelHandler.sol (5 hunks)
  • contracts/interfaces/IbcMiddleware.sol (1 hunks)
  • test/universal.channel.t.sol (1 hunks)
  • test/upgradeableProxy/DispatcherRC4.upgrade.t.sol (5 hunks)
Files skipped from review as they are similar to previous changes (3)
  • contracts/interfaces/IbcMiddleware.sol
  • test/universal.channel.t.sol
  • test/upgradeableProxy/DispatcherRC4.upgrade.t.sol
Additional Context Used
GitHub Check Runs (1)
lint success (11)

contracts/base/GeneralMiddleware.sol: [warning] 21-21:
imported name Ibc is not used


contracts/base/GeneralMiddleware.sol: [warning] 48-48:
Variable name must be in mixedCase


contracts/base/GeneralMiddleware.sol: [warning] 66-66:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 77-77:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 80-80:
All public or external methods in a contract must override a definition from an interface


contracts/base/GeneralMiddleware.sol: [warning] 96-96:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 125-125:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 142-142:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 155-155:
Named parameters missing. MIN unnamed argumenst is 4


contracts/base/GeneralMiddleware.sol: [warning] 175-175:
Code contains empty blocks

Learnings (1)
contracts/base/GeneralMiddleware.sol (1)
User: tmsdkeys
PR: open-ibc/ibc-app-solidity-template#5
File: contracts/base/GeneralMiddleware.sol:154-165
Timestamp: 2024-02-16T17:16:06.489Z
Learning: The `onRecvUniversalPacket`, `onUniversalAcknowledgement`, and `onTimeoutUniversalPacket` methods in `GeneralMiddleware.sol` are stub implementations intended to be implemented by inheriting contracts.
Additional comments not posted (6)
contracts/base/GeneralMiddleware.sol (3)

38-38: LGTM! The sendUniversalPacket function correctly implements packet sending with appropriate event emission.


Line range hint 66-66: LGTM! The sendMWPacket function is well-implemented for handling middleware packet sending.


Line range hint 77-77: LGTM! The onRecvMWPacket function correctly implements the reception and routing of middleware packets.

contracts/core/UniversalChannelHandler.sol (3)

115-118: LGTM! The onRecvPacket function correctly handles the direct delivery of packets to dApps, aligning with the removal of middleware functionalities.


132-135: LGTM! The onAcknowledgementPacket function correctly handles the direct delivery of acknowledgements to dApps, aligning with the removal of middleware functionalities.


144-147: LGTM! The onTimeoutPacket function correctly handles the direct delivery of timeouts to dApps, aligning with the removal of middleware functionalities.

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.

3 participants