2023-06-23 06:44:27 +00:00
|
|
|
|
using DistTestCore;
|
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using DistTestCore.Marketplace;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
|
|
|
|
|
namespace CodexNetDeployer
|
|
|
|
|
{
|
|
|
|
|
public class CodexNodeStarter
|
|
|
|
|
{
|
|
|
|
|
private readonly Configuration config;
|
|
|
|
|
private readonly TestLifecycle lifecycle;
|
|
|
|
|
private readonly GethStartResult gethResult;
|
|
|
|
|
private string bootstrapSpr = "";
|
|
|
|
|
private int validatorsLeft;
|
|
|
|
|
|
2023-08-10 08:58:18 +00:00
|
|
|
|
public CodexNodeStarter(Configuration config, TestLifecycle lifecycle, GethStartResult gethResult, int numberOfValidators)
|
2023-06-23 06:44:27 +00:00
|
|
|
|
{
|
|
|
|
|
this.config = config;
|
|
|
|
|
this.lifecycle = lifecycle;
|
|
|
|
|
this.gethResult = gethResult;
|
2023-07-11 08:59:41 +00:00
|
|
|
|
validatorsLeft = numberOfValidators;
|
2023-06-23 06:44:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 09:32:32 +00:00
|
|
|
|
public CodexNodeStartResult? Start(int i)
|
2023-06-23 06:44:27 +00:00
|
|
|
|
{
|
|
|
|
|
Console.Write($" - {i} = ");
|
2023-08-10 08:58:18 +00:00
|
|
|
|
var workflow = lifecycle.WorkflowCreator.CreateWorkflow();
|
2023-06-23 06:44:27 +00:00
|
|
|
|
var workflowStartup = new StartupConfig();
|
|
|
|
|
workflowStartup.Add(gethResult);
|
|
|
|
|
workflowStartup.Add(CreateCodexStartupConfig(bootstrapSpr, i, validatorsLeft));
|
|
|
|
|
|
|
|
|
|
var containers = workflow.Start(1, Location.Unspecified, new CodexContainerRecipe(), workflowStartup);
|
|
|
|
|
|
|
|
|
|
var container = containers.Containers.First();
|
2023-06-29 14:07:49 +00:00
|
|
|
|
var codexAccess = new CodexAccess(lifecycle.Log, container, lifecycle.TimeSet, lifecycle.Configuration.GetAddress(container));
|
2023-06-28 06:48:46 +00:00
|
|
|
|
var account = gethResult.MarketplaceNetwork.Bootstrap.AllAccounts.Accounts[i];
|
|
|
|
|
var tokenAddress = gethResult.MarketplaceNetwork.Marketplace.TokenAddress;
|
|
|
|
|
var marketAccess = new MarketplaceAccess(lifecycle, gethResult.MarketplaceNetwork, account, codexAccess);
|
|
|
|
|
|
2023-06-29 08:23:04 +00:00
|
|
|
|
try
|
2023-06-23 06:44:27 +00:00
|
|
|
|
{
|
2023-06-29 14:07:49 +00:00
|
|
|
|
var debugInfo = codexAccess.GetDebugInfo();
|
2023-06-29 08:23:04 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
|
|
|
|
|
{
|
|
|
|
|
Console.Write("Online\t");
|
2023-06-23 06:44:27 +00:00
|
|
|
|
|
2023-06-29 08:23:04 +00:00
|
|
|
|
var interaction = gethResult.MarketplaceNetwork.Bootstrap.StartInteraction(lifecycle);
|
|
|
|
|
interaction.MintTestTokens(new[] { account.Account }, config.InitialTestTokens, tokenAddress);
|
|
|
|
|
Console.Write("Tokens minted\t");
|
2023-06-28 06:48:46 +00:00
|
|
|
|
|
2023-06-29 08:23:04 +00:00
|
|
|
|
var response = marketAccess.MakeStorageAvailable(
|
2023-06-29 09:05:58 +00:00
|
|
|
|
totalSpace: config.StorageSell!.Value.MB(),
|
2023-06-29 08:23:04 +00:00
|
|
|
|
minPriceForTotalSpace: config.MinPrice.TestTokens(),
|
|
|
|
|
maxCollateral: config.MaxCollateral.TestTokens(),
|
|
|
|
|
maxDuration: TimeSpan.FromSeconds(config.MaxDuration));
|
2023-06-28 06:48:46 +00:00
|
|
|
|
|
2023-06-29 08:23:04 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(response))
|
|
|
|
|
{
|
|
|
|
|
Console.Write("Storage available\tOK" + Environment.NewLine);
|
2023-06-28 06:48:46 +00:00
|
|
|
|
|
2023-06-29 08:23:04 +00:00
|
|
|
|
if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr;
|
|
|
|
|
validatorsLeft--;
|
2023-08-28 09:53:59 +00:00
|
|
|
|
return new CodexNodeStartResult(workflow, container, codexAccess);
|
2023-06-29 08:23:04 +00:00
|
|
|
|
}
|
2023-06-28 06:48:46 +00:00
|
|
|
|
}
|
2023-06-23 06:44:27 +00:00
|
|
|
|
}
|
2023-06-29 08:23:04 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Exception:" + ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.Write("Unknown failure. Downloading container log." + Environment.NewLine);
|
|
|
|
|
lifecycle.DownloadLog(container);
|
2023-06-28 06:48:46 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
2023-06-23 06:44:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CodexStartupConfig CreateCodexStartupConfig(string bootstrapSpr, int i, int validatorsLeft)
|
|
|
|
|
{
|
|
|
|
|
var codexStart = new CodexStartupConfig(config.CodexLogLevel);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(bootstrapSpr)) codexStart.BootstrapSpr = bootstrapSpr;
|
|
|
|
|
codexStart.StorageQuota = config.StorageQuota!.Value.MB();
|
|
|
|
|
var marketplaceConfig = new MarketplaceInitialConfig(100000.Eth(), 0.TestTokens(), validatorsLeft > 0);
|
|
|
|
|
marketplaceConfig.AccountIndexOverride = i;
|
|
|
|
|
codexStart.MarketplaceConfig = marketplaceConfig;
|
2023-08-13 07:07:23 +00:00
|
|
|
|
codexStart.MetricsMode = config.Metrics;
|
2023-07-11 10:21:48 +00:00
|
|
|
|
|
2023-06-29 14:03:45 +00:00
|
|
|
|
if (config.BlockTTL != Configuration.SecondsIn1Day)
|
|
|
|
|
{
|
|
|
|
|
codexStart.BlockTTL = config.BlockTTL;
|
|
|
|
|
}
|
2023-08-23 06:29:16 +00:00
|
|
|
|
if (config.BlockMI != Configuration.TenMinutes)
|
|
|
|
|
{
|
|
|
|
|
codexStart.BlockMaintenanceInterval = TimeSpan.FromSeconds(config.BlockMI);
|
|
|
|
|
}
|
|
|
|
|
if (config.BlockMN != 1000)
|
|
|
|
|
{
|
|
|
|
|
codexStart.BlockMaintenanceNumber = config.BlockMN;
|
|
|
|
|
}
|
2023-06-23 06:44:27 +00:00
|
|
|
|
|
|
|
|
|
return codexStart;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-24 09:32:32 +00:00
|
|
|
|
|
|
|
|
|
public class CodexNodeStartResult
|
|
|
|
|
{
|
2023-08-28 09:53:59 +00:00
|
|
|
|
public CodexNodeStartResult(StartupWorkflow workflow, RunningContainer container, CodexAccess access)
|
2023-08-24 09:32:32 +00:00
|
|
|
|
{
|
2023-08-28 09:53:59 +00:00
|
|
|
|
Workflow = workflow;
|
2023-08-24 09:32:32 +00:00
|
|
|
|
Container = container;
|
|
|
|
|
Access = access;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 09:53:59 +00:00
|
|
|
|
public StartupWorkflow Workflow { get; }
|
2023-08-24 09:32:32 +00:00
|
|
|
|
public RunningContainer Container { get; }
|
|
|
|
|
public CodexAccess Access { get; }
|
|
|
|
|
}
|
2023-06-23 06:44:27 +00:00
|
|
|
|
}
|