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

chore: updates to node deploy script #546

Merged
merged 5 commits into from
Feb 24, 2025

Conversation

fbac
Copy link
Collaborator

@fbac fbac commented Feb 24, 2025

Closes #542

Summary by CodeRabbit

  • New Features

    • Introduced a new deployment workflow for the node registry that automatically produces a JSON summary of deployment data.
    • Expanded the environment configuration with additional output parameters.
  • Refactor

    • Updated validations in the deployment process to ensure necessary credentials are provided.
    • Streamlined the contract initialization process for a more flexible and robust deployment experience.

@fbac fbac requested a review from a team as a code owner February 24, 2025 16:28
Copy link

coderabbitai bot commented Feb 24, 2025

Warning

Rate limit exceeded

@fbac has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 45 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 9f62eb7 and 8b2e245.

📒 Files selected for processing (1)
  • contracts/script/DeployNodeRegistryV2.s.sol (1 hunks)

Walkthrough

This pull request updates several deployment scripts. In both the GroupMessages and IdentityUpdates scripts, the check ensuring the admin is an Externally Owned Account has been removed and replaced with a new validation that confirms the private key is non-zero. A new constant, XMTP_NODE_REGISTRY_OUTPUT_JSON, is introduced in the Environment utility. In addition, the Node Registry V1 script now instantiates the Nodes contract without passing msg.sender, and a new contract, DeployXMTPNodeRegistry, is added to V2 with functions for deployment and JSON serialization of deployment data.

Changes

File(s) Change Summary
contracts/script/DeployGroupMessages.s.sol, contracts/script/DeployIdentityUpdates.s.sol Removed the admin EOA check (admin.code.length == 0) and added a validation to ensure privateKey is non-zero.
contracts/script/utils/Environment.sol Added a new public constant: XMTP_NODE_REGISTRY_OUTPUT_JSON initialized to "XMTPNodeRegistry".
contracts/script/DeployNodeRegistryV1.s.sol Modified the instantiation of the Nodes contract by removing the msg.sender argument from its constructor.
contracts/script/DeployNodeRegistryV2.s.sol Introduced a new contract DeployXMTPNodeRegistry that deploys the Nodes contract with an admin address and serializes deployment data to JSON.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant DX as DeployXMTPNodeRegistry
    participant Env as Environment
    participant N as Nodes Contract
    participant FS as File System

    U->>DX: Call run()
    DX->>Env: Retrieve admin & privateKey
    Env-->>DX: Return admin & privateKey
    DX->>DX: Validate privateKey is non-zero
    DX->>N: Deploy new Nodes(admin)
    N-->>DX: Return deployed contract instance
    DX->>FS: Serialize and write deployment data to JSON file
    FS-->>DX: Confirm write operation
Loading

Possibly related PRs

Suggested reviewers

  • richardhuaaa
  • mkysel

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

🧹 Nitpick comments (1)
contracts/script/DeployNodeRegistry.s.sol (1)

32-48: Improve string constants and naming.

Consider making the string literals constants and using a more descriptive name for the parent object.

Apply this diff to improve the code:

+    string private constant PARENT_OBJECT = "xmtp_node_registry";
+    string private constant ADDRESSES_KEY = "addresses";
+    string private constant DEPLOYER_KEY = "XMTPNodeRegistryDeployer";
+    string private constant ADMIN_KEY = "XMTPNodeRegistryInitialAdmin";
+    string private constant REGISTRY_KEY = "XMTPNodeRegistry";
+    string private constant DEPLOYMENT_BLOCK_KEY = "deploymentBlock";
+    string private constant UPGRADE_BLOCK_KEY = "latestUpgradeBlock";
+
     function _serializeDeploymentData() internal {
-        string memory parent_object = "parent object";
-        string memory addresses = "addresses";
         string memory addressesOutput;

-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistryDeployer", deployer);
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistryInitialAdmin", admin);
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistry", address(nodes));
+        addressesOutput = vm.serializeAddress(ADDRESSES_KEY, DEPLOYER_KEY, deployer);
+        addressesOutput = vm.serializeAddress(ADDRESSES_KEY, ADMIN_KEY, admin);
+        addressesOutput = vm.serializeAddress(ADDRESSES_KEY, REGISTRY_KEY, address(nodes));

         string memory finalJson;
-        finalJson = vm.serializeString(parent_object, addresses, addressesOutput);
-        finalJson = vm.serializeUint(parent_object, "deploymentBlock", block.number);
-        finalJson = vm.serializeUint(parent_object, "latestUpgradeBlock", block.number);
+        finalJson = vm.serializeString(PARENT_OBJECT, ADDRESSES_KEY, addressesOutput);
+        finalJson = vm.serializeUint(PARENT_OBJECT, DEPLOYMENT_BLOCK_KEY, block.number);
+        finalJson = vm.serializeUint(PARENT_OBJECT, UPGRADE_BLOCK_KEY, block.number);

         writeOutput(finalJson, XMTP_NODE_REGISTRY_OUTPUT_JSON);
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79c6dbd and 3285959.

📒 Files selected for processing (4)
  • contracts/script/DeployGroupMessages.s.sol (0 hunks)
  • contracts/script/DeployIdentityUpdates.s.sol (0 hunks)
  • contracts/script/DeployNodeRegistry.s.sol (1 hunks)
  • contracts/script/utils/Environment.sol (1 hunks)
💤 Files with no reviewable changes (2)
  • contracts/script/DeployIdentityUpdates.s.sol
  • contracts/script/DeployGroupMessages.s.sol
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: abis
🔇 Additional comments (3)
contracts/script/utils/Environment.sol (1)

9-9: LGTM!

The new constant follows the established naming convention and aligns with the contract renaming in DeployNodeRegistry.s.sol.

contracts/script/DeployNodeRegistry.s.sol (2)

4-10: LGTM!

The imports and contract inheritance are well-structured and follow good practices.


11-14: LGTM!

The state variables are well-defined and necessary for the deployment process.

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 (1)
contracts/script/DeployNodeRegistry.s.sol (1)

34-50: Consider defining string literals as constants.

The string literals "parent object" and "addresses" should be defined as constants for better maintainability and to avoid magic strings.

 contract DeployXMTPNodeRegistry is Script, Environment, Utils {
+    string constant PARENT_OBJECT = "parent object";
+    string constant ADDRESSES = "addresses";
     Nodes nodes;
     
     // ... existing code ...
     
     function _serializeDeploymentData() internal {
-        string memory parent_object = "parent object";
-        string memory addresses = "addresses";
+        string memory addressesOutput;
 
-        string memory addressesOutput;
-
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistryDeployer", deployer);
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistryInitialAdmin", admin);
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistry", address(nodes));
+        addressesOutput = vm.serializeAddress(ADDRESSES, "XMTPNodeRegistryDeployer", deployer);
+        addressesOutput = vm.serializeAddress(ADDRESSES, "XMTPNodeRegistryInitialAdmin", admin);
+        addressesOutput = vm.serializeAddress(ADDRESSES, "XMTPNodeRegistry", address(nodes));
 
         string memory finalJson;
-        finalJson = vm.serializeString(parent_object, addresses, addressesOutput);
-        finalJson = vm.serializeUint(parent_object, "deploymentBlock", block.number);
-        finalJson = vm.serializeUint(parent_object, "latestUpgradeBlock", block.number);
+        finalJson = vm.serializeString(PARENT_OBJECT, ADDRESSES, addressesOutput);
+        finalJson = vm.serializeUint(PARENT_OBJECT, "deploymentBlock", block.number);
+        finalJson = vm.serializeUint(PARENT_OBJECT, "latestUpgradeBlock", block.number);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3285959 and 6f2ebd0.

📒 Files selected for processing (3)
  • contracts/script/DeployGroupMessages.s.sol (1 hunks)
  • contracts/script/DeployIdentityUpdates.s.sol (1 hunks)
  • contracts/script/DeployNodeRegistry.s.sol (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • contracts/script/DeployIdentityUpdates.s.sol
  • contracts/script/DeployGroupMessages.s.sol
🔇 Additional comments (3)
contracts/script/DeployNodeRegistry.s.sol (3)

4-8: LGTM! Well-organized imports.

The imports are logically organized and align with the contract's new functionality.


10-14: LGTM! Clear contract structure.

The contract name is descriptive, and the state variables are well-organized with appropriate inheritance.


16-32: LGTM! Robust deployment flow with proper validations.

The deployment flow includes all necessary validations, including the previously suggested private key check.

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

🧹 Nitpick comments (1)
contracts/script/DeployNodeRegistryV2.s.sol (1)

34-50: Consider using constants for string literals.

The JSON keys and object names could be defined as constants to improve maintainability and prevent typos.

 contract DeployXMTPNodeRegistry is Script, Environment, Utils {
+    string constant PARENT_OBJECT = "parent object";
+    string constant ADDRESSES_OBJECT = "addresses";
+    string constant DEPLOYER_KEY = "XMTPNodeRegistryDeployer";
+    string constant ADMIN_KEY = "XMTPNodeRegistryInitialAdmin";
+    string constant REGISTRY_KEY = "XMTPNodeRegistry";
+    string constant DEPLOYMENT_BLOCK_KEY = "deploymentBlock";
+    string constant UPGRADE_BLOCK_KEY = "latestUpgradeBlock";

     function _serializeDeploymentData() internal {
-        string memory parent_object = "parent object";
-        string memory addresses = "addresses";
+        string memory addressesOutput;
 
-        string memory addressesOutput;
-
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistryDeployer", deployer);
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistryInitialAdmin", admin);
-        addressesOutput = vm.serializeAddress(addresses, "XMTPNodeRegistry", address(nodes));
+        addressesOutput = vm.serializeAddress(ADDRESSES_OBJECT, DEPLOYER_KEY, deployer);
+        addressesOutput = vm.serializeAddress(ADDRESSES_OBJECT, ADMIN_KEY, admin);
+        addressesOutput = vm.serializeAddress(ADDRESSES_OBJECT, REGISTRY_KEY, address(nodes));
 
         string memory finalJson;
-        finalJson = vm.serializeString(parent_object, addresses, addressesOutput);
-        finalJson = vm.serializeUint(parent_object, "deploymentBlock", block.number);
-        finalJson = vm.serializeUint(parent_object, "latestUpgradeBlock", block.number);
+        finalJson = vm.serializeString(PARENT_OBJECT, ADDRESSES_OBJECT, addressesOutput);
+        finalJson = vm.serializeUint(PARENT_OBJECT, DEPLOYMENT_BLOCK_KEY, block.number);
+        finalJson = vm.serializeUint(PARENT_OBJECT, UPGRADE_BLOCK_KEY, block.number);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6f2ebd0 and 9f62eb7.

📒 Files selected for processing (2)
  • contracts/script/DeployNodeRegistryV1.s.sol (1 hunks)
  • contracts/script/DeployNodeRegistryV2.s.sol (1 hunks)
🔇 Additional comments (3)
contracts/script/DeployNodeRegistryV2.s.sol (3)

10-14: LGTM!

The contract inheritance and state variables are well-structured for a deployment script.


49-49:

✅ Verification successful

Verify the output file constant.

The XMTP_NODE_REGISTRY_OUTPUT_JSON constant should be defined in the Environment contract.

Let's verify the constant definition:


🏁 Script executed:

#!/bin/bash
# Description: Check for XMTP_NODE_REGISTRY_OUTPUT_JSON constant in Environment contract
rg "XMTP_NODE_REGISTRY_OUTPUT_JSON" contracts/script/utils/Environment.sol

Length of output: 154


Constant Verification: The XMTP_NODE_REGISTRY_OUTPUT_JSON constant is correctly defined in the contracts/script/utils/Environment.sol file with the value "XMTPNodeRegistry", as expected. No changes are needed here.


16-32:

✅ Verification successful

Verify the intentional removal of admin address validation.

The script only validates that the admin address is non-zero but doesn't check if it's a contract address. According to the AI summary, this is an intentional change aligned with other deployment scripts.

Let's verify this pattern in other deployment scripts:


🏁 Script executed:

#!/bin/bash
# Description: Check for admin address validation in other deployment scripts
rg -A 5 "XMTP_NODE_REGISTRY_ADMIN_ADDRESS" contracts/script/

Length of output: 672


Confirm intentional omission of additional admin validation

After verifying the code in contracts/script/DeployNodeRegistryV2.s.sol, it's clear that the admin address is retrieved from the environment and only checked to ensure it isn’t the zero address. No extra validation (such as checking that the admin isn’t a contract) is performed, which is consistent with the behavior observed in similar deployment scripts.

  • Verification findings:
    • The deployment script only validates that the admin address is non-zero.
    • A search in the deployment scripts did not reveal any extra contract address validation for the admin.

Please confirm that this minimal validation is an intentional design choice.

@fbac fbac merged commit 25ee31b into contracts/add-active-metadata Feb 24, 2025
11 checks passed
@fbac fbac deleted the nodes/deploy-script branch February 24, 2025 22:05
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