From bcb690d143a79e7a0e85b8653e93b794de0b4ced Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 23 Oct 2023 12:33:48 +0200 Subject: [PATCH] Adds option to deploy codex in a public test net. --- .../CodexPlugin/CodexContainerRecipe.cs | 36 ++++++++++--------- ProjectPlugins/CodexPlugin/CodexSetup.cs | 8 ++--- .../CodexPlugin/CodexStartupConfig.cs | 9 ++++- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs index 533698a..1397303 100644 --- a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs +++ b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs @@ -37,14 +37,13 @@ namespace CodexPlugin AddEnvVar("CODEX_DATA_DIR", dataDir); AddVolume($"codex/{dataDir}", GetVolumeCapacity(config)); - var discPort = CreateP2pPort(config, DiscoveryPortTag); + var discPort = CreateDiscoveryPort(config); AddEnvVar("CODEX_DISC_PORT", discPort); AddEnvVar("CODEX_LOG_LEVEL", config.LogLevelWithTopics()); - if (config.IsPublicTestNet) + if (config.PublicTestNet != null) { - todo - AddEnvVar("CODEX_NAT", "required"); + AddEnvVar("CODEX_NAT", config.PublicTestNet.PublicNatIP); } else { @@ -52,7 +51,7 @@ namespace CodexPlugin AddEnvVar("NAT_IP_AUTO", "true"); } - var listenPort = CreateP2pPort(config, ListenPortTag); + var listenPort = CreateListenPort(config); AddEnvVar("CODEX_LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{listenPort.Number}"); if (!string.IsNullOrEmpty(config.BootstrapSpr)) @@ -120,6 +119,20 @@ namespace CodexPlugin } } + private Port CreateListenPort(CodexStartupConfig config) + { + if (config.PublicTestNet == null) return AddInternalPort(ListenPortTag); + + return AddExposedPort(config.PublicTestNet.PublicListenPort, ListenPortTag); + } + + private Port CreateDiscoveryPort(CodexStartupConfig config) + { + if (config.PublicTestNet == null) return AddInternalPort(DiscoveryPortTag); + + return AddExposedPort(config.PublicTestNet.PublicDiscoveryPort, DiscoveryPortTag); + } + private ByteSize GetVolumeCapacity(CodexStartupConfig config) { if (config.StorageQuota != null) return config.StorageQuota; @@ -135,22 +148,13 @@ namespace CodexPlugin return DefaultDockerImage; } - private Port CreateP2pPort(CodexStartupConfig config, string tag) + private Port CreateApiPort(CodexStartupConfig config, string tag) { - if (config.IsPublicTestNet) + if (config.PublicTestNet == null) { return AddExposedPort(tag); } return AddInternalPort(tag); } - - private Port CreateApiPort(CodexStartupConfig config, string tag) - { - if (config.IsPublicTestNet) - { - return AddInternalPort(tag); - } - return AddExposedPort(tag); - } } } diff --git a/ProjectPlugins/CodexPlugin/CodexSetup.cs b/ProjectPlugins/CodexPlugin/CodexSetup.cs index 6240fb8..8b7dbb1 100644 --- a/ProjectPlugins/CodexPlugin/CodexSetup.cs +++ b/ProjectPlugins/CodexPlugin/CodexSetup.cs @@ -22,7 +22,7 @@ namespace CodexPlugin /// Provides an invalid proof every N proofs /// ICodexSetup WithSimulateProofFailures(uint failEveryNProofs); - ICodexSetup AsPublicTestNet(); + ICodexSetup AsPublicTestNet(CodexTestNetConfig testNetConfig); } public class CodexLogCustomTopics @@ -119,9 +119,9 @@ namespace CodexPlugin return this; } - public ICodexSetup AsPublicTestNet() + public ICodexSetup AsPublicTestNet(CodexTestNetConfig testNetConfig) { - IsPublicTestNet = true; + PublicTestNet = testNetConfig; return this; } @@ -133,7 +133,7 @@ namespace CodexPlugin private IEnumerable DescribeArgs() { - if (IsPublicTestNet) yield return "Public TestNet"; + if (PublicTestNet != null) yield return $"Public TestNet at {PublicTestNet.PublicNatIP}:{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 3de9c4b..6e59f2a 100644 --- a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs +++ b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs @@ -18,7 +18,7 @@ namespace CodexPlugin public bool? EnableValidator { get; set; } public TimeSpan? BlockMaintenanceInterval { get; set; } public int? BlockMaintenanceNumber { get; set; } - public bool IsPublicTestNet { get; set; } = false; + public CodexTestNetConfig? PublicTestNet { get; set; } public string LogLevelWithTopics() { @@ -62,4 +62,11 @@ namespace CodexPlugin return level; } } + + public class CodexTestNetConfig + { + public string PublicNatIP { get; set; } = string.Empty; + public int PublicDiscoveryPort { get; set; } + public int PublicListenPort { get; set; } + } }