From a68e849768fc4d629de694c2a67b9a6755f81a96 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 23 Oct 2023 13:19:57 +0200 Subject: [PATCH] Wires up geth public IP and discovery port. --- .../GethPlugin/GethContainerRecipe.cs | 22 +++++++++++++++---- .../GethPlugin/GethStartupConfig.cs | 20 +++++++++++++---- Tools/CodexNetDeployer/Configuration.cs | 9 +++++++- Tools/CodexNetDeployer/Deployer.cs | 9 +++++++- .../CodexNetDeployer/deploy-public-testnet.sh | 4 +++- 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs index e26d9a2..b98ebc0 100644 --- a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs +++ b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs @@ -31,11 +31,11 @@ namespace GethPlugin UnlockAccounts(0, 1); var httpPort = CreateApiPort(config, tag: HttpPortTag); - var discovery = CreateP2pPort(config, tag: DiscoveryPortTag); + var discovery = CreateDiscoveryPort(config); 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 {discovery.Number} --discovery.port {discovery.Number} {defaultArgs}"; + var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {discovery.Number} --discovery.port {discovery.Number} {GetTestNetArgs(config)} {defaultArgs}"; if (config.BootstrapNode != null) { @@ -59,9 +59,23 @@ 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); + + return AddExposedPort(config.IsPublicTestNet.DiscoveryPort, DiscoveryPortTag); + } + private Port CreateP2pPort(GethStartupConfig config, string tag) { - if (config.IsPublicTestNet) + if (config.IsPublicTestNet != null) { return AddExposedPort(tag); } @@ -70,7 +84,7 @@ namespace GethPlugin private Port CreateApiPort(GethStartupConfig config, string tag) { - if (config.IsPublicTestNet) + if (config.IsPublicTestNet != null) { return AddInternalPort(tag); } diff --git a/ProjectPlugins/GethPlugin/GethStartupConfig.cs b/ProjectPlugins/GethPlugin/GethStartupConfig.cs index 690a6ba..ed6f806 100644 --- a/ProjectPlugins/GethPlugin/GethStartupConfig.cs +++ b/ProjectPlugins/GethPlugin/GethStartupConfig.cs @@ -5,7 +5,7 @@ IGethSetup IsMiner(); IGethSetup WithBootstrapNode(GethBootstrapNode node); IGethSetup WithName(string name); - IGethSetup AsPublicTestNet(); + IGethSetup AsPublicTestNet(GethTestNetConfig gethTestNetConfig); } public class GethStartupConfig : IGethSetup @@ -13,7 +13,7 @@ public bool IsMiner { get; private set; } public GethBootstrapNode? BootstrapNode { get; private set; } public string? NameOverride { get; private set; } - public bool IsPublicTestNet { get; private set; } = false; + public GethTestNetConfig? IsPublicTestNet { get; private set; } public IGethSetup WithBootstrapNode(GethBootstrapNode node) { @@ -33,13 +33,25 @@ return this; } - public IGethSetup AsPublicTestNet() + public IGethSetup AsPublicTestNet(GethTestNetConfig gethTestNetConfig) { - IsPublicTestNet = true; + IsPublicTestNet = gethTestNetConfig; return this; } } + public class GethTestNetConfig + { + public GethTestNetConfig(string publicIp, int discoveryPort) + { + PublicIp = publicIp; + DiscoveryPort = discoveryPort; + } + + public string PublicIp { get; } + public int DiscoveryPort { get; } + } + public class GethBootstrapNode { public GethBootstrapNode(string publicKey, string ipAddress, int port) diff --git a/Tools/CodexNetDeployer/Configuration.cs b/Tools/CodexNetDeployer/Configuration.cs index 2d7d295..4da2673 100644 --- a/Tools/CodexNetDeployer/Configuration.cs +++ b/Tools/CodexNetDeployer/Configuration.cs @@ -86,7 +86,7 @@ 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 used by nodes for network annoucements.")] + [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.")] @@ -95,6 +95,12 @@ namespace CodexNetDeployer [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; } + public List Validate() { var errors = new List(); @@ -120,6 +126,7 @@ namespace CodexNetDeployer 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."); } return errors; diff --git a/Tools/CodexNetDeployer/Deployer.cs b/Tools/CodexNetDeployer/Deployer.cs index 3273909..dfde03f 100644 --- a/Tools/CodexNetDeployer/Deployer.cs +++ b/Tools/CodexNetDeployer/Deployer.cs @@ -104,7 +104,14 @@ namespace CodexNetDeployer { s.IsMiner(); s.WithName("geth"); - if (config.IsPublicTestNet) s.AsPublicTestNet(); + + if (config.IsPublicTestNet) + { + s.AsPublicTestNet(new GethTestNetConfig( + publicIp: config.PublicGethIP, + discoveryPort: config.PublicGethDiscPort + )); + } }); } diff --git a/Tools/CodexNetDeployer/deploy-public-testnet.sh b/Tools/CodexNetDeployer/deploy-public-testnet.sh index 7bb70cb..53fb267 100644 --- a/Tools/CodexNetDeployer/deploy-public-testnet.sh +++ b/Tools/CodexNetDeployer/deploy-public-testnet.sh @@ -17,4 +17,6 @@ dotnet run \ --public-testnet=1 \ --public-ip=1.2.3.4 \ --public-discports=20010,20020,20030 \ - --public-listenports=20011,20021,20031 + --public-listenports=20011,20021,20031 \ + --public-gethip=1.2.3.5 \ + --public-gethdiscport=20040