2023-04-14 07:54:07 +00:00
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
|
|
|
|
|
namespace DistTestCore.Marketplace
|
|
|
|
|
{
|
|
|
|
|
public class GethContainerRecipe : ContainerRecipeFactory
|
|
|
|
|
{
|
2023-07-17 09:12:14 +00:00
|
|
|
|
private const string defaultArgs = "--ipcdisable --syncmode full";
|
2023-05-03 08:21:15 +00:00
|
|
|
|
|
2023-04-14 08:51:35 +00:00
|
|
|
|
public const string HttpPortTag = "http_port";
|
2023-04-17 08:31:14 +00:00
|
|
|
|
public const string DiscoveryPortTag = "disc_port";
|
2023-05-03 08:21:15 +00:00
|
|
|
|
public const string AccountsFilename = "accounts.csv";
|
2023-04-26 09:12:33 +00:00
|
|
|
|
|
2023-07-17 09:12:14 +00:00
|
|
|
|
public override string Image { get; }
|
|
|
|
|
|
|
|
|
|
public GethContainerRecipe()
|
|
|
|
|
{
|
2023-07-31 07:16:52 +00:00
|
|
|
|
Image = "codexstorage/dist-tests-geth:sha-b788a2d";
|
2023-07-17 09:12:14 +00:00
|
|
|
|
}
|
2023-04-14 07:54:07 +00:00
|
|
|
|
|
|
|
|
|
protected override void Initialize(StartupConfig startupConfig)
|
|
|
|
|
{
|
|
|
|
|
var config = startupConfig.Get<GethStartupConfig>();
|
|
|
|
|
|
|
|
|
|
var args = CreateArgs(config);
|
|
|
|
|
|
|
|
|
|
AddEnvVar("GETH_ARGS", args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string CreateArgs(GethStartupConfig config)
|
|
|
|
|
{
|
2023-04-17 08:31:14 +00:00
|
|
|
|
var discovery = AddInternalPort(tag: DiscoveryPortTag);
|
|
|
|
|
|
2023-04-14 07:54:07 +00:00
|
|
|
|
if (config.IsBootstrapNode)
|
|
|
|
|
{
|
2023-04-21 07:11:45 +00:00
|
|
|
|
return CreateBootstapArgs(discovery);
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 07:11:45 +00:00
|
|
|
|
return CreateCompanionArgs(discovery, config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string CreateBootstapArgs(Port discovery)
|
|
|
|
|
{
|
2023-05-03 08:21:15 +00:00
|
|
|
|
AddEnvVar("ENABLE_MINER", "1");
|
|
|
|
|
UnlockAccounts(0, 1);
|
2023-04-21 07:11:45 +00:00
|
|
|
|
var exposedPort = AddExposedPort(tag: HttpPortTag);
|
2023-04-25 12:58:19 +00:00
|
|
|
|
return $"--http.port {exposedPort.Number} --port {discovery.Number} --discovery.port {discovery.Number} {defaultArgs}";
|
2023-04-21 07:11:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string CreateCompanionArgs(Port discovery, GethStartupConfig config)
|
|
|
|
|
{
|
2023-05-03 08:21:15 +00:00
|
|
|
|
UnlockAccounts(
|
|
|
|
|
config.CompanionAccountStartIndex + 1,
|
|
|
|
|
config.NumberOfCompanionAccounts);
|
2023-04-26 09:12:33 +00:00
|
|
|
|
|
2023-04-14 07:54:07 +00:00
|
|
|
|
var port = AddInternalPort();
|
|
|
|
|
var authRpc = AddInternalPort();
|
2023-04-24 12:09:23 +00:00
|
|
|
|
var httpPort = AddExposedPort(tag: HttpPortTag);
|
2023-04-17 08:31:14 +00:00
|
|
|
|
|
|
|
|
|
var bootPubKey = config.BootstrapNode.PubKey;
|
2023-06-02 08:04:07 +00:00
|
|
|
|
var bootIp = config.BootstrapNode.RunningContainers.Containers[0].Pod.PodInfo.Ip;
|
2023-04-17 08:31:14 +00:00
|
|
|
|
var bootPort = config.BootstrapNode.DiscoveryPort.Number;
|
2023-04-25 12:58:19 +00:00
|
|
|
|
var bootstrapArg = $"--bootnodes enode://{bootPubKey}@{bootIp}:{bootPort} --nat=extip:{bootIp}";
|
2023-04-17 08:31:14 +00:00
|
|
|
|
|
2023-04-25 12:58:19 +00:00
|
|
|
|
return $"--port {port.Number} --discovery.port {discovery.Number} --authrpc.port {authRpc.Number} --http.addr 0.0.0.0 --http.port {httpPort.Number} --ws --ws.addr 0.0.0.0 --ws.port {httpPort.Number} {bootstrapArg} {defaultArgs}";
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
2023-05-03 08:21:15 +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());
|
|
|
|
|
}
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|