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

revert api split changes #62

Merged
merged 1 commit into from
Mar 12, 2024
Merged

revert api split changes #62

merged 1 commit into from
Mar 12, 2024

Conversation

nicopernas
Copy link
Contributor

@nicopernas nicopernas commented Mar 12, 2024

Revert channel handshake "split api" changes since those break the api and will make contract
deployment hard

Summary by CodeRabbit

  • New Features
    • Introduced a streamlined process for opening and connecting IBC channels with enhanced version compatibility checks.
    • Added new events OpenIbcChannel and ConnectIbcChannel for better visibility into channel operations.
  • Refactor
    • Consolidated channel opening functions into openIbcChannel and connectIbcChannel across multiple contracts for clarity and efficiency.
    • Updated IBC callback functions in the UniversalChannelHandler to handle channel openings more effectively.
  • Bug Fixes
    • Added a new error VersionMismatch to handle version incompatibilities during channel connections.
  • Tests
    • Updated and restructured tests to align with the new channel opening and connection handling logic.

This reverts commit 7777f17.
Copy link

coderabbitai bot commented Mar 12, 2024

Walkthrough

The updates focus on refining the IBC (Inter-Blockchain Communication) channel handling in smart contracts, particularly around opening and connecting channels. This includes the consolidation of channel opening functions into more streamlined versions, enhanced version compatibility checks, and the introduction of new events and errors to better reflect the process. The changes aim to simplify the interaction model and improve the reliability of cross-chain communication.

Changes

Files Summary
contracts/core/Dispatcher.sol, contracts/interfaces/IbcDispatcher.sol Refactored channelOpenInit and channelOpenTry into openIbcChannel, connectIbcChannel, and related functions. Introduced new events and a Ics23Proof parameter.
contracts/core/UniversalChannelHandler.sol Updated IBC callback functions to handle ChanOpenInit and ChanOpenTry more efficiently, with improved version checks.
contracts/examples/Mars.sol Refactored IBC channel handling functions for better version compatibility and streamlined channel opening.
contracts/interfaces/IbcReceiver.sol Replaced various channel opening functions with onOpenIbcChannel and onConnectIbcChannel, adding a VersionMismatch error.
test/.../Dispatcher.*.t.sol, test/VirtualChain.sol Renamed and restructured IBC channel opening steps, adjusted parameter names, and aligned event emissions.
test/universal.channel.t.sol Modified channelOpenAck and channelOpenConfirm functions to channelOpenAckOrConfirm with an added boolean parameter.

🐰✨
In the realm of chains that span,
A rabbit hopped, a clever plan.
"Let's weave the links," it said with glee,
"Connect them all, from sea to shining sea."
With code refined, the channels open wide,
Across the blockchain, side by side.
🚀🌌

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@nicopernas nicopernas requested review from RnkSngh and alfredo-stonk and removed request for RnkSngh March 12, 2024 18:24
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7777f17 and d8f844e.
Files selected for processing (10)
  • contracts/core/Dispatcher.sol (5 hunks)
  • contracts/core/UniversalChannelHandler.sol (2 hunks)
  • contracts/examples/Mars.sol (2 hunks)
  • contracts/interfaces/IbcDispatcher.sol (3 hunks)
  • contracts/interfaces/IbcReceiver.sol (2 hunks)
  • test/Dispatcher.base.t.sol (2 hunks)
  • test/Dispatcher.proof.t.sol (1 hunks)
  • test/Dispatcher.t.sol (6 hunks)
  • test/VirtualChain.sol (5 hunks)
  • test/universal.channel.t.sol (1 hunks)
Additional comments: 29
contracts/interfaces/IbcReceiver.sol (3)
  • 15-21: The consolidation of channel opening functions into onOpenIbcChannel simplifies the interface and potentially reduces the complexity of implementing the IBC protocol. However, ensure that all implementing contracts are updated to reflect these changes, as this could break existing implementations that rely on the previous function signatures.
  • 23-24: The addition of onConnectIbcChannel is a logical extension of the interface to handle the connection phase of the IBC channel lifecycle. This change aligns with the PR's objective to simplify the channel handshake process. Ensure that the documentation is updated to clearly explain the expected behavior and use cases of this function.
  • 56-56: The introduction of the VersionMismatch error is a good practice for handling version incompatibilities more explicitly. This can improve error handling and debugging experiences for developers. Ensure that all functions that could potentially throw this error are documented accordingly.
contracts/interfaces/IbcDispatcher.sol (2)
  • 26-33: Renaming channelOpenInit to openIbcChannel and the addition of the Ics23Proof parameter align with the PR's objective to simplify and enhance the channel opening process. Ensure that all dependent contracts and tests are updated to reflect this change. Additionally, consider updating the documentation to explain the role of the Ics23Proof parameter in the channel opening process.
  • 46-52: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [49-59]

The replacement of ChannelOpenInit and ChannelOpenTry events with OpenIbcChannel and ConnectIbcChannel is consistent with the interface function changes. This should simplify event handling and improve clarity. Ensure that all event listeners and handlers are updated accordingly to prevent any potential issues with event processing.

contracts/examples/Mars.sol (2)
  • 37-51: The implementation of onConnectIbcChannel to verify supported versions before connecting channels is a good practice. It ensures that only compatible channel versions are connected, which can prevent potential issues down the line. Ensure that the list of supportedVersions is maintained and updated as necessary to reflect the versions supported by the contract.
  • 84-117: Modifying onOpenIbcChannel to handle version selection based on the channel initiation type (ChanOpenInit or ChanOpenTry) is a smart approach to streamline the channel opening process. This change makes the version negotiation more explicit and manageable. Ensure that the logic correctly handles all possible scenarios and that comprehensive tests are in place to verify its behavior.
test/Dispatcher.base.t.sol (2)
  • 75-96: The refactoring of the IBC channel opening steps to use the new openChannel function is a positive change that aligns with the interface updates. Ensure that the tests cover all possible scenarios and edge cases to verify the correct behavior of the channel opening process. Additionally, verify that the event emissions are correctly captured and asserted in the tests.
  • 115-126: The implementation of connectChannel to handle the connection phase of the IBC channel lifecycle in tests is consistent with the changes in the main contracts. Ensure that the tests adequately cover the new logic and that the expected behavior is clearly documented in the test cases.
test/Dispatcher.proof.t.sol (2)
  • 34-39: Updating the test to use the openIbcChannel method with the new parameter structure is a necessary change following the interface updates. Ensure that the tests are comprehensive and cover various scenarios to validate the correct behavior of the openIbcChannel method, especially with the inclusion of proofs.
  • 55-57: The adjustment to use connectIbcChannel for acknowledging channel connections in tests is in line with the main contract changes. Ensure that the tests validate the correct handling of proofs and the expected event emissions during the channel acknowledgment process.
contracts/core/UniversalChannelHandler.sol (2)
  • 36-45: The implementation of onConnectIbcChannel in the UniversalChannelHandler contract to enforce version compatibility is a good practice. It ensures that channels can only be connected if they are compatible, which is crucial for maintaining the integrity of the IBC protocol. Ensure that the list of supported versions (VERSION) is correctly managed and that this function is thoroughly tested.
  • 152-168: The modifications to onOpenIbcChannel to handle both ChanOpenInit and ChanOpenTry scenarios with version checks are well thought out. This approach simplifies the channel opening process by consolidating the logic into a single function. Ensure that the function correctly handles all scenarios and that comprehensive tests are in place to verify its behavior.
test/VirtualChain.sol (2)
  • 135-138: Renaming channelOpenConfirm to channelOpenAckOrConfirm and adding the isChanConfirm parameter to differentiate between channel acknowledgment and confirmation is a logical change that aligns with the PR's objectives. Ensure that the tests cover both scenarios (acknowledgment and confirmation) and that the behavior is consistent with the updated interface.
  • 217-248: The adjustments made to the channelOpenAckOrConfirm function to handle the acknowledgment or confirmation of channel connections in tests are consistent with the changes in the main contracts. Ensure that the tests are comprehensive and validate the correct behavior of the channel connection process, including the handling of the new isChanConfirm parameter.
test/universal.channel.t.sol (2)
  • 80-80: The addition of a boolean parameter in channelOpenAckOrConfirm calls is noted. This change aligns with the PR's objective to simplify the channel handshake process by merging channelOpenAck and channelOpenConfirm into a single function. However, it's crucial to ensure that the boolean parameter's purpose (likely indicating whether it's an ack or confirm operation) is clearly documented to avoid confusion.
  • 83-83: Similar to the previous comment, the addition of a boolean parameter in channelOpenAckOrConfirm is observed here as well. It's essential to maintain consistency in how this parameter is used across different calls to this function to ensure the logic remains clear and understandable.
test/Dispatcher.t.sol (9)
  • 35-35: Renaming functions to openChannel and connectChannel simplifies the channel handshake process, making it more intuitive. This change is consistent with the PR's objective to revert problematic modifications and improve the API's stability. Ensure that all references to the old function names are updated across the codebase to avoid any broken functionality.
  • 52-52: The consolidation of channel opening functions into openChannel is noted here as well. It's important to verify that the new function adequately handles all scenarios previously covered by separate functions, ensuring no loss of functionality or error handling capabilities.
  • 56-56: The use of an empty string for version selection in openChannel suggests an auto-selection mechanism. This approach can be beneficial for flexibility but requires clear documentation and robust error handling to manage potential version mismatches effectively.
  • 72-73: The introduction of connectChannel as part of the channel handshake process is a significant change. It's crucial to ensure that this function integrates seamlessly with the rest of the handshake process, particularly in terms of version compatibility checks and error handling.
  • 78-93: Adding tests for version mismatches (test_openChannel_receiver_fail_versionMismatch) is a positive step towards ensuring robustness in the channel handshake process. It's important to cover various scenarios where version mismatches can occur to ensure comprehensive testing.
  • 69-98: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [95-105]

The addition of tests for unsupported versions (test_openChannel_initiator_fail_unsupportedVersion) is crucial for validating the channel handshake process's resilience. Ensure that these tests adequately cover different scenarios where unsupported versions might be encountered.

  • 117-159: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [111-121]

Testing for invalid proof in test_openChannel_receiver_fail_invalidProof is essential for security. It's important to ensure that the contract correctly rejects invalid proofs to prevent unauthorized channel openings.

  • 127-138: The tests for unsupported versions in test_connectChannel_fail_unsupportedVersion are important for ensuring compatibility and error handling in the channel connection process. Ensure comprehensive coverage of scenarios where unsupported versions might be encountered.
  • 144-156: Testing for invalid proof in test_connectChannel_fail_invalidProof is crucial for maintaining the integrity of the channel connection process. It's important to verify that the contract correctly identifies and rejects invalid proofs to prevent unauthorized actions.
contracts/core/Dispatcher.sol (3)
  • 87-104: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [77-101]

The openIbcChannel function introduces a consolidated approach to initiating or trying to open an IBC channel. A few observations and suggestions:

  1. Parameter Validation (Lines 77-96): The validation of counterparty.portId is crucial to ensure that the channel opening process is initiated with a valid counterparty. However, consider adding more detailed comments explaining the significance of each validation step for future maintainability.

  2. Proof Verification (Lines 90-96): The use of consensusStateManager.verifyMembership for proof verification is appropriate. Ensure that the proof, channelProofKey, and channelProofValue are correctly formed and that their integrity is maintained across updates to related components.

  3. Callback Invocation (Lines 98-99): The callback to portAddress.onOpenIbcChannel is a critical step in the channel opening process. It's important to ensure that the IbcChannelReceiver interface and its implementations are robust and handle all possible outcomes of this callback.

  4. Event Emission (Lines 101): The OpenIbcChannel event provides transparency and traceability for channel opening actions. Ensure that all parameters of the event are accurately populated and that the event is documented for consumers.

Overall, the changes align with the PR's objectives to simplify the channel opening process. However, thorough testing and validation are recommended to ensure that these changes do not introduce regressions or new issues.

Ensure comprehensive testing, especially for the proof verification logic and callback invocation, to validate the correctness and robustness of the channel opening process.

  • 456-473: The _verifyConnectIbcChannelProof internal function plays a key role in verifying the connection proof during the channel connection process. A few observations:
  1. Proof Verification (Lines 464-473): The use of consensusStateManager.verifyMembership for proof verification is appropriate. Ensure that the proof, keys, and values are correctly formed and that their integrity is maintained across updates to related components.

  2. Channel State Handling (Lines 468-469): The conditional logic to determine the channel state (CONFIRM_PENDING or ACK_PENDING) based on isChanConfirm is clear and logical. Ensure that all possible states are correctly handled and that the state transitions are well-documented.

This function is critical for the security and integrity of the channel connection process. Thorough testing and validation are recommended to ensure its correctness.

Consider adding more detailed comments explaining the significance of each step in the proof verification process for future maintainability and clarity.

  • 521-530: The _isChannelOpenTry internal function effectively determines if the channel open attempt is a ChanOpenTry. Key observations:
  1. Logic Clarity (Lines 521-530): The function's logic is clear and effectively uses the counterparty information to determine the channel open attempt type. The use of counterparty.channelId and counterparty.version to differentiate between ChanOpenInit and ChanOpenTry is logical.

  2. Error Handling (Line 529): The use of revert IBCErrors.invalidCounterParty(); for invalid counterparty scenarios is appropriate. Ensure that all possible invalid scenarios are correctly identified and handled.

This function is crucial for correctly handling different channel open attempts. Ensure that it is thoroughly tested, especially with edge cases and invalid counterparty scenarios.

The implementation and logic of _isChannelOpenTry are sound and align with the contract's requirements for handling different channel open attempts.

Comment on lines +117 to +149
function connectIbcChannel(
IbcChannelReceiver portAddress,
CounterParty calldata local,
string[] calldata connectionHops,
ChannelOrder ordering,
bool feeEnabled,
bool isChanConfirm,
CounterParty calldata counterparty,
Ics23Proof calldata proof
) external {
consensusStateManager.verifyMembership(
proof,
channelProofKey(local.portId, local.channelId),
channelProofValue(ChannelState.ACK_PENDING, ordering, local.version, connectionHops, counterparty)
);

_connectChannel(portAddress, local, connectionHops, ordering, feeEnabled, counterparty);

portAddress.onChanOpenAck(local.channelId, counterparty.version);
_verifyConnectIbcChannelProof(local, connectionHops, ordering, isChanConfirm, counterparty, proof);

emit ChannelOpenAck(address(portAddress), local.channelId);
}
portAddress.onConnectIbcChannel(local.channelId, counterparty.channelId, counterparty.version);

/**
* This func is called by a 'relayer' after the IBC/VIBC hub chain has processed the ChannelOpenTry event.
* The dApp should implement the onChannelConnect method to handle the last channel handshake method:
* ChannelOpenConfirm
*/
function channelOpenConfirm(
IbcChannelReceiver portAddress,
CounterParty calldata local,
string[] calldata connectionHops,
ChannelOrder ordering,
bool feeEnabled,
CounterParty calldata counterparty,
Ics23Proof calldata proof
) external {
consensusStateManager.verifyMembership(
proof,
channelProofKey(local.portId, local.channelId),
channelProofValue(ChannelState.CONFIRM_PENDING, ordering, local.version, connectionHops, counterparty)
// Register port and channel mapping
// TODO: check duplicated channel registration?
// TODO: The call to `Channel` constructor MUST be move to `openIbcChannel` phase
// Then `connectIbcChannel` phase can use the `version` as part of `require` condition.
portChannelMap[address(portAddress)][local.channelId] = Channel(
counterparty.version, // TODO: this should be self version instead of counterparty version
ordering,
feeEnabled,
connectionHops,
counterparty.portId,
counterparty.channelId
);

_connectChannel(portAddress, local, connectionHops, ordering, feeEnabled, counterparty);

portAddress.onChanOpenConfirm(local.channelId, counterparty.version);
// initialize channel sequences
nextSequenceSend[address(portAddress)][local.channelId] = 1;
nextSequenceRecv[address(portAddress)][local.channelId] = 1;
nextSequenceAck[address(portAddress)][local.channelId] = 1;

emit ChannelOpenConfirm(address(portAddress), local.channelId);
emit ConnectIbcChannel(address(portAddress), local.channelId);
Copy link

Choose a reason for hiding this comment

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

The connectIbcChannel function manages the connection phase of the IBC channel handshake. Key points include:

  1. Proof Verification and Callback Invocation (Lines 127-129): The _verifyConnectIbcChannelProof internal function is used for proof verification, which is a good practice. The callback to portAddress.onConnectIbcChannel is crucial for the dApp to handle the connection phase. Ensure that the callback's implementation in dApps is robust and handles all edge cases.

  2. Channel Registration (Lines 131-141): The registration of the channel in the portChannelMap is a critical step. The comment on line 136 indicates a potential issue with using the counterparty version instead of the self version. This needs to be addressed to ensure that the channel information is correctly registered.

  3. Event Emission (Line 149): Emitting the ConnectIbcChannel event provides transparency for the channel connection process. Ensure that the event parameters are accurately populated.

  4. TODO Comments (Lines 132-134): The TODO comments suggest areas for improvement, such as checking for duplicated channel registration and moving the call to the Channel constructor to the openIbcChannel phase. These improvements should be prioritized to enhance the contract's robustness and clarity.

Line 136 uses the counterparty version instead of the self version for channel registration. This could lead to incorrect channel information being stored. Consider revising this to use the correct version.

Would you like assistance in addressing the TODO comments mentioned in lines 132-134? Implementing these improvements could enhance the contract's functionality and maintainability.

@nicopernas nicopernas merged commit fa7b730 into main Mar 12, 2024
2 checks passed
@nicopernas nicopernas deleted the nico/revert-split-api branch March 12, 2024 18:48
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