2023-09-15 10:36:35 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-11-12 09:07:23 +00:00
|
|
|
|
using KubernetesWorkflow.Recipe;
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
|
|
|
|
namespace GethPlugin
|
|
|
|
|
{
|
|
|
|
|
public class GethContainerRecipe : ContainerRecipeFactory
|
|
|
|
|
{
|
2023-09-19 11:58:45 +00:00
|
|
|
|
public static string DockerImage { get; } = "codexstorage/dist-tests-geth:latest";
|
2023-09-15 10:36:35 +00:00
|
|
|
|
private const string defaultArgs = "--ipcdisable --syncmode full";
|
|
|
|
|
|
|
|
|
|
public const string HttpPortTag = "http_port";
|
|
|
|
|
public const string DiscoveryPortTag = "disc_port";
|
2023-10-27 06:33:07 +00:00
|
|
|
|
public const string ListenPortTag = "listen_port";
|
2023-09-22 07:52:30 +00:00
|
|
|
|
public const string WsPortTag = "ws_port";
|
2023-10-23 09:23:44 +00:00
|
|
|
|
public const string AuthRpcPortTag = "auth_rpc_port";
|
2023-09-15 10:36:35 +00:00
|
|
|
|
public const string AccountsFilename = "accounts.csv";
|
|
|
|
|
|
|
|
|
|
public override string AppName => "geth";
|
2023-09-19 11:58:45 +00:00
|
|
|
|
public override string Image => DockerImage;
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
|
|
|
|
protected override void Initialize(StartupConfig startupConfig)
|
|
|
|
|
{
|
|
|
|
|
var config = startupConfig.Get<GethStartupConfig>();
|
|
|
|
|
|
|
|
|
|
var args = CreateArgs(config);
|
|
|
|
|
|
2023-11-27 17:06:04 +00:00
|
|
|
|
SetSchedulingAffinity(notIn: "false");
|
2023-11-23 13:50:54 +00:00
|
|
|
|
SetSystemCriticalPriority();
|
2023-11-14 09:16:00 +00:00
|
|
|
|
|
2023-09-15 10:36:35 +00:00
|
|
|
|
AddEnvVar("GETH_ARGS", args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string CreateArgs(GethStartupConfig config)
|
|
|
|
|
{
|
2023-11-21 09:33:11 +00:00
|
|
|
|
if (config.IsMiner)
|
|
|
|
|
{
|
|
|
|
|
AddEnvVar("ENABLE_MINER", "1");
|
|
|
|
|
UnlockAccounts(0, 1);
|
|
|
|
|
}
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-10-23 09:23:44 +00:00
|
|
|
|
var httpPort = CreateApiPort(config, tag: HttpPortTag);
|
2023-10-23 11:19:57 +00:00
|
|
|
|
var discovery = CreateDiscoveryPort(config);
|
2023-10-27 06:33:07 +00:00
|
|
|
|
var listen = CreateListenPort(config);
|
2023-10-23 09:23:44 +00:00
|
|
|
|
var authRpc = CreateP2pPort(config, tag: AuthRpcPortTag);
|
|
|
|
|
var wsPort = CreateP2pPort(config, tag: WsPortTag);
|
|
|
|
|
|
2023-11-15 13:53:25 +00:00
|
|
|
|
var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {listen.Number} --discovery.port {discovery.Number} {defaultArgs}";
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-09-15 13:52:02 +00:00
|
|
|
|
if (config.BootstrapNode != null)
|
|
|
|
|
{
|
|
|
|
|
var bootPubKey = config.BootstrapNode.PublicKey;
|
|
|
|
|
var bootIp = config.BootstrapNode.IpAddress;
|
|
|
|
|
var bootPort = config.BootstrapNode.Port;
|
2023-11-21 09:33:11 +00:00
|
|
|
|
var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort}";
|
2023-09-15 13:52:02 +00:00
|
|
|
|
args += bootstrapArg;
|
|
|
|
|
}
|
2023-11-15 13:53:25 +00:00
|
|
|
|
if (config.IsPublicTestNet != null)
|
|
|
|
|
{
|
2023-12-11 07:38:31 +00:00
|
|
|
|
AddEnvVar("NAT_PUBLIC_IP_AUTO", PublicIpService.Address);
|
2023-11-15 13:53:25 +00:00
|
|
|
|
}
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-09-22 07:52:30 +00:00
|
|
|
|
return args + $" --authrpc.port {authRpc.Number} --ws --ws.addr 0.0.0.0 --ws.port {wsPort.Number}";
|
2023-09-15 10:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UnlockAccounts(int startIndex, int numberOfAccounts)
|
|
|
|
|
{
|
|
|
|
|
if (startIndex < 0) throw new ArgumentException();
|
2023-11-21 09:33:11 +00:00
|
|
|
|
if (numberOfAccounts < 0) throw new ArgumentException();
|
2023-09-15 10:36:35 +00:00
|
|
|
|
if (startIndex + numberOfAccounts > 1000) throw new ArgumentException("Out of accounts!");
|
|
|
|
|
|
|
|
|
|
AddEnvVar("UNLOCK_START_INDEX", startIndex.ToString());
|
|
|
|
|
AddEnvVar("UNLOCK_NUMBER", numberOfAccounts.ToString());
|
|
|
|
|
}
|
2023-10-23 09:23:44 +00:00
|
|
|
|
|
2023-10-23 11:19:57 +00:00
|
|
|
|
private Port CreateDiscoveryPort(GethStartupConfig config)
|
|
|
|
|
{
|
|
|
|
|
if (config.IsPublicTestNet == null) return AddInternalPort(DiscoveryPortTag);
|
|
|
|
|
|
2023-10-25 12:23:07 +00:00
|
|
|
|
return AddExposedPort(config.IsPublicTestNet.DiscoveryPort, DiscoveryPortTag, PortProtocol.UDP);
|
2023-10-23 11:19:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 06:33:07 +00:00
|
|
|
|
private Port CreateListenPort(GethStartupConfig config)
|
|
|
|
|
{
|
|
|
|
|
if (config.IsPublicTestNet == null) return AddInternalPort(ListenPortTag);
|
|
|
|
|
|
|
|
|
|
return AddExposedPort(config.IsPublicTestNet.ListenPort, ListenPortTag);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 09:23:44 +00:00
|
|
|
|
private Port CreateP2pPort(GethStartupConfig config, string tag)
|
|
|
|
|
{
|
2023-10-23 11:19:57 +00:00
|
|
|
|
if (config.IsPublicTestNet != null)
|
2023-10-23 09:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
return AddExposedPort(tag);
|
|
|
|
|
}
|
|
|
|
|
return AddInternalPort(tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Port CreateApiPort(GethStartupConfig config, string tag)
|
|
|
|
|
{
|
2023-10-23 11:19:57 +00:00
|
|
|
|
if (config.IsPublicTestNet != null)
|
2023-10-23 09:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
return AddInternalPort(tag);
|
|
|
|
|
}
|
|
|
|
|
return AddExposedPort(tag);
|
|
|
|
|
}
|
2023-09-15 10:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|