From 854325f10c60400b95b069fee97b0ec577bb30e2 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 23 Oct 2023 11:23:44 +0200 Subject: [PATCH] Adds option to deploy geth for public testnet. --- .../GethPlugin/GethContainerRecipe.cs | 31 +++++++++++++++---- .../GethPlugin/GethStartupConfig.cs | 8 +++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs index b040564..e26d9a2 100644 --- a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs +++ b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs @@ -10,6 +10,7 @@ namespace GethPlugin public const string HttpPortTag = "http_port"; public const string DiscoveryPortTag = "disc_port"; public const string WsPortTag = "ws_port"; + public const string AuthRpcPortTag = "auth_rpc_port"; public const string AccountsFilename = "accounts.csv"; public override string AppName => "geth"; @@ -26,15 +27,15 @@ namespace GethPlugin private string CreateArgs(GethStartupConfig config) { - var discovery = AddInternalPort(tag: DiscoveryPortTag); - if (config.IsMiner) AddEnvVar("ENABLE_MINER", "1"); UnlockAccounts(0, 1); - var httpPort = AddExposedPort(tag: HttpPortTag); - var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {discovery.Number} --discovery.port {discovery.Number} {defaultArgs}"; - var authRpc = AddInternalPort(); - var wsPort = AddInternalPort(tag: WsPortTag); + var httpPort = CreateApiPort(config, tag: HttpPortTag); + var discovery = CreateP2pPort(config, tag: DiscoveryPortTag); + 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}"; if (config.BootstrapNode != null) { @@ -57,5 +58,23 @@ namespace GethPlugin AddEnvVar("UNLOCK_START_INDEX", startIndex.ToString()); AddEnvVar("UNLOCK_NUMBER", numberOfAccounts.ToString()); } + + private Port CreateP2pPort(GethStartupConfig config, string tag) + { + if (config.IsPublicTestNet) + { + return AddExposedPort(tag); + } + return AddInternalPort(tag); + } + + private Port CreateApiPort(GethStartupConfig config, string tag) + { + if (config.IsPublicTestNet) + { + return AddInternalPort(tag); + } + return AddExposedPort(tag); + } } } diff --git a/ProjectPlugins/GethPlugin/GethStartupConfig.cs b/ProjectPlugins/GethPlugin/GethStartupConfig.cs index fb1991a..690a6ba 100644 --- a/ProjectPlugins/GethPlugin/GethStartupConfig.cs +++ b/ProjectPlugins/GethPlugin/GethStartupConfig.cs @@ -5,6 +5,7 @@ IGethSetup IsMiner(); IGethSetup WithBootstrapNode(GethBootstrapNode node); IGethSetup WithName(string name); + IGethSetup AsPublicTestNet(); } public class GethStartupConfig : IGethSetup @@ -12,6 +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 IGethSetup WithBootstrapNode(GethBootstrapNode node) { @@ -30,6 +32,12 @@ IsMiner = true; return this; } + + public IGethSetup AsPublicTestNet() + { + IsPublicTestNet = true; + return this; + } } public class GethBootstrapNode