Skip to content

Conversation

@fbac
Copy link
Collaborator

@fbac fbac commented Feb 28, 2025

#550 was closed in favor of this PR, where the changes will be implemented incrementally to support the migrator tool and further modifications.

Closes #542

Summary by CodeRabbit

  • New Features

    • Introduced a new deployment command for version 2 of nodes.
    • Enhanced node management with distinct handling for API and replication nodes.
  • Refactor

    • Redesigned node operations with improved naming conventions and streamlined error/event reporting.
  • Tests

    • Expanded testing coverage to include new node functionalities and deployment scenarios.
  • Chores

    • Updated maintainer contact information in Dockerfiles.
    • Updated deployment utilities and helper configurations to support the new NodesV2 features.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 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 11 minutes and 12 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 44aab04 and f5fa384.

📒 Files selected for processing (1)
  • contracts/dev/lib/common (1 hunks)

Walkthrough

The changes introduce a new deployment option for a NodesV2 contract across deployment scripts, smart contract implementations, interfaces, tests, and associated test utilities. The NodesV2 contract now manages nodes with separate mappings for API and replication functionalities, adds new enabling/disabling functions, and renames several functions for clarity. Additionally, the INodes interface is restructured by splitting out error and event definitions, and test cases as well as proxy address handling are updated accordingly.

Changes

Files Changes Summary
contracts/dev/deploy-local, contracts/dev/lib/common Added new deployment command forge_deploy_script nodes_v2 and a corresponding case option for deploying the NodesV2 contract.
contracts/src/NodesV2.sol Revised node management by introducing separate mappings for API and replication nodes; added new functions (e.g., enableNode, disableNode) and modifiers; renamed several functions for improved clarity.
contracts/src/interfaces/INodes.sol Restructured the interface by splitting errors and events into INodesErrors and INodesEvents while updating function signatures and the Node struct to reflect the new node management logic.
contracts/test/Nodes.sol Refactored and renamed test functions to match updated naming conventions; added tests for node enabling/disabling and improved event/error handling.
pkg/testutils/config.go, pkg/testutils/contracts.go Enhanced JSON proxy address parsing to support XMTPNodeRegistry JSON files and added new deployment handling for the NodesV2 contract, including a new constant and deployment function.
dev/baked/Dockerfile, dev/docker/Dockerfile, dev/docker/Dockerfile-cli Updated maintainer email address from engineering@xmtp.com to eng@ephemerahq.com.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant D as Deployment Script
    participant F as Forge Script
    participant BC as Blockchain

    U ->> D: Execute "forge_deploy_script nodes_v2"
    D ->> D: Parse command and select NodesV2 deployment
    D ->> F: Invoke DeployNodeRegistryV2 with RPC URL
    F ->> BC: Deploy NodesV2 contract
    BC -->> F: Return deployment details
    F -->> D: Provide success/error response
    D -->> U: Output deployment result
Loading
sequenceDiagram
    participant U as User
    participant C as NodesV2 Contract

    U ->> C: Call transferFrom() for node transfer
    C ->> C: Disable API and Replication node functionalities
    C ->> C: Complete ownership transfer
    C -->> U: Confirm transfer with node deactivation
Loading

Possibly Related PRs

  • ci: slither and soldeer #310: The changes in the main PR, which involve adding a new command for deploying a specific version of the nodes contract, are related to the modifications in the retrieved PR that include the addition of a command to update dependencies before deploying smart contracts, as both pertain to deployment functionalities.
  • Handle pipefail in bash contract scripts #488: The changes in the main PR, which involve adding a new command to the deployment script for the nodes_v2 contract, are related to the modifications in the retrieved PR that enhance error handling in the forge_deploy_script function, as both PRs involve changes to the deployment process of contracts.
  • feat!: enhancements to XMTP Nodes Registry #524: The changes in the main PR, which involve adding a new command for deploying the NodesV2 contract, are directly related to the modifications in the retrieved PR that enhance the Nodes NFT and introduce a new contract structure for managing nodes, including the NodesV2 contract. Both PRs focus on the deployment and management of the NodesV2 contract and its functionalities.

Suggested Reviewers

  • neekolas

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.
  • @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
Contributor

@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: 2

🧹 Nitpick comments (1)
pkg/testutils/config.go (1)

87-88: Consider maintaining naming consistency.

The name "XMTPNodeRegistry" uses a different naming pattern compared to other proxy addresses like "groupMessagesProxy" and "identityUpdatesProxy". This inconsistency could lead to confusion or maintenance issues.

Consider using a consistent naming convention across all proxy addresses:

-	case strings.Contains(fileName, "XMTPNodeRegistry.json"):
-		return fastjson.GetString(data, "addresses", "XMTPNodeRegistry")
+	case strings.Contains(fileName, "NodesV2.json"):
+		return fastjson.GetString(data, "addresses", "nodesV2Proxy")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82bf0e3 and 7beefe9.

📒 Files selected for processing (7)
  • contracts/dev/deploy-local (1 hunks)
  • contracts/dev/lib/common (1 hunks)
  • contracts/src/NodesV2.sol (6 hunks)
  • contracts/src/interfaces/INodes.sol (7 hunks)
  • contracts/test/Nodes.sol (15 hunks)
  • pkg/testutils/config.go (1 hunks)
  • pkg/testutils/contracts.go (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Test (Node)
  • GitHub Check: Build pre-baked anvil-xmtpd
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
🔇 Additional comments (39)
contracts/dev/deploy-local (1)

33-33: LGTM!

The addition of forge_deploy_script nodes_v2 correctly enables the deployment of the new NodesV2 contract, complementing the existing deployment options.

pkg/testutils/contracts.go (3)

16-16: LGTM!

The import for the nodesv2 package is correctly added.


27-27: LGTM!

The constant NODES_V2_CONTRACT_NAME is appropriately defined and follows the existing naming pattern.


143-145: LGTM!

The DeployNodesV2Contract helper function correctly follows the pattern of existing deployment functions.

contracts/dev/lib/common (2)

40-49: LGTM!

The implementation for the nodes_v2 case is well-structured, following the pattern established by other deployment scripts. Error handling is properly implemented, ensuring that deployment failures are caught and reported.


40-49:

Details

❌ Incorrect review comment

Verify file naming consistency.

The NodesV2 contract deployment details are written to "XMTPNodeRegistry.json", which doesn't follow the naming pattern of other contracts (where the file is typically named after the contract). This inconsistency could lead to confusion.


🏁 Script executed:

#!/bin/bash
# Check why the output JSON file is named "XMTPNodeRegistry.json" instead of "NodesV2.json"
grep -r "XMTPNodeRegistry" --include="*.sol" .

Length of output: 702


Clarification on Deployment File Naming

The output file naming as "XMTPNodeRegistry.json" is by design. The constant defined in contracts/script/utils/Environment.sol (XMTP_NODE_REGISTRY_OUTPUT_JSON) and its consistent usage in contracts/script/DeployNodeRegistryV2.s.sol indicate that the deployment details for the NodesV2 contract are intentionally written to this file. There is no naming inconsistency in this context.

Likely an incorrect or invalid review comment.

contracts/test/Nodes.sol (20)

8-8: Use of separate interfaces is clean and modular.
No issues found.


23-26: Helpful documentation comments.
These reminders clarify the internal helper functions and recommended usage sequence, improving maintainability.


39-55: Event emission and isDisabled check align with new interface changes.
Consolidating events under INodesEvents and switching to isDisabled make the test logic consistent with the updated contract design.


57-79: Correct error usage for invalid node parameters.
Leveraging INodesErrors.InvalidAddress, InvalidSigningKey, and InvalidHttpAddress ensures clarity and uniformity across the codebase.


116-140: Disable/enable node test covers critical transitions thoroughly.
This test checks both disabling and re-enabling states effectively. The approach of not automatically re-enabling API/replication flags after un-disabling seems intentional.


142-193: Unauthorized or non-existent node scenarios are properly tested.
Ensuring these revert paths helps maintain robust access control.


199-225: Replication node removal tests follow the same pattern as API node removal.
Maintains consistency in error handling, revert messages, and coverage.


365-419: setHttpAddress tests ensure correct revert handling and required privileges.
Good coverage on the “node does not exist,” “invalid address,” and unauthorized calls.


422-466: setIsApiEnabled checks properly handle node ownership, node existence, and disabled states.
These tests confirm each revert path is triggered correctly.


469-513: setIsReplicationEnabled tests mirror API enabling checks.
Consistent naming and error usage across the two enabling features improves maintainability.


516-562: setMinMonthlyFee tests check new error codes and role-based restrictions.
Validates that only authorized roles can update the fee.


565-600: setMaxActiveNodes logic is properly tested, especially for below-current-count scenarios.
This ensures the contract can’t silently reduce capacity below active usage.


603-632: setNodeOperatorCommissionPercent covers happy path and invalid inputs.
Ensures robust checks on max basis points.


642-642: Event-driven base URI updates.
The single event is consistent with the restructured events approach.


662-669: InvalidURI revert checks for empty or missing trailing slash.
Appropriately restricts base URL format.


708-708: Consistent alignment on isDisabled field.
Using vm.assertEq ensures the updated approach works as expected.


713-713: Reverting on non-existent node access.
Properly guards against invalid node IDs.


717-805: Active nodes queries are comprehensive.
Tests thoroughly cover API and replication sets, enabling and disabling flows, and verifying correctness of the results.


839-870: Internal helpers _addNode, _enableNode, and _enableNodes.
These are well-structured, DRY utilities that streamline repeated setup steps.


878-878: Default isDisabled set to false aligns with node enable/disable logic.
This initial value avoids unintentional “disabled” states.

contracts/src/interfaces/INodes.sol (3)

7-45: Introduction of a dedicated INodesErrors interface.
Having distinct error definitions simplifies error handling and fosters clarity across the codebase.


47-120: INodesEvents interface neatly segregates events from core logic.
This separation reduces clutter and makes events easier to discover and maintain.


122-281: Refactored INodes interface with new fields and function signatures.
Adding isDisabled and splitting functionality (API vs. replication) clarifies node states. The extended getter methods provide precise views into node activity.

contracts/src/NodesV2.sol (10)

69-72: Granting both ADMIN_ROLE and NODE_MANAGER_ROLE to _initialAdmin.
Ensures consistent roles for immediate administration.

Would you like to confirm no other addresses require these roles on deployment?


98-109: disableNode properly sets isDisabled and removes the node from active sets.
This is essential to ensure an administratively disabled node doesn’t remain in API or replication sets.


131-139: setMaxActiveNodes checks active sets to prevent accidental reduction below the current count.
Helps maintain system stability by disallowing contradictory configurations.


160-176: Overriding transferFrom to deactivate the node prior to ownership change.
Effectively mitigates the risk of leftover active states when ownership changes.


178-184: setHttpAddress restricted to NODE_MANAGER_ROLE.
Maintains administrative clarity; using a specific role (instead of admin) for node management is a good practice.


186-191: setMinMonthlyFee writer access restricted to NODE_MANAGER_ROLE.
Aligns with the overarching design of limiting node configuration privileges.


198-215: whenNotDisabled modifier ensures only active nodes can enable API/replication.
Prevents accidentally enabling features on disabled nodes and enforces consistent state transitions.


218-297: Comprehensive getters for API and replication statuses.
Implementation with EnumerableSet provides efficient membership checks. The result arrays are built in a loop, which is straightforward for a moderate number of nodes.


299-304: whenNotDisabled ensures node existence and active state.
Enhances contract safety by gatekeeping restricted functions.


318-369: Private helper methods _activateApiNode, _disableApiNode, _activateReplicationNode, _disableReplicationNode.
Encapsulating these calls reduces duplication and helps keep logic consistent for each enable/disable path.

Borja Aranda added 2 commits February 28, 2025 20:09
@fbac fbac marked this pull request as ready for review February 28, 2025 19:21
@fbac fbac requested a review from a team as a code owner February 28, 2025 19:21
@fbac fbac merged commit 5890ef1 into main Feb 28, 2025
14 checks passed
@fbac fbac deleted the 02-28-node_registry_enhancements branch February 28, 2025 22:29
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.

Nodes contract: sanitize deploy script

3 participants