Merge branch 'feature/codex-net-deployer'
This commit is contained in:
commit
f9a221bad5
|
@ -2,7 +2,6 @@
|
||||||
using DistTestCore.Codex;
|
using DistTestCore.Codex;
|
||||||
using DistTestCore.Marketplace;
|
using DistTestCore.Marketplace;
|
||||||
using KubernetesWorkflow;
|
using KubernetesWorkflow;
|
||||||
using Logging;
|
|
||||||
|
|
||||||
namespace CodexNetDeployer
|
namespace CodexNetDeployer
|
||||||
{
|
{
|
||||||
|
@ -11,19 +10,15 @@ namespace CodexNetDeployer
|
||||||
private readonly Configuration config;
|
private readonly Configuration config;
|
||||||
private readonly WorkflowCreator workflowCreator;
|
private readonly WorkflowCreator workflowCreator;
|
||||||
private readonly TestLifecycle lifecycle;
|
private readonly TestLifecycle lifecycle;
|
||||||
private readonly BaseLog log;
|
|
||||||
private readonly ITimeSet timeSet;
|
|
||||||
private readonly GethStartResult gethResult;
|
private readonly GethStartResult gethResult;
|
||||||
private string bootstrapSpr = "";
|
private string bootstrapSpr = "";
|
||||||
private int validatorsLeft;
|
private int validatorsLeft;
|
||||||
|
|
||||||
public CodexNodeStarter(Configuration config, WorkflowCreator workflowCreator, TestLifecycle lifecycle, BaseLog log, ITimeSet timeSet, GethStartResult gethResult, int numberOfValidators)
|
public CodexNodeStarter(Configuration config, WorkflowCreator workflowCreator, TestLifecycle lifecycle, GethStartResult gethResult, int numberOfValidators)
|
||||||
{
|
{
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.workflowCreator = workflowCreator;
|
this.workflowCreator = workflowCreator;
|
||||||
this.lifecycle = lifecycle;
|
this.lifecycle = lifecycle;
|
||||||
this.log = log;
|
|
||||||
this.timeSet = timeSet;
|
|
||||||
this.gethResult = gethResult;
|
this.gethResult = gethResult;
|
||||||
this.validatorsLeft = numberOfValidators;
|
this.validatorsLeft = numberOfValidators;
|
||||||
}
|
}
|
||||||
|
@ -39,24 +34,39 @@ namespace CodexNetDeployer
|
||||||
var containers = workflow.Start(1, Location.Unspecified, new CodexContainerRecipe(), workflowStartup);
|
var containers = workflow.Start(1, Location.Unspecified, new CodexContainerRecipe(), workflowStartup);
|
||||||
|
|
||||||
var container = containers.Containers.First();
|
var container = containers.Containers.First();
|
||||||
var address = lifecycle.Configuration.GetAddress(container);
|
var codexAccess = new CodexAccess(lifecycle, container);
|
||||||
var codexNode = new CodexNode(log, timeSet, address);
|
|
||||||
var debugInfo = codexNode.GetDebugInfo();
|
|
||||||
|
|
||||||
|
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();
|
||||||
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
|
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
|
||||||
{
|
{
|
||||||
var pod = container.Pod.PodInfo;
|
Console.Write("Online\t");
|
||||||
Console.Write($"Online ({pod.Name} at {pod.Ip} on '{pod.K8SNodeName}')" + Environment.NewLine);
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr;
|
var interaction = gethResult.MarketplaceNetwork.Bootstrap.StartInteraction(lifecycle);
|
||||||
validatorsLeft--;
|
interaction.MintTestTokens(new[] { account.Account }, config.InitialTestTokens, tokenAddress);
|
||||||
return container;
|
Console.Write("Tokens minted\t");
|
||||||
}
|
|
||||||
else
|
var response = marketAccess.MakeStorageAvailable(
|
||||||
{
|
totalSpace: (config.StorageQuota!.Value - 1).MB(),
|
||||||
Console.Write("Unknown failure." + Environment.NewLine);
|
minPriceForTotalSpace: config.MinPrice.TestTokens(),
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.Write("Unknown failure." + Environment.NewLine);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CodexStartupConfig CreateCodexStartupConfig(string bootstrapSpr, int i, int validatorsLeft)
|
private CodexStartupConfig CreateCodexStartupConfig(string bootstrapSpr, int i, int validatorsLeft)
|
||||||
|
|
|
@ -34,6 +34,18 @@ namespace CodexNetDeployer
|
||||||
[Uniform("log-level", "l", "LOGLEVEL", true, "Log level used by each Codex node. [Trace, Debug*, Info, Warn, Error]")]
|
[Uniform("log-level", "l", "LOGLEVEL", true, "Log level used by each Codex node. [Trace, Debug*, Info, Warn, Error]")]
|
||||||
public CodexLogLevel CodexLogLevel { get; set; } = CodexLogLevel.Debug;
|
public CodexLogLevel CodexLogLevel { get; set; } = CodexLogLevel.Debug;
|
||||||
|
|
||||||
|
[Uniform("test-tokens", "tt", "TESTTOKENS", true, "Initial amount of test-tokens minted for each Codex node.")]
|
||||||
|
public int InitialTestTokens { get; set; } = int.MaxValue;
|
||||||
|
|
||||||
|
[Uniform("min-price", "mp", "MINPRICE", true, "Minimum price for the storage space for which contracts will be accepted.")]
|
||||||
|
public int MinPrice { get; set; }
|
||||||
|
|
||||||
|
[Uniform("max-collateral", "mc", "MAXCOLLATERAL", true, "Maximum collateral that will be placed for the total storage space.")]
|
||||||
|
public int MaxCollateral { get; set; }
|
||||||
|
|
||||||
|
[Uniform("max-duration", "md", "MAXDURATION", true, "Maximum duration in seconds for contracts which will be accepted.")]
|
||||||
|
public int MaxDuration { get; set; }
|
||||||
|
|
||||||
public TestRunnerLocation RunnerLocation { get; set; } = TestRunnerLocation.InternalToCluster;
|
public TestRunnerLocation RunnerLocation { get; set; } = TestRunnerLocation.InternalToCluster;
|
||||||
|
|
||||||
public List<string> Validate()
|
public List<string> Validate()
|
||||||
|
@ -59,6 +71,7 @@ namespace CodexNetDeployer
|
||||||
{
|
{
|
||||||
if (p.PropertyType == typeof(string)) onString(p.Name, (string)p.GetValue(this)!);
|
if (p.PropertyType == typeof(string)) onString(p.Name, (string)p.GetValue(this)!);
|
||||||
if (p.PropertyType == typeof(int?)) onInt(p.Name, (int?)p.GetValue(this)!);
|
if (p.PropertyType == typeof(int?)) onInt(p.Name, (int?)p.GetValue(this)!);
|
||||||
|
if (p.PropertyType == typeof(int)) onInt(p.Name, (int)p.GetValue(this)!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace CodexNetDeployer
|
||||||
Log("Starting Codex nodes...");
|
Log("Starting Codex nodes...");
|
||||||
|
|
||||||
// Each node must have its own IP, so it needs it own pod. Start them 1 at a time.
|
// Each node must have its own IP, so it needs it own pod. Start them 1 at a time.
|
||||||
var codexStarter = new CodexNodeStarter(config, workflowCreator, lifecycle, log, timeset, gethResults, config.NumberOfValidators!.Value);
|
var codexStarter = new CodexNodeStarter(config, workflowCreator, lifecycle, gethResults, config.NumberOfValidators!.Value);
|
||||||
var codexContainers = new List<RunningContainer>();
|
var codexContainers = new List<RunningContainer>();
|
||||||
for (var i = 0; i < config.NumberOfCodexNodes; i++)
|
for (var i = 0; i < config.NumberOfCodexNodes; i++)
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,11 @@ namespace CodexNetDeployer
|
||||||
numberOfCodexNodes: config.NumberOfCodexNodes!.Value,
|
numberOfCodexNodes: config.NumberOfCodexNodes!.Value,
|
||||||
numberOfValidators: config.NumberOfValidators!.Value,
|
numberOfValidators: config.NumberOfValidators!.Value,
|
||||||
storageQuotaMB: config.StorageQuota!.Value,
|
storageQuotaMB: config.StorageQuota!.Value,
|
||||||
codexLogLevel: config.CodexLogLevel);
|
codexLogLevel: config.CodexLogLevel,
|
||||||
|
initialTestTokens: config.InitialTestTokens,
|
||||||
|
minPrice: config.MinPrice,
|
||||||
|
maxCollateral: config.MaxCollateral,
|
||||||
|
maxDuration: config.MaxDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Log(string msg)
|
private void Log(string msg)
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace DistTestCore.Codex
|
||||||
|
|
||||||
public class DeploymentMetadata
|
public class DeploymentMetadata
|
||||||
{
|
{
|
||||||
public DeploymentMetadata(string codexImage, string gethImage, string contractsImage, string kubeNamespace, int numberOfCodexNodes, int numberOfValidators, int storageQuotaMB, CodexLogLevel codexLogLevel)
|
public DeploymentMetadata(string codexImage, string gethImage, string contractsImage, string kubeNamespace, int numberOfCodexNodes, int numberOfValidators, int storageQuotaMB, CodexLogLevel codexLogLevel, int initialTestTokens, int minPrice, int maxCollateral, int maxDuration)
|
||||||
{
|
{
|
||||||
DeployDateTimeUtc = DateTime.UtcNow;
|
DeployDateTimeUtc = DateTime.UtcNow;
|
||||||
CodexImage = codexImage;
|
CodexImage = codexImage;
|
||||||
|
@ -30,8 +30,12 @@ namespace DistTestCore.Codex
|
||||||
NumberOfValidators = numberOfValidators;
|
NumberOfValidators = numberOfValidators;
|
||||||
StorageQuotaMB = storageQuotaMB;
|
StorageQuotaMB = storageQuotaMB;
|
||||||
CodexLogLevel = codexLogLevel;
|
CodexLogLevel = codexLogLevel;
|
||||||
|
InitialTestTokens = initialTestTokens;
|
||||||
|
MinPrice = minPrice;
|
||||||
|
MaxCollateral = maxCollateral;
|
||||||
|
MaxDuration = maxDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CodexImage { get; }
|
public string CodexImage { get; }
|
||||||
public DateTime DeployDateTimeUtc { get; }
|
public DateTime DeployDateTimeUtc { get; }
|
||||||
public string GethImage { get; }
|
public string GethImage { get; }
|
||||||
|
@ -41,5 +45,9 @@ namespace DistTestCore.Codex
|
||||||
public int NumberOfValidators { get; }
|
public int NumberOfValidators { get; }
|
||||||
public int StorageQuotaMB { get; }
|
public int StorageQuotaMB { get; }
|
||||||
public CodexLogLevel CodexLogLevel { get; }
|
public CodexLogLevel CodexLogLevel { get; }
|
||||||
|
public int InitialTestTokens { get; }
|
||||||
|
public int MinPrice { get; }
|
||||||
|
public int MaxCollateral { get; }
|
||||||
|
public int MaxDuration { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,19 +62,19 @@ namespace DistTestCore.Marketplace
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration)
|
public string MakeStorageAvailable(ByteSize totalSpace, TestToken minPriceForTotalSpace, TestToken maxCollateral, TimeSpan maxDuration)
|
||||||
{
|
{
|
||||||
var request = new CodexSalesAvailabilityRequest
|
var request = new CodexSalesAvailabilityRequest
|
||||||
{
|
{
|
||||||
size = ToHexBigInt(size.SizeInBytes),
|
size = ToHexBigInt(totalSpace.SizeInBytes),
|
||||||
duration = ToHexBigInt(maxDuration.TotalSeconds),
|
duration = ToHexBigInt(maxDuration.TotalSeconds),
|
||||||
maxCollateral = ToHexBigInt(maxCollateral),
|
maxCollateral = ToHexBigInt(maxCollateral),
|
||||||
minPrice = ToHexBigInt(minPricePerBytePerSecond)
|
minPrice = ToHexBigInt(minPriceForTotalSpace)
|
||||||
};
|
};
|
||||||
|
|
||||||
Log($"Making storage available... (" +
|
Log($"Making storage available... (" +
|
||||||
$"size: {size}, " +
|
$"size: {totalSpace}, " +
|
||||||
$"minPricePerBytePerSecond: {minPricePerBytePerSecond}, " +
|
$"minPricePerBytePerSecond: {minPriceForTotalSpace}, " +
|
||||||
$"maxCollateral: {maxCollateral}, " +
|
$"maxCollateral: {maxCollateral}, " +
|
||||||
$"maxDuration: {Time.FormatDuration(maxDuration)})");
|
$"maxDuration: {Time.FormatDuration(maxDuration)})");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue