Wires up geth public IP and discovery port.

This commit is contained in:
benbierens 2023-10-23 13:19:57 +02:00
parent 020865f5c0
commit a68e849768
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 53 additions and 11 deletions

View File

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

View File

@ -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)

View File

@ -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<string> Validate()
{
var errors = new List<string>();
@ -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;

View File

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

View File

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