cs-codex-dist-tests/GethPlugin/GethContainerRecipe.cs

61 lines
2.3 KiB
C#
Raw Normal View History

2023-09-15 10:36:35 +00:00
using KubernetesWorkflow;
namespace GethPlugin
{
public class GethContainerRecipe : ContainerRecipeFactory
{
private const string defaultArgs = "--ipcdisable --syncmode full";
public const string HttpPortTag = "http_port";
public const string DiscoveryPortTag = "disc_port";
2023-09-15 14:27:08 +00:00
public const string wsPortTag = "ws_port";
2023-09-15 10:36:35 +00:00
public const string AccountsFilename = "accounts.csv";
public override string AppName => "geth";
public override string Image => "codexstorage/dist-tests-geth:latest";
protected override void Initialize(StartupConfig startupConfig)
{
var config = startupConfig.Get<GethStartupConfig>();
var args = CreateArgs(config);
AddEnvVar("GETH_ARGS", args);
}
private string CreateArgs(GethStartupConfig config)
{
var discovery = AddInternalPort(tag: DiscoveryPortTag);
2023-09-15 13:52:02 +00:00
if (config.IsMiner) AddEnvVar("ENABLE_MINER", "1");
2023-09-15 10:36:35 +00:00
UnlockAccounts(0, 1);
2023-09-15 14:27:08 +00:00
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}";
2023-09-15 10:36:35 +00:00
var authRpc = AddInternalPort();
2023-09-15 14:27:08 +00:00
var wsPort = AddInternalPort(tag: wsPortTag);
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;
var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort} --nat=extip:{bootIp}";
args += bootstrapArg;
}
2023-09-15 10:36:35 +00:00
2023-09-15 14:27:08 +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();
if (numberOfAccounts < 1) throw new ArgumentException();
if (startIndex + numberOfAccounts > 1000) throw new ArgumentException("Out of accounts!");
AddEnvVar("UNLOCK_START_INDEX", startIndex.ToString());
AddEnvVar("UNLOCK_NUMBER", numberOfAccounts.ToString());
}
}
}