From 38110e573d6c664d4b38693f0d54a69e7a7f83e2 Mon Sep 17 00:00:00 2001 From: Matt Curtis Date: Mon, 20 Nov 2023 12:13:27 +0000 Subject: [PATCH 1/2] Contract deployment: store important addresses --- .../workflows/manual-deploy-testnet-l2.yml | 1 + .../bridge/001_deploy_bridge.ts | 10 +++++++ .../001_deploy_cross_chain_messenger.ts | 14 ++++++++-- .../launcher/l2contractdeployer/cmd/cli.go | 3 +++ .../l2contractdeployer/cmd/cli_flags.go | 2 ++ .../launcher/l2contractdeployer/cmd/main.go | 1 + testnet/launcher/l2contractdeployer/config.go | 27 ++++++++++++------- testnet/launcher/l2contractdeployer/docker.go | 5 ++-- 8 files changed, 49 insertions(+), 14 deletions(-) diff --git a/.github/workflows/manual-deploy-testnet-l2.yml b/.github/workflows/manual-deploy-testnet-l2.yml index e321709a3a..83d3107526 100644 --- a/.github/workflows/manual-deploy-testnet-l2.yml +++ b/.github/workflows/manual-deploy-testnet-l2.yml @@ -309,6 +309,7 @@ jobs: -l2_private_key=8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b \ -l2_hoc_private_key=6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682 \ -l2_poc_private_key=4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8 \ + -management_contract_addr=${{ needs.build.outputs.MGMT_CONTRACT_ADDR }} \ -message_bus_contract_addr=${{ needs.build.outputs.MSG_BUS_CONTRACT_ADDR }} \ -docker_image=${{ vars.L2_HARDHATDEPLOYER_DOCKER_BUILD_TAG }} \ -faucet_funds=${{ vars.FAUCET_INITIAL_FUNDS }} diff --git a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts index c6e4caa21a..c9df0e084f 100644 --- a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts +++ b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts @@ -12,6 +12,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { deployments, getNamedAccounts } = hre; + const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! // L2 address of a prefunded deployer account to be used in smart contracts const accountsL2 = await getNamedAccounts(); @@ -27,6 +28,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { log: true, }); + // get management contract and write the L1 bridge address to it + const mgmtContract = (await hre.ethers.getContractFactory('ManagementContract')).attach(mgmtContractAddress) + const tx = await mgmtContract.SetImportantContractAddress("L1Bridge", layer1BridgeDeployment.address); + const receipt = await tx.wait(); + if (receipt.status !== 1) { + console.log("Failed to set L1BridgeAddress in management contract"); + } + console.log(`L1BridgeAddress=${layer1BridgeDeployment.address}`) + // We get the Cross chain messenger deployment on the layer 2 network. const messengerL2 = await deployments.get("CrossChainMessenger"); diff --git a/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts b/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts index ae7c6562a9..cb55e27665 100644 --- a/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts +++ b/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts @@ -13,16 +13,26 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { deployer } = await hre.companionNetworks.layer1.getNamedAccounts(); - // Read the message bus address from the management contract deployment. + // Use the contract addresses from the management contract deployment. + const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! const messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!! console.log(`Message Bus address ${messageBusAddress}`); // Setup the cross chain messenger and point it to the message bus from the management contract to be used for validation - await deployments.deploy('CrossChainMessenger', { + const crossChainDeployment = await deployments.deploy('CrossChainMessenger', { from: deployer, args: [ messageBusAddress ], log: true, }); + + // get management contract and write the cross chain messenger address to it + const mgmtContract = (await hre.ethers.getContractFactory('ManagementContract')).attach(mgmtContractAddress) + const tx = await mgmtContract.SetImportantContractAddress("L1CrossChainMessenger", crossChainDeployment.address); + const receipt = await tx.wait(); + if (receipt.status !== 1) { + console.log("Failed to set L1CrossChainMessenger in management contract"); + } + console.log(`L1CrossChainMessenger=${crossChainDeployment.address}`) }; export default func; diff --git a/testnet/launcher/l2contractdeployer/cmd/cli.go b/testnet/launcher/l2contractdeployer/cmd/cli.go index 71486b73d7..74b1314c8e 100644 --- a/testnet/launcher/l2contractdeployer/cmd/cli.go +++ b/testnet/launcher/l2contractdeployer/cmd/cli.go @@ -11,6 +11,7 @@ type L2ContractDeployerConfigCLI struct { dockerImage string l2Host string l2WSPort int + managementContractAddr string messageBusContractAddr string l2PrivateKey string l2HOCPrivateKey string @@ -28,6 +29,7 @@ func ParseConfigCLI() *L2ContractDeployerConfigCLI { dockerImage := flag.String(dockerImageFlag, "testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest", flagUsageMap[dockerImageFlag]) l2Host := flag.String(l2HostFlag, "", flagUsageMap[l2HostFlag]) l2WSPort := flag.Int(l2WSPortFlag, 9000, flagUsageMap[l2WSPortFlag]) + managementContractAddr := flag.String(managementContractAddrFlag, "", flagUsageMap[managementContractAddrFlag]) messageBusContractAddr := flag.String(messageBusContractAddrFlag, "", flagUsageMap[messageBusContractAddrFlag]) l2PrivateKey := flag.String(l2privateKeyFlag, "", flagUsageMap[l2privateKeyFlag]) l2HOCPrivateKey := flag.String(l2HOCPrivateKeyFlag, "", flagUsageMap[l2HOCPrivateKeyFlag]) @@ -41,6 +43,7 @@ func ParseConfigCLI() *L2ContractDeployerConfigCLI { cfg.dockerImage = *dockerImage cfg.l2Host = *l2Host cfg.l2WSPort = *l2WSPort + cfg.managementContractAddr = *managementContractAddr cfg.messageBusContractAddr = *messageBusContractAddr cfg.l2PrivateKey = *l2PrivateKey cfg.l2HOCPrivateKey = *l2POCPrivateKey diff --git a/testnet/launcher/l2contractdeployer/cmd/cli_flags.go b/testnet/launcher/l2contractdeployer/cmd/cli_flags.go index d5286cf2bb..3067229454 100644 --- a/testnet/launcher/l2contractdeployer/cmd/cli_flags.go +++ b/testnet/launcher/l2contractdeployer/cmd/cli_flags.go @@ -7,6 +7,7 @@ const ( dockerImageFlag = "docker_image" l2HostFlag = "l2_host" l2WSPortFlag = "l2_ws_port" + managementContractAddrFlag = "management_contract_addr" messageBusContractAddrFlag = "message_bus_contract_addr" l2privateKeyFlag = "l2_private_key" l2HOCPrivateKeyFlag = "l2_hoc_private_key" @@ -23,6 +24,7 @@ func getFlagUsageMap() map[string]string { dockerImageFlag: "Docker image to run", l2HostFlag: "Layer 2 network host addr", l2WSPortFlag: "Layer 2 network WebSocket port", + managementContractAddrFlag: "Management contract address", messageBusContractAddrFlag: "Message bus contract address", l2privateKeyFlag: "Layer 2 private key", l2HOCPrivateKeyFlag: "Layer 2 HOC contract private key", diff --git a/testnet/launcher/l2contractdeployer/cmd/main.go b/testnet/launcher/l2contractdeployer/cmd/main.go index 7c926d155e..781857b7fb 100644 --- a/testnet/launcher/l2contractdeployer/cmd/main.go +++ b/testnet/launcher/l2contractdeployer/cmd/main.go @@ -16,6 +16,7 @@ func main() { l2cd.WithL2Host(cliConfig.l2Host), // "host" l2cd.WithL2WSPort(cliConfig.l2WSPort), // 81 l2cd.WithL1PrivateKey(cliConfig.privateKey), // "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb" + l2cd.WithManagementContractAddress(cliConfig.managementContractAddr), // l2cd.WithMessageBusContractAddress(cliConfig.messageBusContractAddr), // "0xFD03804faCA2538F4633B3EBdfEfc38adafa259B" l2cd.WithL2PrivateKey(cliConfig.l2PrivateKey), // "8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b" l2cd.WithHocPKString(cliConfig.l2HOCPrivateKey), // "6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682"), diff --git a/testnet/launcher/l2contractdeployer/config.go b/testnet/launcher/l2contractdeployer/config.go index fe26b5199e..044081517b 100644 --- a/testnet/launcher/l2contractdeployer/config.go +++ b/testnet/launcher/l2contractdeployer/config.go @@ -5,16 +5,17 @@ type Option = func(c *Config) // Config holds the properties that configure the package type Config struct { - l1HTTPURL string - l1privateKey string - l2Port int - l2Host string - l2PrivateKey string - hocPKString string - pocPKString string - messageBusAddress string - dockerImage string - faucetPrefundAmount string + l1HTTPURL string + l1privateKey string + l2Port int + l2Host string + l2PrivateKey string + hocPKString string + pocPKString string + managementContractAddress string + messageBusAddress string + dockerImage string + faucetPrefundAmount string } func NewContractDeployerConfig(opts ...Option) *Config { @@ -53,6 +54,12 @@ func WithL2Host(s string) Option { } } +func WithManagementContractAddress(s string) Option { + return func(c *Config) { + c.managementContractAddress = s + } +} + func WithMessageBusContractAddress(s string) Option { return func(c *Config) { c.messageBusAddress = s diff --git a/testnet/launcher/l2contractdeployer/docker.go b/testnet/launcher/l2contractdeployer/docker.go index 43963bd150..af9ecc3c37 100644 --- a/testnet/launcher/l2contractdeployer/docker.go +++ b/testnet/launcher/l2contractdeployer/docker.go @@ -33,8 +33,9 @@ func (n *ContractDeployer) Start() error { } envs := map[string]string{ - "PREFUND_FAUCET_AMOUNT": n.cfg.faucetPrefundAmount, - "MESSAGE_BUS_ADDRESS": n.cfg.messageBusAddress, + "PREFUND_FAUCET_AMOUNT": n.cfg.faucetPrefundAmount, + "MANAGEMENT_CONTRACT_ADDRESS": n.cfg.managementContractAddress, + "MESSAGE_BUS_ADDRESS": n.cfg.messageBusAddress, "NETWORK_JSON": fmt.Sprintf(` { "layer1" : { From d50a1fda835fd28b29a9bf0cab05e22a163894cf Mon Sep 17 00:00:00 2001 From: Matt Curtis Date: Thu, 23 Nov 2023 10:30:52 +0000 Subject: [PATCH 2/2] fix env var name --- testnet/launcher/l2contractdeployer/docker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testnet/launcher/l2contractdeployer/docker.go b/testnet/launcher/l2contractdeployer/docker.go index af9ecc3c37..e7532de5a6 100644 --- a/testnet/launcher/l2contractdeployer/docker.go +++ b/testnet/launcher/l2contractdeployer/docker.go @@ -33,9 +33,9 @@ func (n *ContractDeployer) Start() error { } envs := map[string]string{ - "PREFUND_FAUCET_AMOUNT": n.cfg.faucetPrefundAmount, - "MANAGEMENT_CONTRACT_ADDRESS": n.cfg.managementContractAddress, - "MESSAGE_BUS_ADDRESS": n.cfg.messageBusAddress, + "PREFUND_FAUCET_AMOUNT": n.cfg.faucetPrefundAmount, + "MGMT_CONTRACT_ADDRESS": n.cfg.managementContractAddress, + "MESSAGE_BUS_ADDRESS": n.cfg.messageBusAddress, "NETWORK_JSON": fmt.Sprintf(` { "layer1" : {