From b90c47a994f0fba8acc0efdbe0758f98f27b1992 Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 15 Nov 2023 14:53:25 +0100 Subject: [PATCH] Switches to automatic public IP address for codex and geth containers. --- ProjectPlugins/CodexPlugin/CodexApiTypes.cs | 3 ++- .../CodexPlugin/CodexContainerRecipe.cs | 4 +++- ProjectPlugins/CodexPlugin/CodexSetup.cs | 2 +- .../CodexPlugin/CodexStartupConfig.cs | 1 - .../GethPlugin/GethContainerRecipe.cs | 17 +++++++++-------- ProjectPlugins/GethPlugin/GethStartupConfig.cs | 4 +--- Tools/CodexNetDeployer/CodexNodeStarter.cs | 1 - Tools/CodexNetDeployer/Configuration.cs | 7 ------- Tools/CodexNetDeployer/Deployer.cs | 1 - Tools/CodexNetDeployer/deploy-public-testnet.sh | 2 -- 10 files changed, 16 insertions(+), 26 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexApiTypes.cs b/ProjectPlugins/CodexPlugin/CodexApiTypes.cs index af52383..b1965cd 100644 --- a/ProjectPlugins/CodexPlugin/CodexApiTypes.cs +++ b/ProjectPlugins/CodexPlugin/CodexApiTypes.cs @@ -5,9 +5,10 @@ namespace CodexPlugin public class CodexDebugResponse { public string id { get; set; } = string.Empty; - public string[] addrs { get; set; } = new string[0]; + public string[] addrs { get; set; } = Array.Empty(); public string repo { get; set; } = string.Empty; public string spr { get; set; } = string.Empty; + public string[] announceAddresses { get; set; } = Array.Empty(); public EnginePeerResponse[] enginePeers { get; set; } = Array.Empty(); public SwitchPeerResponse[] switchPeers { get; set; } = Array.Empty(); public CodexDebugVersionResponse codex { get; set; } = new(); diff --git a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs index 744ae37..d08675a 100644 --- a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs +++ b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs @@ -47,13 +47,15 @@ namespace CodexPlugin if (config.PublicTestNet != null) { - AddEnvVar("CODEX_NAT", config.PublicTestNet.PublicNatIP); + // This makes the node announce itself to its public IP address. AddEnvVar("NAT_IP_AUTO", "false"); + AddEnvVar("NAT_PUBLIC_IP_AUTO", "true"); } else { // This makes the node announce itself to its local (pod) IP address. AddEnvVar("NAT_IP_AUTO", "true"); + AddEnvVar("NAT_PUBLIC_IP_AUTO", "false"); } var listenPort = CreateListenPort(config); diff --git a/ProjectPlugins/CodexPlugin/CodexSetup.cs b/ProjectPlugins/CodexPlugin/CodexSetup.cs index 8b7dbb1..a491fb3 100644 --- a/ProjectPlugins/CodexPlugin/CodexSetup.cs +++ b/ProjectPlugins/CodexPlugin/CodexSetup.cs @@ -133,7 +133,7 @@ namespace CodexPlugin private IEnumerable DescribeArgs() { - if (PublicTestNet != null) yield return $"Public TestNet at {PublicTestNet.PublicNatIP}:{PublicTestNet.PublicListenPort}"; + if (PublicTestNet != null) yield return $"Public TestNet with listenPort: {PublicTestNet.PublicListenPort}"; yield return $"LogLevel={LogLevelWithTopics()}"; if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}"; if (StorageQuota != null) yield return $"StorageQuota={StorageQuota}"; diff --git a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs index 6e59f2a..ed840d0 100644 --- a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs +++ b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs @@ -65,7 +65,6 @@ namespace CodexPlugin public class CodexTestNetConfig { - public string PublicNatIP { get; set; } = string.Empty; public int PublicDiscoveryPort { get; set; } public int PublicListenPort { get; set; } } diff --git a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs index 35b994c..beda54c 100644 --- a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs +++ b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs @@ -40,7 +40,7 @@ namespace GethPlugin var authRpc = CreateP2pPort(config, tag: AuthRpcPortTag); var wsPort = CreateP2pPort(config, tag: WsPortTag); - var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {listen.Number} --discovery.port {discovery.Number} {GetTestNetArgs(config)} {defaultArgs}"; + var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {listen.Number} --discovery.port {discovery.Number} {defaultArgs}"; if (config.BootstrapNode != null) { @@ -50,6 +50,14 @@ namespace GethPlugin var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort} --nat=extip:{bootIp}"; args += bootstrapArg; } + if (config.IsPublicTestNet != null) + { + AddEnvVar("NAT_PUBLIC_IP_AUTO", "true"); + } + else + { + AddEnvVar("NAT_PUBLIC_IP_AUTO", "false"); + } return args + $" --authrpc.port {authRpc.Number} --ws --ws.addr 0.0.0.0 --ws.port {wsPort.Number}"; } @@ -64,13 +72,6 @@ namespace GethPlugin AddEnvVar("UNLOCK_NUMBER", numberOfAccounts.ToString()); } - private string GetTestNetArgs(GethStartupConfig config) - { - if (config.IsPublicTestNet == null) return string.Empty; - - return $"--nat=extip:{config.IsPublicTestNet.PublicIp}"; - } - private Port CreateDiscoveryPort(GethStartupConfig config) { if (config.IsPublicTestNet == null) return AddInternalPort(DiscoveryPortTag); diff --git a/ProjectPlugins/GethPlugin/GethStartupConfig.cs b/ProjectPlugins/GethPlugin/GethStartupConfig.cs index 0776541..0d6b86e 100644 --- a/ProjectPlugins/GethPlugin/GethStartupConfig.cs +++ b/ProjectPlugins/GethPlugin/GethStartupConfig.cs @@ -42,14 +42,12 @@ public class GethTestNetConfig { - public GethTestNetConfig(string publicIp, int discoveryPort, int listenPort) + public GethTestNetConfig(int discoveryPort, int listenPort) { - PublicIp = publicIp; DiscoveryPort = discoveryPort; ListenPort = listenPort; } - public string PublicIp { get; } public int DiscoveryPort { get; } public int ListenPort { get; } } diff --git a/Tools/CodexNetDeployer/CodexNodeStarter.cs b/Tools/CodexNetDeployer/CodexNodeStarter.cs index e18720e..7b54001 100644 --- a/Tools/CodexNetDeployer/CodexNodeStarter.cs +++ b/Tools/CodexNetDeployer/CodexNodeStarter.cs @@ -105,7 +105,6 @@ namespace CodexNetDeployer return new CodexTestNetConfig { - PublicNatIP = config.PublicIP, PublicDiscoveryPort = Convert.ToInt32(discPort), PublicListenPort = Convert.ToInt32(listenPort) }; diff --git a/Tools/CodexNetDeployer/Configuration.cs b/Tools/CodexNetDeployer/Configuration.cs index 8279f96..da654fa 100644 --- a/Tools/CodexNetDeployer/Configuration.cs +++ b/Tools/CodexNetDeployer/Configuration.cs @@ -86,18 +86,12 @@ namespace CodexNetDeployer [Uniform("public-testnet", "ptn", "PUBLICTESTNET", false, "If true, deployment is created for public exposure. Default is false.")] public bool IsPublicTestNet { get; set; } = false; - [Uniform("public-ip", "pip", "PUBLICIP", false, "Required if public-testnet is true. Public IP address used by nodes for network annoucements.")] - public string PublicIP { get; set; } = string.Empty; - [Uniform("public-discports", "pdps", "PUBLICDISCPORTS", false, "Required if public-testnet is true. Comma-separated port numbers used for discovery. Number must match number of nodes.")] public string PublicDiscPorts { get; set; } = string.Empty; [Uniform("public-listenports", "plps", "PUBLICLISTENPORTS", false, "Required if public-testnet is true. Comma-separated port numbers used for listening. Number must match number of nodes.")] public string PublicListenPorts { get; set; } = string.Empty; - [Uniform("public-gethip", "pgdp", "PUBLICGETHIP", false, "Required if public-testnet is true. Geth's public IP address.")] - public string PublicGethIP { get; set; } = string.Empty; - [Uniform("public-gethdiscport", "pgdp", "PUBLICGETHDISCPORT", false, "Required if public-testnet is true. Single port number used for Geth's public discovery port.")] public int PublicGethDiscPort { get; set; } @@ -150,7 +144,6 @@ namespace CodexNetDeployer if (IsPublicTestNet) { - if (string.IsNullOrEmpty(PublicIP)) errors.Add("Public IP required when deploying public testnet."); if (PublicDiscPorts.Split(",").Length != NumberOfCodexNodes) errors.Add("Number of public discovery-ports provided does not match number of codex nodes."); if (PublicListenPorts.Split(",").Length != NumberOfCodexNodes) errors.Add("Number of public listen-ports provided does not match number of codex nodes."); if (PublicGethDiscPort == 0) errors.Add("Geth public discovery port is not set."); diff --git a/Tools/CodexNetDeployer/Deployer.cs b/Tools/CodexNetDeployer/Deployer.cs index a0cb0ad..30316bd 100644 --- a/Tools/CodexNetDeployer/Deployer.cs +++ b/Tools/CodexNetDeployer/Deployer.cs @@ -113,7 +113,6 @@ namespace CodexNetDeployer if (config.IsPublicTestNet) { s.AsPublicTestNet(new GethTestNetConfig( - publicIp: config.PublicGethIP, discoveryPort: config.PublicGethDiscPort, listenPort: config.PublicGethListenPort )); diff --git a/Tools/CodexNetDeployer/deploy-public-testnet.sh b/Tools/CodexNetDeployer/deploy-public-testnet.sh index 159315a..c25d010 100644 --- a/Tools/CodexNetDeployer/deploy-public-testnet.sh +++ b/Tools/CodexNetDeployer/deploy-public-testnet.sh @@ -16,10 +16,8 @@ dotnet run \ --check-connect=0 \ \ --public-testnet=1 \ - --public-ip=1.2.3.4 \ --public-discports=30010,30020,30030 \ --public-listenports=30011,30021,30031 \ - --public-gethip=1.2.3.5 \ --public-gethdiscport=30040 \ --public-gethlistenport=30041 \ \