From a362eb1e962fab3ec88067c3382df97d4de13ca9 Mon Sep 17 00:00:00 2001 From: benbierens Date: Fri, 27 Oct 2023 08:33:07 +0200 Subject: [PATCH] Separate port for geth listening --- .../CodexContractsPlugin/CodexContractsStarter.cs | 5 ++++- ProjectPlugins/GethPlugin/GethContainerRecipe.cs | 11 ++++++++++- ProjectPlugins/GethPlugin/GethStartupConfig.cs | 4 +++- Tools/CodexNetDeployer/Configuration.cs | 4 ++++ Tools/CodexNetDeployer/Deployer.cs | 3 ++- Tools/CodexNetDeployer/deploy-public-testnet.sh | 1 + 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs index 60a7104b..12c28f7a 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs @@ -31,7 +31,10 @@ namespace CodexContractsPlugin try { - return DeployContract(container, workflow, gethNode); + var result = DeployContract(container, workflow, gethNode); + workflow.Stop(containers); + Log("Container stopped."); + return result; } catch (Exception ex) { diff --git a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs index 79329b4f..e74c2c55 100644 --- a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs +++ b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs @@ -9,6 +9,7 @@ namespace GethPlugin public const string HttpPortTag = "http_port"; public const string DiscoveryPortTag = "disc_port"; + public const string ListenPortTag = "listen_port"; public const string WsPortTag = "ws_port"; public const string AuthRpcPortTag = "auth_rpc_port"; public const string AccountsFilename = "accounts.csv"; @@ -32,10 +33,11 @@ namespace GethPlugin var httpPort = CreateApiPort(config, tag: HttpPortTag); var discovery = CreateDiscoveryPort(config); + var listen = CreateListenPort(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} {GetTestNetArgs(config)} {defaultArgs}"; + var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {listen.Number} --discovery.port {discovery.Number} {GetTestNetArgs(config)} {defaultArgs}"; if (config.BootstrapNode != null) { @@ -73,6 +75,13 @@ namespace GethPlugin return AddExposedPort(config.IsPublicTestNet.DiscoveryPort, DiscoveryPortTag, PortProtocol.UDP); } + private Port CreateListenPort(GethStartupConfig config) + { + if (config.IsPublicTestNet == null) return AddInternalPort(ListenPortTag); + + return AddExposedPort(config.IsPublicTestNet.ListenPort, ListenPortTag); + } + private Port CreateP2pPort(GethStartupConfig config, string tag) { if (config.IsPublicTestNet != null) diff --git a/ProjectPlugins/GethPlugin/GethStartupConfig.cs b/ProjectPlugins/GethPlugin/GethStartupConfig.cs index ed6f8063..0776541b 100644 --- a/ProjectPlugins/GethPlugin/GethStartupConfig.cs +++ b/ProjectPlugins/GethPlugin/GethStartupConfig.cs @@ -42,14 +42,16 @@ public class GethTestNetConfig { - public GethTestNetConfig(string publicIp, int discoveryPort) + public GethTestNetConfig(string publicIp, int discoveryPort, int listenPort) { PublicIp = publicIp; DiscoveryPort = discoveryPort; + ListenPort = listenPort; } public string PublicIp { get; } public int DiscoveryPort { get; } + public int ListenPort { get; } } public class GethBootstrapNode diff --git a/Tools/CodexNetDeployer/Configuration.cs b/Tools/CodexNetDeployer/Configuration.cs index f021b120..8279f969 100644 --- a/Tools/CodexNetDeployer/Configuration.cs +++ b/Tools/CodexNetDeployer/Configuration.cs @@ -101,6 +101,9 @@ namespace CodexNetDeployer [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; } + [Uniform("public-gethlistenport", "pglp", "PUBLICGETHLISTENPORT", false, "Required if public-testnet is true. Single port number used for Geth's public listen port.")] + public int PublicGethListenPort { get; set; } + [Uniform("discord-bot", "dbot", "DISCORDBOT", false, "If true, will deploy discord bot. Default is false.")] public bool DeployDiscordBot { get; set; } = false; @@ -151,6 +154,7 @@ namespace CodexNetDeployer 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."); + if (PublicGethListenPort == 0) errors.Add("Geth public listen port is not set."); } if (DeployDiscordBot) diff --git a/Tools/CodexNetDeployer/Deployer.cs b/Tools/CodexNetDeployer/Deployer.cs index 5302d7a7..54b0f819 100644 --- a/Tools/CodexNetDeployer/Deployer.cs +++ b/Tools/CodexNetDeployer/Deployer.cs @@ -114,7 +114,8 @@ namespace CodexNetDeployer { s.AsPublicTestNet(new GethTestNetConfig( publicIp: config.PublicGethIP, - discoveryPort: config.PublicGethDiscPort + discoveryPort: config.PublicGethDiscPort, + listenPort: config.PublicGethListenPort )); } }); diff --git a/Tools/CodexNetDeployer/deploy-public-testnet.sh b/Tools/CodexNetDeployer/deploy-public-testnet.sh index 0b36c0a3..deddff16 100644 --- a/Tools/CodexNetDeployer/deploy-public-testnet.sh +++ b/Tools/CodexNetDeployer/deploy-public-testnet.sh @@ -21,6 +21,7 @@ dotnet run \ --public-listenports=20011,20021,20031 \ --public-gethip=1.2.3.5 \ --public-gethdiscport=20040 \ + --public-gethlistenport=20041 \ \ --discord-bot=1 \ --dbot-token=tokenhere \