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 WorkflowCreator workflowCreator;
|
|
|
|
|
private readonly TestLifecycle lifecycle;
|
|
|
|
|
private readonly GethStartResult gethResult;
|
|
|
|
|
private string bootstrapSpr = "";
|
|
|
|
|
private int validatorsLeft;
|
|
|
|
|
|
2023-06-28 06:48:46 +00:00
|
|
|
|
public CodexNodeStarter(Configuration config, WorkflowCreator workflowCreator, TestLifecycle lifecycle, GethStartResult gethResult, int numberOfValidators)
|
2023-06-23 06:44:27 +00:00
|
|
|
|
{
|
|
|
|
|
this.config = config;
|
|
|
|
|
this.workflowCreator = workflowCreator;
|
|
|
|
|
this.lifecycle = lifecycle;
|
|
|
|
|
this.gethResult = gethResult;
|
|
|
|
|
this.validatorsLeft = numberOfValidators;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RunningContainer? Start(int i)
|
|
|
|
|
{
|
|
|
|
|
Console.Write($" - {i} = ");
|
|
|
|
|
var workflow = workflowCreator.CreateWorkflow();
|
|
|
|
|
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-28 06:48:46 +00:00
|
|
|
|
var codexAccess = new CodexAccess(lifecycle, container);
|
2023-06-23 06:44:27 +00:00
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
var debugInfo = codexAccess.Node.GetDebugInfo();
|
2023-06-23 06:44:27 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
|
|
|
|
|
{
|
2023-06-28 06:48:46 +00:00
|
|
|
|
Console.Write("Online\t");
|
2023-06-23 06:44:27 +00:00
|
|
|
|
|
2023-06-28 06:48:46 +00:00
|
|
|
|
var interaction = gethResult.MarketplaceNetwork.Bootstrap.StartInteraction(lifecycle);
|
|
|
|
|
interaction.MintTestTokens(new[] { account.Account }, config.InitialTestTokens, tokenAddress);
|
|
|
|
|
Console.Write("Tokens minted\t");
|
|
|
|
|
|
|
|
|
|
var response = marketAccess.MakeStorageAvailable(
|
|
|
|
|
totalSpace: (config.StorageQuota!.Value - 1).MB(),
|
|
|
|
|
minPriceForTotalSpace: config.MinPrice.TestTokens(),
|
|
|
|
|
maxCollateral: config.MaxCollateral.TestTokens(),
|
|
|
|
|
maxDuration: TimeSpan.FromSeconds(config.MaxDuration));
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(response))
|
|
|
|
|
{
|
|
|
|
|
Console.Write("Storage available\tOK" + Environment.NewLine);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr;
|
|
|
|
|
validatorsLeft--;
|
|
|
|
|
return container;
|
|
|
|
|
}
|
2023-06-23 06:44:27 +00:00
|
|
|
|
}
|
2023-06-28 06:48:46 +00:00
|
|
|
|
|
|
|
|
|
Console.Write("Unknown failure." + Environment.NewLine);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
return codexStart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|