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

Contract deploy: record L2 contract addresses #1667

Merged
merged 2 commits into from
Nov 29, 2023

Conversation

BedrockSquirrel
Copy link
Collaborator

Why this change is needed

We should record and serve the contract addresses for L2 bridge and cross-chain messenger.

What changes were made as part of this PR

Deployer writes new contract addresses to mgmt contract for reference.

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Nov 27, 2023

Walkthrough

The changes across the deployment scripts for a blockchain project focus on improving code clarity and extending functionality. Variable names have been made more descriptive, additional operations for setting contract addresses have been included, and there is now logging for the deployment of a Layer 2 bridge. Additionally, a minor formatting fix was applied to a console log statement, and new logic was added to interact with a management contract during the deployment of a cross-chain messenger.

Changes

File Path Change Summary
.../bridge/001_deploy_bridge.ts Renamed variable for clarity, added operations for setting contract addresses, and implemented logging for L2 bridge deployment.
.../messenger/layer1/001_deploy_cross_chain_messenger.ts Added a semicolon to a console log statement for proper formatting.
.../messenger/layer2/001_deploy_cross_chain_messenger.ts Added companionNetworks variable, retrieved management contract address, and added logic for setting the L2CrossChainMessenger contract address with transaction receipt handling.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

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 3af59e7 and 5ea9597.
Files selected for processing (3)
  • contracts/deployment_scripts/bridge/001_deploy_bridge.ts (2 hunks)
  • contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts (1 hunks)
  • contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts (2 hunks)
Files skipped from review due to trivial changes (2)
  • contracts/deployment_scripts/bridge/001_deploy_bridge.ts
  • contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts
Additional comments: 1
contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts (1)
  • 28-47: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [11-47]

The busAddress is currently hardcoded, as noted by the TODO comment. Ensure that this is addressed before production deployment to avoid potential issues with address mismatches in different environments.

} = hre;
// Use the contract addresses from the management contract deployment.
const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!!
Copy link

Choose a reason for hiding this comment

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

The non-null assertion operator !! is used without checking if MGMT_CONTRACT_ADDRESS is actually set, which could lead to runtime errors if the environment variable is not provided. Consider adding a check to ensure the variable is set before using it.

- const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!!
+ const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS;
+ if (!mgmtContractAddress) {
+     throw new Error('MGMT_CONTRACT_ADDRESS is not set');
+ }

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!!
const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS;
if (!mgmtContractAddress) {
throw new Error('MGMT_CONTRACT_ADDRESS is not set');
}

const tx = await mgmtContract.SetImportantContractAddress("L2CrossChainMessenger", crossChainDeployment.address);
const receipt = await tx.wait();
if (receipt.status !== 1) {
console.log("Failed to set L2CrossChainMessenger in management contract");
Copy link

Choose a reason for hiding this comment

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

The error message in the console.log statement could be more informative by including the transaction hash or additional details to aid in debugging.

- console.log("Failed to set L2CrossChainMessenger in management contract");
+ console.log(`Failed to set L2CrossChainMessenger in management contract, transaction hash: ${tx.hash}`);

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
console.log("Failed to set L2CrossChainMessenger in management contract");
console.log(`Failed to set L2CrossChainMessenger in management contract, transaction hash: ${tx.hash}`);

Comment on lines 31 to 35
const crossChainDeployment = await deployments.deploy('CrossChainMessenger', {
from: deployer,
args: [ busAddress ],
log: true,
});
Copy link

Choose a reason for hiding this comment

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

There is no error handling for the deployment of CrossChainMessenger. If the deployment fails, the script will continue to execute, potentially leading to misleading logs or further errors. Consider adding error handling after the deployment attempt.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5ea9597 and b1d12d8.
Files selected for processing (3)
  • contracts/deployment_scripts/bridge/001_deploy_bridge.ts (2 hunks)
  • contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts (1 hunks)
  • contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts (3 hunks)
Files skipped from review due to trivial changes (2)
  • contracts/deployment_scripts/bridge/001_deploy_bridge.ts
  • contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts
Additional comments: 1
contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts (1)
  • 15-15: Verify whether the companionNetworks variable is used elsewhere in the code. If not, consider removing it to avoid confusion and maintain clean code.

@BedrockSquirrel BedrockSquirrel merged commit c3775b5 into main Nov 29, 2023
15 of 17 checks passed
@BedrockSquirrel BedrockSquirrel deleted the matt/record-l2-contract-addresses branch November 29, 2023 12:38
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