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

make dispatcher reinitializable + add initilization to upgrade specs #134

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

RnkSngh
Copy link
Collaborator

@RnkSngh RnkSngh commented Jul 2, 2024

PR to make dispatcher reinitializable

this adds a minor change to our dispatcher implementation, where we have our initializing function inherit from reinitializer(2) rather than initializer. This will allow us to override the init version for our existing prod + staging contracts to allow setting the fee vault.

Correspondingly, there is a minor feature addition to add initialization to trasnactions as well (similar to existing functionality of constructor initialization), which renders $INITDATA sent to tx specs. This will be utilized in proxy upgrades which utilize initializers (i.e. any contract upgrades which need to modify setting state)

Summary by CodeRabbit

  • New Features
    • Improved initialization logic for deploying smart contracts.
    • Enhanced transaction schema with new initialization fields.
    • Added support for encoding initialization arguments using the ethers library.
  • Bug Fixes
    • Fixed visibility and reinitialization issues in the Dispatcher contract.
  • Updates
    • Modified the initialization parameters in deployment and transaction functions for better consistency and clarity.

@RnkSngh RnkSngh requested a review from h5law July 2, 2024 19:19
Copy link

coderabbitai bot commented Jul 2, 2024

Walkthrough

The modifications involve enhancing initialization logic by adding explicit visibility modifiers, updating reinitializer values, and modifying related scripts. This includes restructuring various parameter handling elements and introducing new functions for encoding initialization arguments, enhancing the clarity and functionality of the initialization processes.

Changes

File Change Summary
contracts/core/Dispatcher.sol Restructured initialize function; added visibility modifiers and reordered other modifiers.
src/deploy.ts Removed old init data code, added renderArgs(init) call in getDeployData function.
src/evm/schemas/tx.ts Added a new init field to TxItemSchema.
src/tx.ts Updated sendTxToChain to include the tx.init parameter in renderArgs calls.
src/utils/io.ts Added compileInitArgs function and updated renderArgs to handle initialization data.
.../DispatcherV2Initializable.sol Updated reinitializer parameter in initialize function from 2 to 3.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Dispatcher
    participant Deployer
    participant ExternalContract
    
    User->>Deployer: Initiate Deployment
    Deployer->>Dispatcher: initialize(initPortPrefix, _feeVault)
    Dispatcher-->>User: Initialization Complete
    
    User->>Dispatcher: Send Transaction (with init)
    Dispatcher->>ExternalContract: renderArgs(init.args, init.signature)
    ExternalContract-->>Dispatcher: Response
    Dispatcher-->>User: Transaction Sent
Loading

Poem

In code's vast realm, the changes swayed,
🌟 Initialization got an upgrade.
Dispatcher and Deployer, a dance so grand,
Together they enhance and better stand.
Args compiled, new paths unfurled,
Cheering progress in our coding world! 🎉

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7083cc5 and ccdb0ee.

Files selected for processing (6)
  • contracts/core/Dispatcher.sol (1 hunks)
  • src/deploy.ts (1 hunks)
  • src/evm/contracts/factories/Dispatcher__factory.ts (1 hunks)
  • src/evm/schemas/tx.ts (1 hunks)
  • src/tx.ts (1 hunks)
  • src/utils/io.ts (2 hunks)
Files not summarized due to errors (1)
  • src/evm/contracts/factories/Dispatcher__factory.ts: Error: Message exceeds token limit
Additional comments not posted (6)
src/evm/schemas/tx.ts (1)

14-19: Add documentation for the new init field.

The new init field in the TxItemSchema should be documented to clarify its purpose and usage.

// Initialization data for the transaction, including the signature and arguments.
init: z.optional(
  z.object({
    signature: z.string().min(1),
    args: z.array(z.string().min(1)),
  })
),
src/tx.ts (1)

78-79: Verify the correctness of renderArgs usage with tx.init.

Ensure that the tx.init parameter is correctly handled in the renderArgs function and that it does not introduce any side effects.

Verification successful

Verified the correctness of renderArgs usage with tx.init.

The renderArgs function correctly handles the tx.init parameter by compiling initial arguments and replacing $INITARGS in the args array without introducing any side effects.

  • The implementation of renderArgs is located in src/utils/io.ts.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `renderArgs` with the `tx.init` parameter.

# Test: Search for the `renderArgs` function implementation and verify its handling of `tx.init`.
rg --type typescript $'renderArgs'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify the usage of `renderArgs` with the `tx.init` parameter.

# Test: Search for the `renderArgs` function implementation and verify its handling of `tx.init`.
rg --type ts 'renderArgs'

Length of output: 335



Script:

#!/bin/bash
# Description: Extract the implementation of the `renderArgs` function from `src/utils/io.ts`.

# Extract the `renderArgs` function implementation.
ast-grep --lang typescript --pattern $'export const renderArgs = ($_$) => {
  $$$
}' src/utils/io.ts

Length of output: 101



Script:

#!/bin/bash
# Description: Extract the implementation of the `renderArgs` function from `src/utils/io.ts`.

# Search for the `renderArgs` function definition and extract its implementation.
rg 'renderArgs' -A 20 src/utils/io.ts

Length of output: 557

src/deploy.ts (1)

52-52: Verify the correctness of renderArgs usage with init.

Ensure that the init parameter is correctly handled in the renderArgs function within getDeployData.

Verification successful

Verified the correctness of renderArgs usage with init.

The init parameter is correctly handled in the renderArgs function, ensuring proper integration and functionality.

  • src/utils/io.ts: lines 282-300
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `renderArgs` with the `init` parameter in `getDeployData`.

# Test: Search for the `renderArgs` function implementation and verify its handling of `init`.
rg --type typescript $'renderArgs'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify the usage of `renderArgs` with the `init` parameter in `getDeployData`.

# Test: Search for the `renderArgs` function implementation and verify its handling of `init`.
ast-grep --lang typescript --pattern $'function renderArgs($_, $_, $_) {
  $$$
}'

Length of output: 82



Script:

#!/bin/bash
# Description: Verify the usage of `renderArgs` with the `init` parameter in `getDeployData`.

# Test: Search for all occurrences of `renderArgs` in the codebase to locate the function definition.
rg 'renderArgs'

Length of output: 325



Script:

#!/bin/bash
# Description: Extract the implementation of the `renderArgs` function from `src/utils/io.ts` to verify its handling of the `init` parameter.

# Test: Extract the `renderArgs` function implementation.
ast-grep --lang typescript --pattern $'export const renderArgs = ($_,$_,$_) => {
  $$$
}' src/utils/io.ts

Length of output: 1001

contracts/core/Dispatcher.sol (1)

80-85: LGTM! Verify the usage of reinitializer(2).

The use of reinitializer(2) is appropriate for allowing reinitialization with a new version number.

Ensure that all necessary checks and balances are in place for reinitialization.

Verification successful

Usage of reinitializer(2) verified and appropriate.

The reinitializer(2) modifier is correctly used in contracts/core/Dispatcher.sol to allow reinitialization with a new version number. This ensures proper handling of contract upgrades.

  • Location: contracts/core/Dispatcher.sol, line 83
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all occurrences of `reinitializer` in the codebase.

# Test: Search for the usage of `reinitializer`. Expect: Only occurances with appropriate version numbers.
rg --type solidity $'reinitializer'

Length of output: 67



Script:

#!/bin/bash
# Description: Verify all occurrences of `reinitializer` in the Solidity codebase.

# Use `fd` to find all Solidity files and then search for `reinitializer` in those files.
fd -e sol -x grep -Hn 'reinitializer' {}

Length of output: 7973

src/evm/contracts/factories/Dispatcher__factory.ts (2)

Line range hint 14-14: Ensure consistent formatting for autogenerated files.

The comment indicates the file is autogenerated. Ensure that any manual changes are consistently applied across the project to maintain uniformity.


2114-2114: Update _bytecode variable to reflect new contract changes.

The _bytecode variable has been updated. Ensure that this change corresponds to the latest contract deployment bytecode.

src/tx.ts Show resolved Hide resolved
src/utils/io.ts Show resolved Hide resolved
src/utils/io.ts Show resolved Hide resolved
@RnkSngh RnkSngh force-pushed the raunak/add-tx-init branch from ccdb0ee to 930d80c Compare July 2, 2024 19:37
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 ccdb0ee and 930d80c.

Files selected for processing (7)
  • contracts/core/Dispatcher.sol (1 hunks)
  • src/deploy.ts (1 hunks)
  • src/evm/contracts/factories/Dispatcher__factory.ts (1 hunks)
  • src/evm/schemas/tx.ts (1 hunks)
  • src/tx.ts (1 hunks)
  • src/utils/io.ts (2 hunks)
  • test/upgradeableProxy/upgrades/DispatcherV2Initializable.sol (1 hunks)
Files not summarized due to errors (1)
  • src/evm/contracts/factories/Dispatcher__factory.ts: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (5)
  • contracts/core/Dispatcher.sol
  • src/deploy.ts
  • src/evm/schemas/tx.ts
  • src/tx.ts
  • src/utils/io.ts
Additional comments not posted (3)
test/upgradeableProxy/upgrades/DispatcherV2Initializable.sol (1)

Line range hint 33-38: Verify the correct usage of reinitializer(3).

The change from reinitializer(2) to reinitializer(3) allows for a new initialization version. Ensure that this change aligns with the contract's upgrade and initialization logic.

src/evm/contracts/factories/Dispatcher__factory.ts (2)

2114-2114: Verify the correct handling of transaction overrides.

Ensure that the overrides parameter is correctly passed and handled in the getDeployTransaction method.

Verification successful

Verified the correct handling of transaction overrides.

The overrides parameter is correctly passed and handled in the getDeployTransaction method within the Dispatcher__factory.ts file. The method uses overrides || {} to ensure that a default empty object is provided if overrides is not supplied.

  • File: src/evm/contracts/factories/Dispatcher__factory.ts
  • Lines: 2114-2114
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct handling of transaction overrides in the codebase.

# Test: Search for the usage of getDeployTransaction method. Expect: Correct handling of overrides parameter.
rg --type typescript $'getDeployTransaction'

Length of output: 78



Script:

#!/bin/bash
# Description: Verify the correct handling of transaction overrides in the codebase.

# Test: Search for the usage of getDeployTransaction method. Expect: Correct handling of overrides parameter.
rg --type ts 'getDeployTransaction'

Length of output: 5429


2114-2114: Ensure the new placeholders in the bytecode are correct.

The placeholders __$d825222459c46c14afb2efe0967c30e98d$__ and __$f61eb90c6f674e787d51c07f105fa231e2$__ should match the actual addresses of Ibc and IbcUtils libraries respectively.

Copy link
Contributor

@h5law h5law left a comment

Choose a reason for hiding this comment

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

LGTM small but good change - curious does this not change the bindings?

@RnkSngh
Copy link
Collaborator Author

RnkSngh commented Jul 2, 2024

LGTM small but good change - curious does this not change the bindings?

We didn't change the interface (making a function external vs public doesn't change the abi at all) so no go bindings were changed.

We DID change the contract bytecode, which is why we have new typescript bindings

@RnkSngh RnkSngh merged commit 6772519 into main Jul 2, 2024
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 11, 2024
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