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

Pedro/debug hh deployer #1710

Merged
merged 5 commits into from
Dec 20, 2023
Merged

Pedro/debug hh deployer #1710

merged 5 commits into from
Dec 20, 2023

Conversation

otherview
Copy link
Contributor

Why this change is needed

https://github.com/ten-protocol/ten-internal/issues/2643

Adds a contract-deployer-debug flag that allows to remotely debug the hh contract deployer.

What changes were made as part of this PR

Please provide a high level list of the changes made

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 Dec 19, 2023

Walkthrough

The recent updates involve enhancing the Testnet configuration and deployment features by adding options for a custom Docker image and debugging for contract deployment. The TestnetConfigCLI structure now includes fields to specify a Docker image and enable debugging. These settings are parsed from command-line flags and integrated into the main application flow. Adjustments were made to the contract deployer's configuration and deployment logic to respect these new settings, including conditional port setup based on the debug configuration.

Changes

Files Change Summaries
testnet/launcher/cmd/cli.go, testnet/launcher/cmd/cli_flags.go, testnet/launcher/cmd/main.go, testnet/launcher/config.go Added contractDeployerDockerImage and contractDeployerDebug to TestnetConfigCLI; introduced corresponding CLI flags; updated main function and Config struct; repositioned isSGXEnabled field.
testnet/launcher/docker.go Made deployL1Contracts a Testnet method; updated Start method to use new t.cfg fields.
testnet/launcher/l1contractdeployer/config.go, testnet/launcher/l1contractdeployer/docker.go, testnet/launcher/l2contractdeployer/config.go Included debugEnabled in Config structs; added WithDebugEnabled method; updated contract deployment logic.
testnet/launcher/l1contractdeployer/docker.go, testnet/launcher/l2contractdeployer/docker.go Reordered and added elements to cmds based on debugEnabled; introduced ports slice for debug port configuration; updated docker.StartNewContainer calls.
contracts/deployment_scripts/core/001_deploy_management_contract.ts Minor formatting change in console log statement.

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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

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 98e0913 and 7822d68.
Files selected for processing (8)
  • testnet/launcher/cmd/cli.go (2 hunks)
  • testnet/launcher/cmd/cli_flags.go (2 hunks)
  • testnet/launcher/cmd/main.go (1 hunks)
  • testnet/launcher/config.go (2 hunks)
  • testnet/launcher/docker.go (3 hunks)
  • testnet/launcher/l1contractdeployer/config.go (2 hunks)
  • testnet/launcher/l1contractdeployer/docker.go (2 hunks)
  • testnet/launcher/l2contractdeployer/config.go (2 hunks)
Additional comments: 14
testnet/launcher/cmd/cli.go (2)
  • 10-15: The addition of contractDeployerDockerImage and contractDeployerDebug fields to the TestnetConfigCLI struct aligns with the PR's objective to support remote debugging for the contract deployer. This change is well-structured and follows the existing pattern of the codebase.

  • 27-37: The parsing of the new CLI flags contractDeployerDockerImage and contractDeployerDebug is consistent with the existing flag parsing logic. However, ensure that the default values provided for these flags are appropriate and that they are documented in the same way as other flags.

testnet/launcher/cmd/cli_flags.go (2)
  • 9-11: The new flags contractDeployerDockerImageFlag and contractDeployerDebugFlag are added correctly. It's important to ensure that these flags are documented and communicated to the developers who will use this CLI, as they are part of the new feature.

  • 22-23: The descriptions for the new flags are clear and concise. It's good practice to keep the flag descriptions helpful for the end-users, as seen here.

testnet/launcher/cmd/main.go (1)
  • 20-21: The integration of the new contract deployer settings into the main function is done correctly. The use of option functions to pass configuration is a clean approach that keeps the code modular and easy to read.
testnet/launcher/config.go (2)
  • 14-17: The restructuring of the Config struct to include the new contractDeployerDockerImage and contractDeployerDebug fields, as well as the repositioning of isSGXEnabled, is logical and maintains the clarity of the configuration's purpose.

  • 60-70: The addition of WithContractDeployerDockerImage and WithContractDeployerDebug functions follows the established pattern for configuration option functions. This is a good use of the options pattern for dependency injection.

testnet/launcher/docker.go (2)
  • 33-39: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [36-43]

The conditional logic to append debug commands and ports based on the debugEnabled flag is implemented correctly. It's important to ensure that the debug port (9229) does not conflict with other services and that it is properly secured.

  • 187-193: The method deployL1Contracts now correctly references the configuration from the Testnet instance. This change encapsulates the deployment logic within the Testnet type, which is a good practice for maintainability.
testnet/launcher/l1contractdeployer/config.go (2)
  • 8-11: The addition of the debugEnabled field to the Config struct is consistent with the feature requirements. It's important to validate that this new configuration is handled correctly wherever the Config is used.

  • 42-46: The WithDebugEnabled function is added to allow the configuration of the debug mode. This is a straightforward and clean implementation of the option pattern.

testnet/launcher/l1contractdeployer/docker.go (1)
  • 34-43: The changes to the command slice to include the node inspector for debugging are correct. However, it's crucial to ensure that exposing the debug port does not introduce security vulnerabilities, especially if the deployer runs in a shared or production-like environment.
testnet/launcher/l2contractdeployer/config.go (2)
  • 19-19: The debugEnabled field is added to the Config struct to support the new debugging feature. This change is consistent with the rest of the codebase and the feature's requirements.

  • 100-104: The WithDebugEnabled function is implemented correctly, following the established pattern for configuration options. This addition will facilitate the enabling of debugging for the contract deployer.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7822d68 and 85b72c2.
Files selected for processing (2)
  • contracts/deployment_scripts/core/001_deploy_management_contract.ts (1 hunks)
  • testnet/launcher/l1contractdeployer/docker.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/deployment_scripts/core/001_deploy_management_contract.ts
Additional comments: 3
testnet/launcher/l1contractdeployer/docker.go (3)
  • 61-64: The changes to the StartNewContainer function call correctly include the ports slice to handle the new debugging feature.

  • 82-90: The logic to adjust the tailSize based on the debug flag is correct and ensures that the correct amount of log output is retrieved.

  • 113-116: The conditional logic to remove debugger lines from the output when debugging is enabled is correct and ensures that only relevant lines are processed.

Comment on lines +34 to +44
cmds := []string{"npx"}
var ports []int

// inspect stops operation until debugger is hooked on port 9229 if debug is enabled
if n.cfg.debugEnabled {
cmds = append(cmds, "--node-options=\"--inspect-brk=0.0.0.0:9229\"")
ports = append(ports, 9229)
}

cmds = append(cmds, "hardhat", "deploy", "--network", "layer1")

Copy link

Choose a reason for hiding this comment

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

The addition of debug options to the cmds slice and the ports slice is correct and follows the intended feature implementation. However, the debug option string is not properly escaped, which could lead to command execution issues.

- cmds = append(cmds, "--node-options=\"--inspect-brk=0.0.0.0:9229\"")
+ cmds = append(cmds, "--node-options=--inspect-brk=0.0.0.0:9229")

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
cmds := []string{"npx"}
var ports []int
// inspect stops operation until debugger is hooked on port 9229 if debug is enabled
if n.cfg.debugEnabled {
cmds = append(cmds, "--node-options=\"--inspect-brk=0.0.0.0:9229\"")
ports = append(ports, 9229)
}
cmds = append(cmds, "hardhat", "deploy", "--network", "layer1")
cmds := []string{"npx"}
var ports []int
// inspect stops operation until debugger is hooked on port 9229 if debug is enabled
if n.cfg.debugEnabled {
cmds = append(cmds, "--node-options=--inspect-brk=0.0.0.0:9229")
ports = append(ports, 9229)
}
cmds = append(cmds, "hardhat", "deploy", "--network", "layer1")

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 85b72c2 and ca36858.
Files selected for processing (1)
  • testnet/launcher/l2contractdeployer/docker.go (2 hunks)
Additional comments: 3
testnet/launcher/l2contractdeployer/docker.go (3)
  • 82-85: The docker.StartNewContainer function is called with the new ports parameter. Ensure that the StartNewContainer function has been updated accordingly to handle this new parameter without causing any regressions.
Verification successful

The StartNewContainer function has been successfully located in the go/common/docker/docker.go file, and it does indeed include a ports []int parameter in its signature. This confirms that the function is designed to handle the ports parameter, which aligns with the changes made in the docker.go file of the l2contractdeployer directory.

Final response:

The StartNewContainer function in the docker.go file has been verified to accept a ports []int parameter, which is consistent with the changes made in the l2contractdeployer directory. No regressions related to this parameter addition should be expected based on this information.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the StartNewContainer function handles the new 'ports' parameter correctly.
ast-grep --lang go --pattern $'func StartNewContainer($_, $_, $_, ports []int, $_, $_, $_) {
  $$$
}'

Length of output: 102



Script:

#!/bin/bash
# Search for the StartNewContainer function to verify its parameters.
ast-grep --lang go --pattern $'func StartNewContainer($$$) {
  $$$
}'

Length of output: 70



Script:

#!/bin/bash
# Use ripgrep to search for the StartNewContainer function in the codebase.
rg "func StartNewContainer"

Length of output: 196

* 27-43: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [27-85]

The Start function has been refactored to include debugging logic. Ensure that the introduction of the debugging feature does not introduce any security concerns, such as exposing sensitive information through the logs or opening unnecessary network ports.

  • 27-43: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [27-85]

The Start function sets n.containerID after starting the container. Ensure that this container ID is used appropriately throughout the codebase and that there are no race conditions or synchronization issues when accessing this field.

Comment on lines 27 to 43
func (n *ContractDeployer) Start() error {
fmt.Printf("Starting L2 contract deployer with config: \n%s\n\n", litter.Sdump(*n.cfg))

cmds := []string{
"npx", "hardhat", "obscuro:deploy",
"--network", "layer2",
cmds := []string{"npx"}
var ports []int

// inspect stops operation until debugger is hooked on port 9229 if debug is enabled
if n.cfg.debugEnabled {
cmds = append(cmds, "--node-options=\"--inspect-brk=0.0.0.0:9229\"")
ports = append(ports, 9229)
}

cmds = append(cmds, "hardhat", "obscuro:deploy", "--network", "layer2")

envs := map[string]string{
"PREFUND_FAUCET_AMOUNT": n.cfg.faucetPrefundAmount,
"MGMT_CONTRACT_ADDRESS": n.cfg.managementContractAddress,
Copy link

Choose a reason for hiding this comment

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

The Start function has been updated to conditionally append command-line arguments and ports for debugging. This is a good use of conditional logic to enable optional features. However, the debug port 9229 is hardcoded. Consider defining it as a constant or configuration parameter to avoid magic numbers and facilitate changes if needed in the future.


Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [27-85]

The Start function prints the configuration and starts the container. However, there is no error handling for the configuration print step. If printing the configuration is critical, consider adding error handling or logging for this step.


Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [27-85]

The Start function's error handling for docker.StartNewContainer is straightforward, but it might be beneficial to add more context to the error before returning it, such as what was being attempted when the error occurred.

@otherview otherview merged commit 6389ace into main Dec 20, 2023
@otherview otherview deleted the pedro/debug_hh_deployer branch December 20, 2023 15:30
This was referenced Dec 20, 2023
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