From b7b4e3e30a7ffe40797cf2869f5a47fbf634213d Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Wed, 13 Sep 2023 07:45:18 +0100 Subject: [PATCH] Change config to use RPC urls instead of host and port (#1512) --- .../workflows/manual-deploy-testnet-l2.yml | 18 ++++--- .../workflows/manual-upgrade-testnet-l2.yml | 12 ++--- go/config/host_config.go | 18 +++---- go/ethadapter/geth_rpc_client.go | 53 +++++++------------ go/host/container/cli.go | 12 ++--- go/host/container/cli_flags.go | 6 +-- go/host/container/host_container.go | 2 +- go/host/container/test.toml | 3 +- go/node/cmd/cli.go | 9 ++-- go/node/cmd/cli_flags.go | 6 +-- go/node/cmd/main.go | 3 +- go/node/config.go | 16 ++---- go/node/docker_node.go | 3 +- integration/networktest/env/network_setup.go | 4 +- integration/networktest/env/testnet.go | 10 ++-- .../helpful/spin_up_local_network_test.go | 2 +- integration/noderunner/noderunner_test.go | 7 ++- integration/simulation/devnetwork/live_l1.go | 2 +- .../simulation/network/obscuro_node_utils.go | 8 +-- integration/simulation/network/socket.go | 13 +++-- testnet/launcher/docker.go | 16 +++--- .../launcher/l1contractdeployer/cmd/cli.go | 9 ++-- .../l1contractdeployer/cmd/cli_flags.go | 6 +-- .../launcher/l1contractdeployer/cmd/main.go | 3 +- testnet/launcher/l1contractdeployer/config.go | 13 ++--- testnet/launcher/l1contractdeployer/docker.go | 4 +- .../launcher/l2contractdeployer/cmd/cli.go | 9 ++-- .../l2contractdeployer/cmd/cli_flags.go | 6 +-- .../launcher/l2contractdeployer/cmd/main.go | 3 +- testnet/launcher/l2contractdeployer/config.go | 13 ++--- testnet/launcher/l2contractdeployer/docker.go | 4 +- 31 files changed, 112 insertions(+), 181 deletions(-) diff --git a/.github/workflows/manual-deploy-testnet-l2.yml b/.github/workflows/manual-deploy-testnet-l2.yml index a62874702c..8fc377d263 100644 --- a/.github/workflows/manual-deploy-testnet-l2.yml +++ b/.github/workflows/manual-deploy-testnet-l2.yml @@ -38,7 +38,8 @@ jobs: RESOURCE_TAG_NAME: ${{ steps.outputVars.outputs.RESOURCE_TAG_NAME }} RESOURCE_STARTING_NAME: ${{ steps.outputVars.outputs.RESOURCE_STARTING_NAME }} RESOURCE_TESTNET_NAME: ${{ steps.outputVars.outputs.RESOURCE_TESTNET_NAME }} - L1_HOST: ${{ steps.outputVars.outputs.L1_HOST }} + L1_WS_URL: ${{ steps.outputVars.outputs.L1_WS_URL }} + L1_HTTP_URL: ${{ steps.outputVars.outputs.L1_HTTP_URL }} steps: @@ -62,7 +63,8 @@ jobs: echo "RESOURCE_TAG_NAME=testnetlatest" >> $GITHUB_ENV echo "RESOURCE_STARTING_NAME=T" >> $GITHUB_ENV echo "RESOURCE_TESTNET_NAME=testnet" >> $GITHUB_ENV - echo "L1_HOST=testnet-eth2network.uksouth.cloudapp.azure.com" >> $GITHUB_ENV + echo "L1_WS_URL=ws://testnet-eth2network.uksouth.cloudapp.azure.com:9000" >> $GITHUB_ENV + echo "L1_HTTP_URL=http://testnet-eth2network.uksouth.cloudapp.azure.com:8025" >> $GITHUB_ENV - name: 'Sets env vars for dev-testnet' if: ${{ (github.event.inputs.testnet_type == 'dev-testnet') }} @@ -73,7 +75,8 @@ jobs: echo "RESOURCE_TAG_NAME=devtestnetlatest" >> $GITHUB_ENV echo "RESOURCE_STARTING_NAME=D" >> $GITHUB_ENV echo "RESOURCE_TESTNET_NAME=devtestnet" >> $GITHUB_ENV - echo "L1_HOST=dev-testnet-eth2network.uksouth.cloudapp.azure.com" >> $GITHUB_ENV + echo "L1_WS_URL=ws://dev-testnet-eth2network.uksouth.cloudapp.azure.com:9000" >> $GITHUB_ENV + echo "L1_HTTP_URL=http://dev-testnet-eth2network.uksouth.cloudapp.azure.com:8025" >> $GITHUB_ENV - name: 'Output env vars' id: outputVars @@ -84,7 +87,8 @@ jobs: echo "RESOURCE_TAG_NAME=${{env.RESOURCE_TAG_NAME}}" >> $GITHUB_OUTPUT echo "RESOURCE_STARTING_NAME=${{env.RESOURCE_STARTING_NAME}}" >> $GITHUB_OUTPUT echo "RESOURCE_TESTNET_NAME=${{env.RESOURCE_TESTNET_NAME}}" >> $GITHUB_OUTPUT - echo "L1_HOST=${{env.L1_HOST}}" >> $GITHUB_OUTPUT + echo "L1_WS_URL=${{env.L1_WS_URL}}" >> $GITHUB_OUTPUT + echo "L1_HTTP_URL=${{env.L1_HTTP_URL}}" >> $GITHUB_OUTPUT - name: 'Login to Azure docker registry' uses: azure/docker-login@v1 @@ -107,7 +111,7 @@ jobs: shell: bash run: | go run ./testnet/launcher/l1contractdeployer/cmd \ - -l1_host=${{ env.L1_HOST }} \ + -l1_ws_url=${{ env.L1_HTTP_URL }} \ -private_key=${{ secrets.GETHNETWORK_PREFUNDED_PKSTR_WORKER }} \ -docker_image=${{env.L2_HARDHATDEPLOYER_DOCKER_BUILD_TAG}} \ -contracts_env_file=./testnet/.env @@ -252,7 +256,7 @@ jobs: -node_type=${{ matrix.node_type }} \ -is_sgx_enabled=true \ -host_id=${{ secrets[matrix.node_pk_addr] }} \ - -l1_host=${{needs.build.outputs.L1_HOST}} \ + -l1_ws_url=${{needs.build.outputs.L1_WS_URL}} \ -management_contract_addr=${{needs.build.outputs.MGMT_CONTRACT_ADDR}} \ -message_bus_contract_addr=${{needs.build.outputs.MSG_BUS_CONTRACT_ADDR}} \ -l1_start=${{needs.build.outputs.L1_START_HASH}} \ @@ -322,7 +326,7 @@ jobs: run: | go run ./testnet/launcher/l2contractdeployer/cmd \ -l2_host=obscuronode-0-${{needs.build.outputs.RESOURCE_TESTNET_NAME}}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com \ - -l1_host=${{ needs.build.outputs.L1_HOST }} \ + -l1_ws_url=${{ needs.build.outputs.L1_HTTP_URL }} \ -l2_ws_port=81 \ -private_key=${{ secrets.GETHNETWORK_PREFUNDED_PKSTR_WORKER }} \ -l2_private_key=8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b \ diff --git a/.github/workflows/manual-upgrade-testnet-l2.yml b/.github/workflows/manual-upgrade-testnet-l2.yml index 3119d08a6b..0ece7acfc5 100644 --- a/.github/workflows/manual-upgrade-testnet-l2.yml +++ b/.github/workflows/manual-upgrade-testnet-l2.yml @@ -39,7 +39,7 @@ jobs: RESOURCE_TAG_NAME: ${{ steps.outputVars.outputs.RESOURCE_TAG_NAME }} RESOURCE_STARTING_NAME: ${{ steps.outputVars.outputs.RESOURCE_STARTING_NAME }} RESOURCE_TESTNET_NAME: ${{ steps.outputVars.outputs.RESOURCE_TESTNET_NAME }} - L1_HOST: ${{ steps.outputVars.outputs.L1_HOST }} + L1_WS_URL: ${{ steps.outputVars.outputs.L1_WS_URL }} VM_BUILD_NUMBER: ${{ steps.outputVars.outputs.VM_BUILD_NUMBER }} steps: @@ -62,8 +62,8 @@ jobs: echo "RESOURCE_TAG_NAME=testnetlatest" >> $GITHUB_ENV echo "RESOURCE_STARTING_NAME=T" >> $GITHUB_ENV echo "RESOURCE_TESTNET_NAME=testnet" >> $GITHUB_ENV - echo "L1_HOST=testnet-eth2network.uksouth.cloudapp.azure.com" >> $GITHUB_ENV - + echo "L1_WS_URL=ws://testnet-eth2network.uksouth.cloudapp.azure.com:9000" >> $GITHUB_ENV + - name: 'Sets env vars for dev-testnet' if: ${{ (github.event.inputs.testnet_type == 'dev-testnet') || (github.event_name == 'schedule') }} run: | @@ -72,7 +72,7 @@ jobs: echo "RESOURCE_TAG_NAME=devtestnetlatest" >> $GITHUB_ENV echo "RESOURCE_STARTING_NAME=D" >> $GITHUB_ENV echo "RESOURCE_TESTNET_NAME=devtestnet" >> $GITHUB_ENV - echo "L1_HOST=dev-testnet-eth2network.uksouth.cloudapp.azure.com" >> $GITHUB_ENV + echo "L1_WS_URL=ws://dev-testnet-eth2network.uksouth.cloudapp.azure.com:9000" >> $GITHUB_ENV - name: 'Fetch latest VM hostnames by env tag and extract build number' id: fetch_hostnames @@ -95,7 +95,7 @@ jobs: echo "RESOURCE_TAG_NAME=${{env.RESOURCE_TAG_NAME}}" >> $GITHUB_OUTPUT echo "RESOURCE_STARTING_NAME=${{env.RESOURCE_STARTING_NAME}}" >> $GITHUB_OUTPUT echo "RESOURCE_TESTNET_NAME=${{env.RESOURCE_TESTNET_NAME}}" >> $GITHUB_OUTPUT - echo "L1_HOST=${{env.L1_HOST}}" >> $GITHUB_OUTPUT + echo "L1_WS_URL=${{env.L1_WS_URL}}" >> $GITHUB_OUTPUT echo "VM_BUILD_NUMBER=${{env.VM_BUILD_NUMBER}}" >> $GITHUB_OUTPUT - name: 'Login to Azure docker registry' @@ -174,7 +174,7 @@ jobs: -node_type=${{ matrix.node_type }} \ -is_sgx_enabled=true \ -host_id=${{ secrets[matrix.node_pk_addr] }} \ - -l1_host=${{needs.build.outputs.L1_HOST}} \ + -l1_ws_url=${{needs.build.outputs.L1_WS_URL}} \ -private_key=${{ secrets[matrix.node_pk_str] }} \ -sequencer_id=${{ secrets.GETHNETWORK_PREFUNDED_ADDR_0 }} \ -host_public_p2p_addr=obscuronode-${{ matrix.host_id }}-${{needs.build.outputs.RESOURCE_TESTNET_NAME}}-${{needs.build.outputs.VM_BUILD_NUMBER}}.uksouth.cloudapp.azure.com:10000 \ diff --git a/go/config/host_config.go b/go/config/host_config.go index 3783fce324..c8f0ae47e2 100644 --- a/go/config/host_config.go +++ b/go/config/host_config.go @@ -37,10 +37,8 @@ type HostInputConfig struct { P2PBindAddress string // P2PPublicAddress is the advertised P2P server address P2PPublicAddress string - // The host of the connected L1 node - L1NodeHost string - // The websocket port of the connected L1 node - L1NodeWebsocketPort uint + // L1WebsocketURL is the RPC address for interactions with the L1 + L1WebsocketURL string // Timeout duration for RPC requests to the enclave service EnclaveRPCTimeout time.Duration // Timeout duration for connecting to, and communicating with, the L1 node @@ -106,8 +104,7 @@ func (p HostInputConfig) ToHostConfig() *HostConfig { EnclaveRPCAddress: p.EnclaveRPCAddress, P2PBindAddress: p.P2PBindAddress, P2PPublicAddress: p.P2PPublicAddress, - L1NodeHost: p.L1NodeHost, - L1NodeWebsocketPort: p.L1NodeWebsocketPort, + L1WebsocketURL: p.L1WebsocketURL, EnclaveRPCTimeout: p.EnclaveRPCTimeout, L1RPCTimeout: p.L1RPCTimeout, P2PConnectionTimeout: p.P2PConnectionTimeout, @@ -197,10 +194,8 @@ type HostConfig struct { P2PBindAddress string // P2PPublicAddress is the advertised P2P server address P2PPublicAddress string - // The host of the connected L1 node - L1NodeHost string - // The websocket port of the connected L1 node - L1NodeWebsocketPort uint + // L1WebsocketURL is the RPC address for interactions with the L1 + L1WebsocketURL string // Timeout duration for RPC requests to the enclave service EnclaveRPCTimeout time.Duration // Timeout duration for connecting to, and communicating with, the L1 node @@ -232,8 +227,7 @@ func DefaultHostParsedConfig() *HostInputConfig { EnclaveRPCAddress: "127.0.0.1:11000", P2PBindAddress: "0.0.0.0:10000", P2PPublicAddress: "127.0.0.1:10000", - L1NodeHost: "127.0.0.1", - L1NodeWebsocketPort: 8546, + L1WebsocketURL: "ws://127.0.0.1:8546", EnclaveRPCTimeout: time.Duration(defaultRPCTimeoutSecs) * time.Second, L1RPCTimeout: time.Duration(defaultL1RPCTimeoutSecs) * time.Second, P2PConnectionTimeout: time.Duration(defaultP2PTimeoutSecs) * time.Second, diff --git a/go/ethadapter/geth_rpc_client.go b/go/ethadapter/geth_rpc_client.go index 156d143d9c..40858acdd7 100644 --- a/go/ethadapter/geth_rpc_client.go +++ b/go/ethadapter/geth_rpc_client.go @@ -31,46 +31,33 @@ const ( // gethRPCClient implements the EthClient interface and allows connection to a real ethereum node type gethRPCClient struct { - client *ethclient.Client // the underlying eth rpc client - l2ID gethcommon.Address // the address of the Obscuro node this client is dedicated to - timeout time.Duration // the timeout for connecting to, or communicating with, the L1 node - logger gethlog.Logger - rpcAddress string + client *ethclient.Client // the underlying eth rpc client + l2ID gethcommon.Address // the address of the Obscuro node this client is dedicated to + timeout time.Duration // the timeout for connecting to, or communicating with, the L1 node + logger gethlog.Logger + rpcURL string } -// NewEthClientFromAddress instantiates a new ethadapter.EthClient that connects to an ethereum node -func NewEthClientFromAddress(rpcAddress string, timeout time.Duration, l2ID gethcommon.Address, logger gethlog.Logger) (EthClient, error) { - client, err := connect(rpcAddress, timeout) +// NewEthClientFromURL instantiates a new ethadapter.EthClient that connects to an ethereum node +func NewEthClientFromURL(rpcURL string, timeout time.Duration, l2ID gethcommon.Address, logger gethlog.Logger) (EthClient, error) { + client, err := connect(rpcURL, timeout) if err != nil { - return nil, fmt.Errorf("unable to connect to the eth node (%s) - %w", rpcAddress, err) + return nil, fmt.Errorf("unable to connect to the eth node (%s) - %w", rpcURL, err) } - logger.Trace(fmt.Sprintf("Initialized eth node connection - addr: %s", rpcAddress)) + logger.Trace(fmt.Sprintf("Initialized eth node connection - addr: %s", rpcURL)) return &gethRPCClient{ - client: client, - l2ID: l2ID, - timeout: timeout, - logger: logger, - rpcAddress: rpcAddress, + client: client, + l2ID: l2ID, + timeout: timeout, + logger: logger, + rpcURL: rpcURL, }, nil } // NewEthClient instantiates a new ethadapter.EthClient that connects to an ethereum node func NewEthClient(ipaddress string, port uint, timeout time.Duration, l2ID gethcommon.Address, logger gethlog.Logger) (EthClient, error) { - rpcAddress := fmt.Sprintf("ws://%s:%d", ipaddress, port) - client, err := connect(rpcAddress, timeout) - if err != nil { - return nil, fmt.Errorf("unable to connect to the eth node (%s) - %w", rpcAddress, err) - } - - logger.Trace(fmt.Sprintf("Initialized eth node connection - addr: %s port: %d", ipaddress, port)) - return &gethRPCClient{ - client: client, - l2ID: l2ID, - timeout: timeout, - logger: logger.New(log.PackageKey, "gethrpcclient"), - rpcAddress: rpcAddress, - }, nil + return NewEthClientFromURL(fmt.Sprintf("ws://%s:%d", ipaddress, port), timeout, l2ID, logger) } func (e *gethRPCClient) FetchHeadBlock() (*types.Block, error) { @@ -271,9 +258,9 @@ func (e *gethRPCClient) ReconnectIfClosed() error { } e.client.Close() - client, err := connect(e.rpcAddress, e.timeout) + client, err := connect(e.rpcURL, e.timeout) if err != nil { - return fmt.Errorf("unable to connect to the eth node (%s) - %w", e.rpcAddress, err) + return fmt.Errorf("unable to connect to the eth node (%s) - %w", e.rpcURL, err) } e.client = client return nil @@ -289,11 +276,11 @@ func (e *gethRPCClient) Alive() bool { return err == nil } -func connect(rpcAddress string, connectionTimeout time.Duration) (*ethclient.Client, error) { +func connect(rpcURL string, connectionTimeout time.Duration) (*ethclient.Client, error) { var err error var c *ethclient.Client for start := time.Now(); time.Since(start) < connectionTimeout; time.Sleep(time.Second) { - c, err = ethclient.Dial(rpcAddress) + c, err = ethclient.Dial(rpcURL) if err == nil { break } diff --git a/go/host/container/cli.go b/go/host/container/cli.go index 68a3016585..eb8c338213 100644 --- a/go/host/container/cli.go +++ b/go/host/container/cli.go @@ -27,8 +27,7 @@ type HostConfigToml struct { EnclaveRPCAddress string P2PBindAddress string P2PPublicAddress string - L1NodeHost string - L1NodeWebsocketPort uint + L1WebsocketURL string EnclaveRPCTimeout int L1RPCTimeout int P2PConnectionTimeout int @@ -67,8 +66,7 @@ func ParseConfig() (*config.HostInputConfig, error) { enclaveRPCAddress := flag.String(enclaveRPCAddressName, cfg.EnclaveRPCAddress, flagUsageMap[enclaveRPCAddressName]) p2pBindAddress := flag.String(p2pBindAddressName, cfg.P2PBindAddress, flagUsageMap[p2pBindAddressName]) p2pPublicAddress := flag.String(p2pPublicAddressName, cfg.P2PPublicAddress, flagUsageMap[p2pPublicAddressName]) - l1NodeHost := flag.String(l1NodeHostName, cfg.L1NodeHost, flagUsageMap[l1NodeHostName]) - l1NodePort := flag.Uint64(l1NodePortName, uint64(cfg.L1NodeWebsocketPort), flagUsageMap[l1NodePortName]) + l1WSURL := flag.String(l1WebsocketURLName, cfg.L1WebsocketURL, flagUsageMap[l1WebsocketURLName]) enclaveRPCTimeoutSecs := flag.Uint64(enclaveRPCTimeoutSecsName, uint64(cfg.EnclaveRPCTimeout.Seconds()), flagUsageMap[enclaveRPCTimeoutSecsName]) l1RPCTimeoutSecs := flag.Uint64(l1RPCTimeoutSecsName, uint64(cfg.L1RPCTimeout.Seconds()), flagUsageMap[l1RPCTimeoutSecsName]) p2pConnectionTimeoutSecs := flag.Uint64(p2pConnectionTimeoutSecsName, uint64(cfg.P2PConnectionTimeout.Seconds()), flagUsageMap[p2pConnectionTimeoutSecsName]) @@ -112,8 +110,7 @@ func ParseConfig() (*config.HostInputConfig, error) { cfg.EnclaveRPCAddress = *enclaveRPCAddress cfg.P2PBindAddress = *p2pBindAddress cfg.P2PPublicAddress = *p2pPublicAddress - cfg.L1NodeHost = *l1NodeHost - cfg.L1NodeWebsocketPort = uint(*l1NodePort) + cfg.L1WebsocketURL = *l1WSURL cfg.EnclaveRPCTimeout = time.Duration(*enclaveRPCTimeoutSecs) * time.Second cfg.L1RPCTimeout = time.Duration(*l1RPCTimeoutSecs) * time.Second cfg.P2PConnectionTimeout = time.Duration(*p2pConnectionTimeoutSecs) * time.Second @@ -182,8 +179,7 @@ func fileBasedConfig(configPath string) (*config.HostInputConfig, error) { EnclaveRPCAddress: tomlConfig.EnclaveRPCAddress, P2PBindAddress: tomlConfig.P2PBindAddress, P2PPublicAddress: tomlConfig.P2PPublicAddress, - L1NodeHost: tomlConfig.L1NodeHost, - L1NodeWebsocketPort: tomlConfig.L1NodeWebsocketPort, + L1WebsocketURL: tomlConfig.L1WebsocketURL, EnclaveRPCTimeout: time.Duration(tomlConfig.EnclaveRPCTimeout) * time.Second, L1RPCTimeout: time.Duration(tomlConfig.L1RPCTimeout) * time.Second, P2PConnectionTimeout: time.Duration(tomlConfig.P2PConnectionTimeout) * time.Second, diff --git a/go/host/container/cli_flags.go b/go/host/container/cli_flags.go index 837555af3a..445d28124b 100644 --- a/go/host/container/cli_flags.go +++ b/go/host/container/cli_flags.go @@ -12,8 +12,7 @@ const ( enclaveRPCAddressName = "enclaveRPCAddress" p2pBindAddressName = "p2pBindAddress" p2pPublicAddressName = "p2pPublicAddress" - l1NodeHostName = "l1NodeHost" - l1NodePortName = "l1NodePort" + l1WebsocketURLName = "l1WSURL" enclaveRPCTimeoutSecsName = "enclaveRPCTimeoutSecs" l1RPCTimeoutSecsName = "l1RPCTimeoutSecs" p2pConnectionTimeoutSecsName = "p2pConnectionTimeoutSecs" @@ -51,8 +50,7 @@ func getFlagUsageMap() map[string]string { enclaveRPCAddressName: "The address to use to connect to the Obscuro enclave service", p2pBindAddressName: "The address where the p2p server is bound to. Defaults to 0.0.0.0:10000", p2pPublicAddressName: "The P2P address where the other servers should connect to. Defaults to 127.0.0.1:10000", - l1NodeHostName: "The network host on which to connect to the Ethereum client", - l1NodePortName: "The port on which to connect to the Ethereum client", + l1WebsocketURLName: "The websocket RPC address the host can use for L1 requests", enclaveRPCTimeoutSecsName: "The timeout for host <-> enclave RPC communication", l1RPCTimeoutSecsName: "The timeout for connecting to, and communicating with, the Ethereum client", p2pConnectionTimeoutSecsName: "The timeout for host <-> host P2P messaging", diff --git a/go/host/container/host_container.go b/go/host/container/host_container.go index c8c4ffb1e1..fe3380cb71 100644 --- a/go/host/container/host_container.go +++ b/go/host/container/host_container.go @@ -114,7 +114,7 @@ func NewHostContainerFromConfig(parsedConfig *config.HostInputConfig, logger get ethWallet := wallet.NewInMemoryWalletFromConfig(cfg.PrivateKeyString, cfg.L1ChainID, log.New("wallet", cfg.LogLevel, cfg.LogPath)) fmt.Println("Connecting to L1 network...") - l1Client, err := ethadapter.NewEthClient(cfg.L1NodeHost, cfg.L1NodeWebsocketPort, cfg.L1RPCTimeout, cfg.ID, logger) + l1Client, err := ethadapter.NewEthClientFromURL(cfg.L1WebsocketURL, cfg.L1RPCTimeout, cfg.ID, logger) if err != nil { logger.Crit("could not create Ethereum client.", log.ErrKey, err) } diff --git a/go/host/container/test.toml b/go/host/container/test.toml index 0e5fbfd916..7a56417666 100644 --- a/go/host/container/test.toml +++ b/go/host/container/test.toml @@ -10,8 +10,7 @@ EnclaveRPCTimeout = 10 P2PBindAddress = "0.0.0.0:10000" P2PPublicAddress = "127.0.0.1:10000" P2PConnectionTimeout = 777 -L1NodeHost = "127.0.0.1" -L1NodeWebsocketPort = 8546 +L1WebsocketURL = "ws://127.0.0.1:8546" L1RPCTimeout = 15 ManagementContractAddress = "" LogLevel = 3 diff --git a/go/node/cmd/cli.go b/go/node/cmd/cli.go index d7d4bf427f..fee04d1277 100644 --- a/go/node/cmd/cli.go +++ b/go/node/cmd/cli.go @@ -21,8 +21,7 @@ type NodeConfigCLI struct { isSGXEnabled bool enclaveDockerImage string hostDockerImage string - l1Host string - l1WSPort int + l1WebsocketURL string hostP2PPort int hostP2PHost string hostP2PPublicAddr string @@ -55,8 +54,7 @@ func ParseConfigCLI() *NodeConfigCLI { isSGXEnabled := flag.Bool(isSGXEnabledFlag, false, flagUsageMap[isSGXEnabledFlag]) enclaveDockerImage := flag.String(enclaveDockerImageFlag, "", flagUsageMap[enclaveDockerImageFlag]) hostDockerImage := flag.String(hostDockerImageFlag, "", flagUsageMap[hostDockerImageFlag]) - l1Host := flag.String(l1HostFlag, "eth2network", flagUsageMap[l1HostFlag]) - l1WSPort := flag.Int(l1WSPortFlag, 9000, flagUsageMap[l1WSPortFlag]) + l1WebsocketURL := flag.String(l1WebsocketURLFlag, "ws://eth2network:9000", flagUsageMap[l1WebsocketURLFlag]) hostP2PPort := flag.Int(hostP2PPortFlag, 14000, flagUsageMap[hostP2PPortFlag]) hostP2PHost := flag.String(hostP2PHostFlag, "0.0.0.0", flagUsageMap[hostP2PHostFlag]) hostP2PPublicAddr := flag.String(hostP2PPublicAddrFlag, "", flagUsageMap[hostP2PPublicAddrFlag]) @@ -83,8 +81,7 @@ func ParseConfigCLI() *NodeConfigCLI { cfg.isSGXEnabled = *isSGXEnabled cfg.enclaveDockerImage = *enclaveDockerImage cfg.hostDockerImage = *hostDockerImage - cfg.l1Host = *l1Host - cfg.l1WSPort = *l1WSPort + cfg.l1WebsocketURL = *l1WebsocketURL cfg.hostP2PPort = *hostP2PPort cfg.hostP2PHost = *hostP2PHost cfg.hostP2PPublicAddr = *hostP2PPublicAddr diff --git a/go/node/cmd/cli_flags.go b/go/node/cmd/cli_flags.go index 7ecd9d8850..ecba8f874e 100644 --- a/go/node/cmd/cli_flags.go +++ b/go/node/cmd/cli_flags.go @@ -9,8 +9,7 @@ const ( isSGXEnabledFlag = "is_sgx_enabled" enclaveDockerImageFlag = "enclave_docker_image" hostDockerImageFlag = "host_docker_image" - l1HostFlag = "l1_host" - l1WSPortFlag = "l1_ws_port" + l1WebsocketURLFlag = "l1_ws_url" hostHTTPPortFlag = "host_http_port" hostWSPortFlag = "host_ws_port" hostP2PPortFlag = "host_p2p_port" @@ -41,8 +40,7 @@ func getFlagUsageMap() map[string]string { isSGXEnabledFlag: "Whether the it should run on an SGX is enabled CPU", enclaveDockerImageFlag: "Docker image for the enclave", hostDockerImageFlag: "Docker image for the host", - l1HostFlag: "Layer 1 network host addr", - l1WSPortFlag: "Layer 1 network WebSocket port", + l1WebsocketURLFlag: "Layer 1 websocket RPC address", hostP2PPortFlag: "Hosts p2p bound port", hostP2PPublicAddrFlag: "Hosts public p2p host.", hostP2PHostFlag: "Hosts p2p bound addr", diff --git a/go/node/cmd/main.go b/go/node/cmd/main.go index ac4dfa49ed..4aa3436c36 100644 --- a/go/node/cmd/main.go +++ b/go/node/cmd/main.go @@ -15,8 +15,7 @@ func main() { node.WithSGXEnabled(cliConfig.isSGXEnabled), node.WithEnclaveImage(cliConfig.enclaveDockerImage), // "local_enclave" node.WithHostImage(cliConfig.hostDockerImage), // "local_host" - node.WithL1Host(cliConfig.l1Host), // "eth2network" - node.WithL1WSPort(cliConfig.l1WSPort), // 9000 + node.WithL1WebsocketURL(cliConfig.l1WebsocketURL), // "ws://eth2network:9000" node.WithHostP2PPort(cliConfig.hostP2PPort), // 14000 node.WithHostP2PHost(cliConfig.hostP2PHost), // 0.0.0.0 node.WithHostPublicP2PAddr(cliConfig.hostP2PPublicAddr), // node public facing ip and port diff --git a/go/node/config.go b/go/node/config.go index 86aef30bad..862ab226dd 100644 --- a/go/node/config.go +++ b/go/node/config.go @@ -24,7 +24,7 @@ type Config struct { enclaveImage string hostImage string nodeType string - l1Host string + l1WSURL string sequencerID string privateKey string hostP2PPort int @@ -35,7 +35,6 @@ type Config struct { messageBusContractAddress string managementContractAddr string l1Start string - l1WSPort int hostP2PHost string hostPublicP2PAddr string pccsAddr string @@ -95,8 +94,7 @@ func (c *Config) ToHostConfig() *config.HostInputConfig { cfg.P2PPublicAddress = fmt.Sprintf("127.0.0.1:%d", c.hostP2PPort) cfg.P2PBindAddress = c.hostPublicP2PAddr - cfg.L1NodeWebsocketPort = uint(c.l1WSPort) - cfg.L1NodeHost = c.l1Host + cfg.L1WebsocketURL = c.l1WSURL cfg.ManagementContractAddress = gethcommon.HexToAddress(c.managementContractAddr) cfg.MessageBusAddress = gethcommon.HexToAddress(c.messageBusContractAddress) cfg.LogPath = testlog.LogFile() @@ -202,15 +200,9 @@ func WithL1Start(blockHash string) Option { } } -func WithL1WSPort(i int) Option { +func WithL1WebsocketURL(addr string) Option { return func(c *Config) { - c.l1WSPort = i - } -} - -func WithL1Host(s string) Option { - return func(c *Config) { - c.l1Host = s + c.l1WSURL = addr } } diff --git a/go/node/docker_node.go b/go/node/docker_node.go index 6a9cb2b973..694559784b 100644 --- a/go/node/docker_node.go +++ b/go/node/docker_node.go @@ -94,8 +94,7 @@ func (d *DockerNode) Upgrade(networkCfg *NetworkConfig) error { func (d *DockerNode) startHost() error { cmd := []string{ "/home/obscuro/go-obscuro/go/host/main/main", - "-l1NodeHost", d.cfg.l1Host, - "-l1NodePort", fmt.Sprintf("%d", d.cfg.l1WSPort), + "-l1WSURL", d.cfg.l1WSURL, "-enclaveRPCAddress", fmt.Sprintf("%s:%d", d.cfg.nodeName+"-enclave", d.cfg.enclaveWSPort), "-managementContractAddress", d.cfg.managementContractAddr, "-messageBusContractAddress", d.cfg.messageBusContractAddress, diff --git a/integration/networktest/env/network_setup.go b/integration/networktest/env/network_setup.go index b4a40aa9b6..f8ded0279c 100644 --- a/integration/networktest/env/network_setup.go +++ b/integration/networktest/env/network_setup.go @@ -25,12 +25,12 @@ func DevTestnet() networktest.Environment { return &testnetEnv{connector} } -func LongRunningLocalNetwork(l1RPCAddress string) networktest.Environment { +func LongRunningLocalNetwork(l1WSURL string) networktest.Environment { connector := NewTestnetConnectorWithFaucetAccount( "http://127.0.0.1:37800", []string{"http://127.0.0.1:37801", "http://127.0.0.1:37802"}, genesis.TestnetPrefundedPK, - l1RPCAddress, + l1WSURL, ) return &testnetEnv{connector} } diff --git a/integration/networktest/env/testnet.go b/integration/networktest/env/testnet.go index d74e8e7a4e..e05a14a773 100644 --- a/integration/networktest/env/testnet.go +++ b/integration/networktest/env/testnet.go @@ -28,16 +28,16 @@ type testnetConnector struct { seqRPCAddress string validatorRPCAddresses []string faucetHTTPAddress string - l1RPCAddress string + l1WSURL string faucetWallet *userwallet.UserWallet } -func NewTestnetConnector(seqRPCAddr string, validatorRPCAddressses []string, faucetHTTPAddress string, l1RPCAddress string) networktest.NetworkConnector { +func NewTestnetConnector(seqRPCAddr string, validatorRPCAddressses []string, faucetHTTPAddress string, l1WSURL string) networktest.NetworkConnector { return &testnetConnector{ seqRPCAddress: seqRPCAddr, validatorRPCAddresses: validatorRPCAddressses, faucetHTTPAddress: faucetHTTPAddress, - l1RPCAddress: l1RPCAddress, + l1WSURL: l1WSURL, } } @@ -50,7 +50,7 @@ func NewTestnetConnectorWithFaucetAccount(seqRPCAddr string, validatorRPCAddress seqRPCAddress: seqRPCAddr, validatorRPCAddresses: validatorRPCAddressses, faucetWallet: userwallet.NewUserWallet(ecdsaKey, validatorRPCAddressses[0], testlog.Logger(), userwallet.WithChainID(big.NewInt(integration.ObscuroChainID))), - l1RPCAddress: l1RPCAddress, + l1WSURL: l1RPCAddress, } } @@ -94,7 +94,7 @@ func (t *testnetConnector) NumValidators() int { } func (t *testnetConnector) GetL1Client() (ethadapter.EthClient, error) { - client, err := ethadapter.NewEthClientFromAddress(t.l1RPCAddress, time.Minute, gethcommon.Address{}, testlog.Logger()) + client, err := ethadapter.NewEthClientFromURL(t.l1WSURL, time.Minute, gethcommon.Address{}, testlog.Logger()) if err != nil { return nil, err } diff --git a/integration/networktest/tests/helpful/spin_up_local_network_test.go b/integration/networktest/tests/helpful/spin_up_local_network_test.go index 4a53d552b8..73b1d01f70 100644 --- a/integration/networktest/tests/helpful/spin_up_local_network_test.go +++ b/integration/networktest/tests/helpful/spin_up_local_network_test.go @@ -62,7 +62,7 @@ func TestRunLocalNetworkAgainstSepolia(t *testing.T) { } func checkBalance(walDesc string, wal wallet.Wallet, rpcAddress string) { - client, err := ethadapter.NewEthClientFromAddress(rpcAddress, 20*time.Second, common.HexToAddress("0x0"), testlog.Logger()) + client, err := ethadapter.NewEthClientFromURL(rpcAddress, 20*time.Second, common.HexToAddress("0x0"), testlog.Logger()) if err != nil { panic("unable to create live L1 eth client, err=" + err.Error()) } diff --git a/integration/noderunner/noderunner_test.go b/integration/noderunner/noderunner_test.go index 5f483ed756..67a034f5fe 100644 --- a/integration/noderunner/noderunner_test.go +++ b/integration/noderunner/noderunner_test.go @@ -72,11 +72,11 @@ func TestCanStartStandaloneObscuroHostAndEnclave(t *testing.T) { } // we create the node RPC client - rpcAddress := fmt.Sprintf("ws://127.0.0.1:%d", _startPort+integration.DefaultGethWSPortOffset) + wsURL := fmt.Sprintf("ws://127.0.0.1:%d", _startPort+integration.DefaultGethWSPortOffset) var obscuroClient rpc.Client wait := 30 // max wait in seconds for { - obscuroClient, err = rpc.NewNetworkClient(rpcAddress) + obscuroClient, err = rpc.NewNetworkClient(wsURL) if err == nil { break } @@ -128,8 +128,7 @@ func createInMemoryNode(t *testing.T) (node.Node, gethcommon.Address) { node.WithEnclaveWSPort(_startPort+integration.DefaultEnclaveOffset), node.WithHostHTTPPort(_startPort+integration.DefaultHostRPCHTTPOffset), node.WithHostWSPort(_startPort+integration.DefaultHostRPCWSOffset), - node.WithL1Host(_localhost), - node.WithL1WSPort(_startPort+integration.DefaultGethWSPortOffset), + node.WithL1WebsocketURL(fmt.Sprintf("ws://%s:%d", _localhost, _startPort+integration.DefaultGethWSPortOffset)), node.WithGenesis(true), node.WithProfiler(true), ) diff --git a/integration/simulation/devnetwork/live_l1.go b/integration/simulation/devnetwork/live_l1.go index e3e4b951cc..6e3ca03367 100644 --- a/integration/simulation/devnetwork/live_l1.go +++ b/integration/simulation/devnetwork/live_l1.go @@ -22,7 +22,7 @@ type liveL1Network struct { func (l *liveL1Network) Prepare() { // nothing to do really, sanity check the L1 connection logger := testlog.Logger() - client, err := ethadapter.NewEthClientFromAddress(l.rpcAddress, 20*time.Second, common.HexToAddress("0x0"), logger) + client, err := ethadapter.NewEthClientFromURL(l.rpcAddress, 20*time.Second, common.HexToAddress("0x0"), logger) if err != nil { panic("unable to create live L1 eth client, err=" + err.Error()) } diff --git a/integration/simulation/network/obscuro_node_utils.go b/integration/simulation/network/obscuro_node_utils.go index b4383b87a2..ad8771fe56 100644 --- a/integration/simulation/network/obscuro_node_utils.go +++ b/integration/simulation/network/obscuro_node_utils.go @@ -135,19 +135,19 @@ func StopObscuroNodes(clients []rpc.Client) { } // CheckHostRPCServersStopped checks whether the hosts' RPC server addresses have been freed up. -func CheckHostRPCServersStopped(hostRPCAddresses []string) { +func CheckHostRPCServersStopped(hostWSURLS []string) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() eg, _ := errgroup.WithContext(ctx) - for _, hostRPCAddress := range hostRPCAddresses { - rpcAddress := hostRPCAddress + for _, hostWSURL := range hostWSURLS { + url := hostWSURL // We cannot stop the RPC server synchronously. This is because the host itself is being stopped by an RPC // call, so there is a deadlock. The RPC server is waiting for all connections to close, but a single // connection remains open, waiting for the RPC server to close. Instead, we check whether the RPC port // becomes free. eg.Go(func() error { - for !isAddressAvailable(rpcAddress) { + for !isAddressAvailable(url) { time.Sleep(100 * time.Millisecond) } return nil diff --git a/integration/simulation/network/socket.go b/integration/simulation/network/socket.go index 17da492b77..74c9b36d37 100644 --- a/integration/simulation/network/socket.go +++ b/integration/simulation/network/socket.go @@ -23,8 +23,8 @@ import ( // creates Obscuro nodes with their own enclave servers that communicate with peers via sockets, wires them up, and populates the network objects type networkOfSocketNodes struct { - l2Clients []rpc.Client - hostRPCAddresses []string + l2Clients []rpc.Client + hostWebsocketURLs []string // geth eth2Network eth2network.Eth2Network @@ -94,8 +94,7 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat node.WithManagementContractAddress(simParams.L1SetupData.MgmtContractAddress.String()), node.WithMessageBusContractAddress(simParams.L1SetupData.MessageBusAddr.String()), node.WithNodeType(nodeTypeStr), - node.WithL1Host("127.0.0.1"), - node.WithL1WSPort(simParams.StartPort+100), + node.WithL1WebsocketURL(fmt.Sprintf("ws://%s:%d", "127.0.0.1", simParams.StartPort+100)), node.WithInboundP2PDisabled(isInboundP2PDisabled), node.WithLogLevel(4), node.WithDebugNamespaceEnabled(true), @@ -128,13 +127,13 @@ func (n *networkOfSocketNodes) TearDown() { // Stop the Obscuro nodes first (each host will attempt to shut down its enclave as part of shutdown). StopObscuroNodes(n.l2Clients) StopEth2Network(n.gethClients, n.eth2Network) - CheckHostRPCServersStopped(n.hostRPCAddresses) + CheckHostRPCServersStopped(n.hostWebsocketURLs) } func (n *networkOfSocketNodes) createConnections(simParams *params.SimParams) error { // create the clients in the structs n.l2Clients = make([]rpc.Client, simParams.NumberOfNodes) - n.hostRPCAddresses = make([]string, simParams.NumberOfNodes) + n.hostWebsocketURLs = make([]string, simParams.NumberOfNodes) n.obscuroClients = make([]*obsclient.ObsClient, simParams.NumberOfNodes) for i := 0; i < simParams.NumberOfNodes; i++ { @@ -154,7 +153,7 @@ func (n *networkOfSocketNodes) createConnections(simParams *params.SimParams) er } n.l2Clients[i] = client - n.hostRPCAddresses[i] = fmt.Sprintf("ws://%s:%d", Localhost, simParams.StartPort+integration.DefaultHostRPCWSOffset+i) + n.hostWebsocketURLs[i] = fmt.Sprintf("ws://%s:%d", Localhost, simParams.StartPort+integration.DefaultHostRPCWSOffset+i) } for idx, l2Client := range n.l2Clients { diff --git a/testnet/launcher/docker.go b/testnet/launcher/docker.go index 5302a31339..80f4ad0390 100644 --- a/testnet/launcher/docker.go +++ b/testnet/launcher/docker.go @@ -46,8 +46,7 @@ func (t *Testnet) Start() error { node.WithEnclaveImage(t.cfg.sequencerEnclaveDockerImage), node.WithEnclaveDebug(t.cfg.sequencerEnclaveDebug), node.WithHostImage("testnetobscuronet.azurecr.io/obscuronet/host:latest"), - node.WithL1Host("eth2network"), - node.WithL1WSPort(9000), + node.WithL1WebsocketURL("ws://eth2network:9000"), node.WithEnclaveWSPort(11000), node.WithHostHTTPPort(80), node.WithHostWSPort(81), @@ -86,8 +85,7 @@ func (t *Testnet) Start() error { node.WithEnclaveImage(t.cfg.validatorEnclaveDockerImage), node.WithEnclaveDebug(t.cfg.validatorEnclaveDebug), node.WithHostImage("testnetobscuronet.azurecr.io/obscuronet/host:latest"), - node.WithL1Host("eth2network"), - node.WithL1WSPort(9000), + node.WithL1WebsocketURL("ws://eth2network:9000"), node.WithEnclaveWSPort(11010), node.WithHostHTTPPort(13010), node.WithHostWSPort(13011), @@ -120,8 +118,7 @@ func (t *Testnet) Start() error { l2ContractDeployer, err := l2cd.NewDockerContractDeployer( l2cd.NewContractDeployerConfig( - l2cd.WithL1Host("eth2network"), - l2cd.WithL1Port(8025), + l2cd.WithL1HTTPURL("http://eth2network:8025"), l2cd.WithL2Host("sequencer-host"), l2cd.WithL2WSPort(81), l2cd.WithL1PrivateKey("f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb"), @@ -185,8 +182,7 @@ func startEth2Network() error { func deployL1Contracts() (*node.NetworkConfig, error) { l1ContractDeployer, err := l1cd.NewDockerContractDeployer( l1cd.NewContractDeployerConfig( - l1cd.WithL1Host("eth2network"), - l1cd.WithL1Port(8025), + l1cd.WithL1HTTPURL("http://eth2network:8025"), l1cd.WithPrivateKey("f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb"), l1cd.WithDockerImage("testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest"), ), @@ -212,11 +208,11 @@ func deployL1Contracts() (*node.NetworkConfig, error) { func waitForHealthyNode(port int) error { // todo: hook the cfg timeStart := time.Now() - hostRPCAddress := fmt.Sprintf("http://localhost:%d", port) + hostURL := fmt.Sprintf("http://localhost:%d", port) fmt.Println("Waiting for Obscuro node to be healthy...") err := retry.Do( func() error { - client, err := rpc.NewNetworkClient(hostRPCAddress) + client, err := rpc.NewNetworkClient(hostURL) if err != nil { return err } diff --git a/testnet/launcher/l1contractdeployer/cmd/cli.go b/testnet/launcher/l1contractdeployer/cmd/cli.go index eabb675633..a7c657d447 100644 --- a/testnet/launcher/l1contractdeployer/cmd/cli.go +++ b/testnet/launcher/l1contractdeployer/cmd/cli.go @@ -6,8 +6,7 @@ import ( // L1ContractDeployerConfigCLI represents the configurations passed into the deployer over CLI type L1ContractDeployerConfigCLI struct { - l1Host string - l1HTTPPort int + l1HTTPURL string privateKey string dockerImage string contractsEnvFile string @@ -18,15 +17,13 @@ func ParseConfigCLI() *L1ContractDeployerConfigCLI { cfg := &L1ContractDeployerConfigCLI{} flagUsageMap := getFlagUsageMap() - l1Host := flag.String(l1HostFlag, "eth2network", flagUsageMap[l1HostFlag]) - l1HTTPPort := flag.Int(l1HTTPPortFlag, 8025, flagUsageMap[l1HTTPPortFlag]) + l1HTTPURL := flag.String(l1HTTPURLFlag, "http://eth2network:8025", flagUsageMap[l1HTTPURLFlag]) privateKey := flag.String(privateKeyFlag, "", flagUsageMap[privateKeyFlag]) dockerImage := flag.String(dockerImageFlag, "testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest", flagUsageMap[dockerImageFlag]) contractsEnvFile := flag.String(contractsEnvFileFlag, "", flagUsageMap[contractsEnvFileFlag]) flag.Parse() - cfg.l1Host = *l1Host - cfg.l1HTTPPort = *l1HTTPPort + cfg.l1HTTPURL = *l1HTTPURL cfg.privateKey = *privateKey cfg.dockerImage = *dockerImage cfg.contractsEnvFile = *contractsEnvFile diff --git a/testnet/launcher/l1contractdeployer/cmd/cli_flags.go b/testnet/launcher/l1contractdeployer/cmd/cli_flags.go index 06c5a3d8ce..0d7385fe4a 100644 --- a/testnet/launcher/l1contractdeployer/cmd/cli_flags.go +++ b/testnet/launcher/l1contractdeployer/cmd/cli_flags.go @@ -2,8 +2,7 @@ package main // Flag names. const ( - l1HostFlag = "l1_host" - l1HTTPPortFlag = "l1_http_port" + l1HTTPURLFlag = "l1_ws_url" privateKeyFlag = "private_key" dockerImageFlag = "docker_image" contractsEnvFileFlag = "contracts_env_file" @@ -13,8 +12,7 @@ const ( // While we could just use constants instead of a map, this approach allows us to test that all the expected flags are defined. func getFlagUsageMap() map[string]string { return map[string]string{ - l1HostFlag: "Layer 1 network host addr", - l1HTTPPortFlag: "Layer 1 network HTTP port", + l1HTTPURLFlag: "Layer 1 network http RPC addr", privateKeyFlag: "L1 and L2 private key used in the node", dockerImageFlag: "Docker image to run", contractsEnvFileFlag: "If set, it will write the contract addresses to the file", diff --git a/testnet/launcher/l1contractdeployer/cmd/main.go b/testnet/launcher/l1contractdeployer/cmd/main.go index 55c65d76c8..7b83350358 100644 --- a/testnet/launcher/l1contractdeployer/cmd/main.go +++ b/testnet/launcher/l1contractdeployer/cmd/main.go @@ -12,8 +12,7 @@ func main() { l1ContractDeployer, err := l1cd.NewDockerContractDeployer( l1cd.NewContractDeployerConfig( - l1cd.WithL1Host(cliConfig.l1Host), - l1cd.WithL1Port(cliConfig.l1HTTPPort), // 8025 + l1cd.WithL1HTTPURL(cliConfig.l1HTTPURL), // "http://eth2network:8025" l1cd.WithPrivateKey(cliConfig.privateKey), //"f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb"), l1cd.WithDockerImage(cliConfig.dockerImage), //"testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest" ), diff --git a/testnet/launcher/l1contractdeployer/config.go b/testnet/launcher/l1contractdeployer/config.go index 5652629aba..0a6a6315cd 100644 --- a/testnet/launcher/l1contractdeployer/config.go +++ b/testnet/launcher/l1contractdeployer/config.go @@ -5,9 +5,8 @@ type Option = func(c *Config) // Config holds the properties that configure the package type Config struct { - l1Host string + l1HTTPURL string privateKey string - l1Port int dockerImage string } @@ -21,15 +20,9 @@ func NewContractDeployerConfig(opts ...Option) *Config { return defaultConfig } -func WithL1Host(s string) Option { +func WithL1HTTPURL(s string) Option { return func(c *Config) { - c.l1Host = s - } -} - -func WithL1Port(i int) Option { - return func(c *Config) { - c.l1Port = i + c.l1HTTPURL = s } } diff --git a/testnet/launcher/l1contractdeployer/docker.go b/testnet/launcher/l1contractdeployer/docker.go index 2d8badd81a..e985fdc358 100644 --- a/testnet/launcher/l1contractdeployer/docker.go +++ b/testnet/launcher/l1contractdeployer/docker.go @@ -40,7 +40,7 @@ func (n *ContractDeployer) Start() error { "NETWORK_JSON": fmt.Sprintf(` { "layer1" : { - "url" : "http://%s:%d", + "url" : "%s", "live" : false, "saveDeployments" : true, "deploy": [ @@ -49,7 +49,7 @@ func (n *ContractDeployer) Start() error { "accounts": [ "%s" ] } } -`, n.cfg.l1Host, n.cfg.l1Port, n.cfg.privateKey), +`, n.cfg.l1HTTPURL, n.cfg.privateKey), } containerID, err := docker.StartNewContainer("hh-l1-deployer", n.cfg.dockerImage, cmds, nil, envs, nil, nil) diff --git a/testnet/launcher/l2contractdeployer/cmd/cli.go b/testnet/launcher/l2contractdeployer/cmd/cli.go index 0454bf7a1f..9de87e00e9 100644 --- a/testnet/launcher/l2contractdeployer/cmd/cli.go +++ b/testnet/launcher/l2contractdeployer/cmd/cli.go @@ -6,8 +6,7 @@ import ( // L2ContractDeployerConfigCLI represents the configurations passed into the deployer over CLI type L2ContractDeployerConfigCLI struct { - l1Host string - l1HTTPPort int + l1HTTPURL string privateKey string dockerImage string l2Host string @@ -23,8 +22,7 @@ func ParseConfigCLI() *L2ContractDeployerConfigCLI { cfg := &L2ContractDeployerConfigCLI{} flagUsageMap := getFlagUsageMap() - l1Host := flag.String(l1HostFlag, "eth2network", flagUsageMap[l1HostFlag]) - l1HTTPPort := flag.Int(l1HTTPPortFlag, 8025, flagUsageMap[l1HTTPPortFlag]) + l1HTTPURL := flag.String(l1HTTPURLFlag, "http://eth2network:8025", flagUsageMap[l1HTTPURLFlag]) privateKey := flag.String(privateKeyFlag, "", flagUsageMap[privateKeyFlag]) dockerImage := flag.String(dockerImageFlag, "testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest", flagUsageMap[dockerImageFlag]) l2Host := flag.String(l2HostFlag, "", flagUsageMap[l2HostFlag]) @@ -36,8 +34,7 @@ func ParseConfigCLI() *L2ContractDeployerConfigCLI { flag.Parse() - cfg.l1Host = *l1Host - cfg.l1HTTPPort = *l1HTTPPort + cfg.l1HTTPURL = *l1HTTPURL cfg.privateKey = *privateKey cfg.dockerImage = *dockerImage cfg.l2Host = *l2Host diff --git a/testnet/launcher/l2contractdeployer/cmd/cli_flags.go b/testnet/launcher/l2contractdeployer/cmd/cli_flags.go index 903f71fe2a..231d23cd47 100644 --- a/testnet/launcher/l2contractdeployer/cmd/cli_flags.go +++ b/testnet/launcher/l2contractdeployer/cmd/cli_flags.go @@ -2,8 +2,7 @@ package main // Flag names. const ( - l1HostFlag = "l1_host" - l1HTTPPortFlag = "l1_http_port" + l1HTTPURLFlag = "l1_ws_url" privateKeyFlag = "private_key" dockerImageFlag = "docker_image" l2HostFlag = "l2_host" @@ -18,8 +17,7 @@ const ( // While we could just use constants instead of a map, this approach allows us to test that all the expected flags are defined. func getFlagUsageMap() map[string]string { return map[string]string{ - l1HostFlag: "Layer 1 network host addr", - l1HTTPPortFlag: "Layer 1 network HTTP port", + l1HTTPURLFlag: "Layer 1 network http RPC addr", privateKeyFlag: "L1 and L2 private key used in the node", dockerImageFlag: "Docker image to run", l2HostFlag: "Layer 2 network host addr", diff --git a/testnet/launcher/l2contractdeployer/cmd/main.go b/testnet/launcher/l2contractdeployer/cmd/main.go index 72b2132ad3..bd24639783 100644 --- a/testnet/launcher/l2contractdeployer/cmd/main.go +++ b/testnet/launcher/l2contractdeployer/cmd/main.go @@ -12,8 +12,7 @@ func main() { l2ContractDeployer, err := l2cd.NewDockerContractDeployer( l2cd.NewContractDeployerConfig( - l2cd.WithL1Host(cliConfig.l1Host), // "eth2network" - l2cd.WithL1Port(cliConfig.l1HTTPPort), // 8025 + l2cd.WithL1HTTPURL(cliConfig.l1HTTPURL), // "http://eth2network:8025" l2cd.WithL2Host(cliConfig.l2Host), // "host" l2cd.WithL2WSPort(cliConfig.l2WSPort), // 81 l2cd.WithL1PrivateKey(cliConfig.privateKey), // "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb" diff --git a/testnet/launcher/l2contractdeployer/config.go b/testnet/launcher/l2contractdeployer/config.go index 9e075cb358..5708936913 100644 --- a/testnet/launcher/l2contractdeployer/config.go +++ b/testnet/launcher/l2contractdeployer/config.go @@ -5,9 +5,8 @@ type Option = func(c *Config) // Config holds the properties that configure the package type Config struct { - l1Host string + l1HTTPURL string l1privateKey string - l1Port int l2Port int l2Host string l2PrivateKey string @@ -27,15 +26,9 @@ func NewContractDeployerConfig(opts ...Option) *Config { return defaultConfig } -func WithL1Host(s string) Option { +func WithL1HTTPURL(s string) Option { return func(c *Config) { - c.l1Host = s - } -} - -func WithL1Port(i int) Option { - return func(c *Config) { - c.l1Port = i + c.l1HTTPURL = s } } diff --git a/testnet/launcher/l2contractdeployer/docker.go b/testnet/launcher/l2contractdeployer/docker.go index bd1f9f350d..e61ba535d6 100644 --- a/testnet/launcher/l2contractdeployer/docker.go +++ b/testnet/launcher/l2contractdeployer/docker.go @@ -37,7 +37,7 @@ func (n *ContractDeployer) Start() error { "NETWORK_JSON": fmt.Sprintf(` { "layer1" : { - "url" : "http://%s:%d", + "url" : "%s", "live" : false, "saveDeployments" : true, "deploy": [ @@ -67,7 +67,7 @@ func (n *ContractDeployer) Start() error { ] } } -`, n.cfg.l1Host, n.cfg.l1Port, n.cfg.l1privateKey, n.cfg.l2Host, n.cfg.l2Port, n.cfg.l2PrivateKey, n.cfg.hocPKString, n.cfg.pocPKString), +`, 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)