Adds option to deploy codex in a public test net.

This commit is contained in:
benbierens 2023-10-23 12:33:48 +02:00
parent 840e794761
commit bcb690d143
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 32 additions and 21 deletions

View File

@ -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)
{
if (config.IsPublicTestNet)
{
return AddExposedPort(tag);
}
return AddInternalPort(tag);
}
private Port CreateApiPort(CodexStartupConfig config, string tag)
{
if (config.IsPublicTestNet)
if (config.PublicTestNet == null)
{
return AddInternalPort(tag);
}
return AddExposedPort(tag);
}
return AddInternalPort(tag);
}
}
}

View File

@ -22,7 +22,7 @@ namespace CodexPlugin
/// Provides an invalid proof every N proofs
/// </summary>
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<string> 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}";

View File

@ -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; }
}
}