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

Reduce contract size to ensure the contract is deployable #44

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

dshiell
Copy link
Collaborator

@dshiell dshiell commented Feb 16, 2024

Optimization to reduce contract size to ensure the contract is deployable.

Summary by CodeRabbit

  • Refactor
    • Optimized contract size by removing the channel closure functionality and related tests. This change impacts how channel closures and callbacks are handled.

Copy link

coderabbitai bot commented Feb 16, 2024

Walkthrough

The recent update involves streamlining the Dispatcher smart contract by omitting the onCloseIbcChannel function and related channel closure functionality within the DispatcherCloseChannelTest. This modification is primarily aimed at optimizing the contract size, focusing on simplifying the channel management by removing the complexities associated with channel closures and their callback mechanisms.

Changes

Files Change Summary
contracts/core/Dispatcher.sol Removed onCloseIbcChannel function for size optimization.
test/Dispatcher.t.sol Commented out channel closure functionality in tests.

🐰✨
In the land of code and spell,
A rabbit hopped, and tweaks did tell.
"Away with closure, sleek we aim,
To optimize, not play the same.
Through ethers vast, our contract sails,
Lighter, swifter, on digital trails."
🌟🐾

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.
  • 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 from git 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 marked this pull request as ready for review February 19, 2024 18:09
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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f915d5f and 0a8dbb8.
Files selected for processing (2)
  • contracts/core/Dispatcher.sol (1 hunks)
  • test/Dispatcher.t.sol (1 hunks)
Files skipped from review due to trivial changes (1)
  • test/Dispatcher.t.sol

Comment on lines +299 to +319
// FIXME this is commented out to make the contract size smaller. We need to optimise for size
// function onCloseIbcChannel(address portAddress, bytes32 channelId, Ics23Proof calldata proof) external {
// // verify VIBC/IBC hub chain has processed ChanCloseConfirm event
// consensusStateManager.verifyMembership(
// proof,
// bytes('channel/path/to/be/added/here'),
// bytes('expected channel bytes constructed from params. Channel.State = {Closed(_Pending?)}')
// );
//
// // ensure port owns channel
// Channel memory channel = portChannelMap[portAddress][channelId];
// if (channel.counterpartyChannelId == bytes32(0)) {
// revert channelNotOwnedByPortAddress();
// }
//
// // confirm with dApp by calling its callback
// IbcChannelReceiver reciever = IbcChannelReceiver(portAddress);
// reciever.onCloseIbcChannel(channelId, channel.counterpartyPortId, channel.counterpartyChannelId);
// delete portChannelMap[portAddress][channelId];
// emit CloseIbcChannel(portAddress, channelId);
// }
Copy link

Choose a reason for hiding this comment

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

The onCloseIbcChannel function has been commented out to reduce the contract size, which is a critical step towards ensuring the contract's deployability. However, this change impacts the contract's ability to handle channel closure events. It's important to consider the implications of this removal on the overall system functionality and whether alternative optimizations could achieve size reduction without sacrificing important features.

Consider optimizing contract size through other methods such as code refactoring, using libraries, or splitting the contract into smaller contracts to preserve important functionalities like channel closure handling.

Comment on lines 296 to 322
* The dApp's onCloseIbcChannel callback is invoked.
* dApp should throw an error if the channel should not be closed.
*/
function onCloseIbcChannel(address portAddress, bytes32 channelId, Ics23Proof calldata proof) external {
// verify VIBC/IBC hub chain has processed ChanCloseConfirm event
consensusStateManager.verifyMembership(
proof,
bytes('channel/path/to/be/added/here'),
bytes('expected channel bytes constructed from params. Channel.State = {Closed(_Pending?)}')
);

// ensure port owns channel
Channel memory channel = portChannelMap[portAddress][channelId];
if (channel.counterpartyChannelId == bytes32(0)) {
revert channelNotOwnedByPortAddress();
}

// confirm with dApp by calling its callback
IbcChannelReceiver reciever = IbcChannelReceiver(portAddress);
reciever.onCloseIbcChannel(channelId, channel.counterpartyPortId, channel.counterpartyChannelId);
delete portChannelMap[portAddress][channelId];
emit CloseIbcChannel(portAddress, channelId);
}
// FIXME this is commented out to make the contract size smaller. We need to optimise for size
// function onCloseIbcChannel(address portAddress, bytes32 channelId, Ics23Proof calldata proof) external {
// // verify VIBC/IBC hub chain has processed ChanCloseConfirm event
// consensusStateManager.verifyMembership(
// proof,
// bytes('channel/path/to/be/added/here'),
// bytes('expected channel bytes constructed from params. Channel.State = {Closed(_Pending?)}')
// );
//
// // ensure port owns channel
// Channel memory channel = portChannelMap[portAddress][channelId];
// if (channel.counterpartyChannelId == bytes32(0)) {
// revert channelNotOwnedByPortAddress();
// }
//
// // confirm with dApp by calling its callback
// IbcChannelReceiver reciever = IbcChannelReceiver(portAddress);
// reciever.onCloseIbcChannel(channelId, channel.counterpartyPortId, channel.counterpartyChannelId);
// delete portChannelMap[portAddress][channelId];
// emit CloseIbcChannel(portAddress, channelId);
// }

//
// IBC Packet methods
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The contract uses SPDX license identifier UNLICENSED, which is appropriate for private or unpublished code but might not be suitable if the code is intended to be open-sourced. Ensure that the licensing aligns with the project's distribution and usage intentions.

Consider specifying a more specific license if the code is intended for open-source distribution, to clearly communicate usage rights and restrictions.


📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [3-3]

The contract specifies Solidity version ^0.8.9. It's good practice to use a fixed Solidity version or a more constrained version range to avoid unexpected behavior due to compiler updates.

Consider using a fixed version or a narrower version range for Solidity to ensure consistent contract behavior.

- pragma solidity ^0.8.9;
+ pragma solidity 0.8.9;

Copy link
Contributor

@nicopernas nicopernas left a comment

Choose a reason for hiding this comment

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

I'm self-approving so we can unblock

@nicopernas nicopernas merged commit 07362dd into main Feb 19, 2024
1 check passed
@nicopernas nicopernas deleted the nico/reduce-sizes branch February 19, 2024 19:26
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