Skip to content

Commit

Permalink
Pedro/debug hh deployer (#1710)
Browse files Browse the repository at this point in the history
* Debug HH contract deployer

* remove debugger lines

* fix contract step

* debug for l2 deployer
  • Loading branch information
otherview authored Dec 20, 2023
1 parent 5c36933 commit 6389ace
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// This is required in CI/CD - look at testnet-deploy-contracts.sh for more information.
// depends on grep -e MessageBusAddress and a positional cut of the address
console.log(`MessageBusAddress= ${busAddress}`);
console.log(`L1Start=${mgmtContractDeployment.receipt.blockHash}`)
console.log(`L1Start= ${mgmtContractDeployment.receipt.blockHash}`)
};

export default func;
Expand Down
6 changes: 6 additions & 0 deletions testnet/launcher/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type TestnetConfigCLI struct {
validatorEnclaveDebug bool
sequencerEnclaveDockerImage string
sequencerEnclaveDebug bool
contractDeployerDockerImage string
contractDeployerDebug bool
isSGXEnabled bool
}

Expand All @@ -22,13 +24,17 @@ func ParseConfigCLI() *TestnetConfigCLI {
validatorEnclaveDebug := flag.Bool(validatorEnclaveDebugFlag, false, flagUsageMap[validatorEnclaveDebugFlag])
sequencerEnclaveDockerImage := flag.String(sequencerEnclaveDockerImageFlag, "testnetobscuronet.azurecr.io/obscuronet/enclave:latest", flagUsageMap[sequencerEnclaveDockerImageFlag])
sequencerEnclaveDebug := flag.Bool(sequencerEnclaveDebugFlag, false, flagUsageMap[sequencerEnclaveDebugFlag])
contractDeployerDockerImage := flag.String(contractDeployerDockerImageFlag, "testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest", flagUsageMap[contractDeployerDockerImageFlag])
contractDeployerDebug := flag.Bool(contractDeployerDebugFlag, false, flagUsageMap[contractDeployerDebugFlag])
isSGXEnabled := flag.Bool(isSGXEnabledFlag, false, flagUsageMap[isSGXEnabledFlag])
flag.Parse()

cfg.validatorEnclaveDockerImage = *validatorEnclaveDockerImage
cfg.sequencerEnclaveDockerImage = *sequencerEnclaveDockerImage
cfg.validatorEnclaveDebug = *validatorEnclaveDebug
cfg.sequencerEnclaveDebug = *sequencerEnclaveDebug
cfg.contractDeployerDebug = *contractDeployerDebug
cfg.contractDeployerDockerImage = *contractDeployerDockerImage
cfg.isSGXEnabled = *isSGXEnabled

return cfg
Expand Down
4 changes: 4 additions & 0 deletions testnet/launcher/cmd/cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const (
validatorEnclaveDebugFlag = "validator-enclave-debug"
sequencerEnclaveDockerImageFlag = "sequencer-enclave-docker-image"
sequencerEnclaveDebugFlag = "sequencer-enclave-debug"
contractDeployerDockerImageFlag = "contract-deployer-docker-image"
contractDeployerDebugFlag = "contract-deployer-debug"
isSGXEnabledFlag = "is-sgx-enabled"
)

Expand All @@ -17,6 +19,8 @@ func getFlagUsageMap() map[string]string {
validatorEnclaveDebugFlag: "Enables the use of DLV to debug the validator enclave",
sequencerEnclaveDockerImageFlag: "The docker image that runs the sequencer enclave",
sequencerEnclaveDebugFlag: "Enables the use of DLV to debug the sequencer enclave",
contractDeployerDockerImageFlag: "The docker image that runs the contract deployer",
contractDeployerDebugFlag: "Enables the use of node inspector to debug the contract deployer",
isSGXEnabledFlag: "Enables the SGX usage",
}
}
2 changes: 2 additions & 0 deletions testnet/launcher/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func main() {
launcher.WithValidatorEnclaveDebug(cliConfig.validatorEnclaveDebug),
launcher.WithSequencerEnclaveDockerImage(cliConfig.sequencerEnclaveDockerImage),
launcher.WithSequencerEnclaveDebug(cliConfig.sequencerEnclaveDebug),
launcher.WithContractDeployerDebug(cliConfig.contractDeployerDebug),
launcher.WithContractDeployerDockerImage(cliConfig.contractDeployerDockerImage),
launcher.WithSGXEnabled(cliConfig.isSGXEnabled),
),
)
Expand Down
18 changes: 17 additions & 1 deletion testnet/launcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ type Config struct {

validatorEnclaveDockerImage string
validatorEnclaveDebug bool
isSGXEnabled bool

contractDeployerDockerImage string
contractDeployerDebug bool

isSGXEnabled bool
}

func NewTestnetConfig(opts ...Option) *Config {
Expand Down Expand Up @@ -52,3 +56,15 @@ func WithSGXEnabled(b bool) Option {
c.isSGXEnabled = b
}
}

func WithContractDeployerDockerImage(s string) Option {
return func(c *Config) {
c.contractDeployerDockerImage = s
}
}

func WithContractDeployerDebug(b bool) Option {
return func(c *Config) {
c.contractDeployerDebug = b
}
}
10 changes: 6 additions & 4 deletions testnet/launcher/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (t *Testnet) Start() error {
return fmt.Errorf("unable to start eth2network - %w", err)
}

networkConfig, err := deployL1Contracts()
networkConfig, err := t.deployL1Contracts()
if err != nil {
return fmt.Errorf("unable to deploy l1 contracts - %w", err)
}
Expand Down Expand Up @@ -129,7 +129,8 @@ func (t *Testnet) Start() error {
l2cd.WithL2PrivateKey("8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b"),
l2cd.WithHocPKString("6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682"),
l2cd.WithPocPKString("4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8"),
l2cd.WithDockerImage("testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest"),
l2cd.WithDockerImage(t.cfg.contractDeployerDockerImage),
l2cd.WithDebugEnabled(t.cfg.contractDeployerDebug),
l2cd.WithFaucetFunds("10000"),
),
)
Expand Down Expand Up @@ -183,12 +184,13 @@ func startEth2Network() error {
return nil
}

func deployL1Contracts() (*node.NetworkConfig, error) {
func (t *Testnet) deployL1Contracts() (*node.NetworkConfig, error) {
l1ContractDeployer, err := l1cd.NewDockerContractDeployer(
l1cd.NewContractDeployerConfig(
l1cd.WithL1HTTPURL("http://eth2network:8025"),
l1cd.WithPrivateKey("f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb"),
l1cd.WithDockerImage("testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest"),
l1cd.WithDockerImage(t.cfg.contractDeployerDockerImage),
l1cd.WithDebugEnabled(t.cfg.contractDeployerDebug),
),
)
if err != nil {
Expand Down
13 changes: 10 additions & 3 deletions testnet/launcher/l1contractdeployer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ type Option = func(c *Config)

// Config holds the properties that configure the package
type Config struct {
l1HTTPURL string
privateKey string
dockerImage string
l1HTTPURL string
privateKey string
dockerImage string
debugEnabled bool
}

func NewContractDeployerConfig(opts ...Option) *Config {
Expand Down Expand Up @@ -37,3 +38,9 @@ func WithDockerImage(s string) Option {
c.dockerImage = s
}
}

func WithDebugEnabled(b bool) Option {
return func(c *Config) {
c.debugEnabled = b
}
}
28 changes: 22 additions & 6 deletions testnet/launcher/l1contractdeployer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ func NewDockerContractDeployer(cfg *Config) (*ContractDeployer, error) {
func (n *ContractDeployer) Start() error {
fmt.Printf("Starting L1 contract deployer with config: \n%s\n\n", litter.Sdump(*n.cfg))

cmds := []string{
"npx", "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")

envs := map[string]string{
"NETWORK_JSON": fmt.Sprintf(`
{
Expand All @@ -52,7 +58,7 @@ func (n *ContractDeployer) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.privateKey),
}

containerID, err := docker.StartNewContainer("hh-l1-deployer", n.cfg.dockerImage, cmds, nil, envs, nil, nil)
containerID, err := docker.StartNewContainer("hh-l1-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil)
if err != nil {
return err
}
Expand All @@ -73,10 +79,15 @@ func (n *ContractDeployer) RetrieveL1ContractAddresses() (*node.NetworkConfig, e
return nil, err
}

tailSize := "3"
if n.cfg.debugEnabled {
tailSize = "4"
}

logsOptions := types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Tail: "3",
Tail: tailSize,
}

// Read the container logs
Expand All @@ -93,12 +104,17 @@ func (n *ContractDeployer) RetrieveL1ContractAddresses() (*node.NetworkConfig, e
return nil, err
}

// Get the last three lines
// Get the last lines
output := buf.String()
fmt.Printf("L2 Deployer output %s\n", output)

lines := strings.Split(output, "\n")

if n.cfg.debugEnabled {
// remove debugger lines
lines = lines[:len(lines)-2]
}

managementAddr, err := findAddress(lines[0])
if err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions testnet/launcher/l2contractdeployer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
messageBusAddress string
dockerImage string
faucetPrefundAmount string
debugEnabled bool
}

func NewContractDeployerConfig(opts ...Option) *Config {
Expand Down Expand Up @@ -95,3 +96,9 @@ func WithFaucetFunds(f string) Option {
c.faucetPrefundAmount = f
}
}

func WithDebugEnabled(b bool) Option {
return func(c *Config) {
c.debugEnabled = b
}
}
14 changes: 10 additions & 4 deletions testnet/launcher/l2contractdeployer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ func NewDockerContractDeployer(cfg *Config) (*ContractDeployer, error) {
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,
Expand Down Expand Up @@ -73,7 +79,7 @@ func (n *ContractDeployer) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.l1privateKey, n.cfg.l2Host, n.cfg.l2Port, n.cfg.l2PrivateKey, n.cfg.hocPKString, n.cfg.pocPKString),
}

containerID, err := docker.StartNewContainer("hh-l2-deployer", n.cfg.dockerImage, cmds, nil, envs, nil, nil)
containerID, err := docker.StartNewContainer("hh-l2-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil)
if err != nil {
return err
}
Expand Down

0 comments on commit 6389ace

Please sign in to comment.