diff --git a/CodexNetDeployer/ArgOrVar.cs b/CodexNetDeployer/ArgOrVar.cs index 90c34ae..f4e35cd 100644 --- a/CodexNetDeployer/ArgOrVar.cs +++ b/CodexNetDeployer/ArgOrVar.cs @@ -8,6 +8,7 @@ public static readonly ArgVar KubeConfigFile = new ArgVar("kube-config", "KUBECONFIG", "Path to Kubeconfig file."); public static readonly ArgVar KubeNamespace = new ArgVar("kube-namespace", "KUBENAMESPACE", "Kubernetes namespace to be used for deployment."); public static readonly ArgVar NumberOfCodexNodes = new ArgVar("nodes", "NODES", "Number of Codex nodes to be created."); + public static readonly ArgVar NumberOfValidatorNodes = new ArgVar("validators", "VALIDATORS", "Number of Codex nodes that will be validating."); public static readonly ArgVar StorageQuota = new ArgVar("storage-quota", "STORAGEQUOTA", "Storage quota in megabytes used by each Codex node."); public static readonly ArgVar LogLevel = new ArgVar("log-level", "LOGLEVEL", "Log level used by each Codex node. [Trace, Debug*, Info, Warn, Error]"); diff --git a/CodexNetDeployer/Configuration.cs b/CodexNetDeployer/Configuration.cs index 3e5346c..2383047 100644 --- a/CodexNetDeployer/Configuration.cs +++ b/CodexNetDeployer/Configuration.cs @@ -12,6 +12,7 @@ namespace CodexNetDeployer string kubeConfigFile, string kubeNamespace, int? numberOfCodexNodes, + int? numberOfValidators, int? storageQuota, CodexLogLevel codexLogLevel, TestRunnerLocation runnerLocation) @@ -22,6 +23,7 @@ namespace CodexNetDeployer KubeConfigFile = kubeConfigFile; KubeNamespace = kubeNamespace; NumberOfCodexNodes = numberOfCodexNodes; + NumberOfValidators = numberOfValidators; StorageQuota = storageQuota; CodexLogLevel = codexLogLevel; RunnerLocation = runnerLocation; @@ -33,6 +35,7 @@ namespace CodexNetDeployer public string KubeConfigFile { get; } public string KubeNamespace { get; } public int? NumberOfCodexNodes { get; } + public int? NumberOfValidators { get; } public int? StorageQuota { get; } public CodexLogLevel CodexLogLevel { get; } public TestRunnerLocation RunnerLocation { get; } @@ -50,6 +53,11 @@ namespace CodexNetDeployer onString: (n, v) => StringIsSet(n, v, errors), onInt: (n, v) => IntIsOverZero(n, v, errors)); + if (NumberOfValidators > NumberOfCodexNodes) + { + errors.Add($"{nameof(NumberOfValidators)} ({NumberOfValidators}) may not be greater than {nameof(NumberOfCodexNodes)} ({NumberOfCodexNodes})."); + } + return errors; } diff --git a/CodexNetDeployer/Deployer.cs b/CodexNetDeployer/Deployer.cs index 40849b5..a4298b9 100644 --- a/CodexNetDeployer/Deployer.cs +++ b/CodexNetDeployer/Deployer.cs @@ -39,16 +39,16 @@ namespace CodexNetDeployer // Each node must have its own IP, so it needs it own pod. Start them 1 at a time. var bootstrapSpr = ""; // The first one will be used to bootstrap the others. + int validatorsLeft = config.NumberOfValidators!.Value; for (var i = 0; i < config.NumberOfCodexNodes; i++) { Console.Write($" - {i} = "); var workflow = workflowCreator.CreateWorkflow(); var workflowStartup = new StartupConfig(); var codexStart = new CodexStartupConfig(config.CodexLogLevel); - workflowStartup.Add(codexStart); if (!string.IsNullOrEmpty(bootstrapSpr)) codexStart.BootstrapSpr = bootstrapSpr; codexStart.StorageQuota = config.StorageQuota.Value.MB(); - var marketplaceConfig = new MarketplaceInitialConfig(100000.Eth(), 0.TestTokens()); + var marketplaceConfig = new MarketplaceInitialConfig(100000.Eth(), 0.TestTokens(), validatorsLeft > 0); marketplaceConfig.AccountIndexOverride = i; codexStart.MarketplaceConfig = marketplaceConfig; workflowStartup.Add(gethResults); @@ -66,6 +66,7 @@ namespace CodexNetDeployer Console.Write($"Online ({pod.Name} at {pod.Ip} on '{pod.K8SNodeName}'" + Environment.NewLine); if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr; + validatorsLeft--; } else { diff --git a/CodexNetDeployer/Program.cs b/CodexNetDeployer/Program.cs index ce59a6d..eb3efc3 100644 --- a/CodexNetDeployer/Program.cs +++ b/CodexNetDeployer/Program.cs @@ -13,7 +13,8 @@ public class Program { @"--kube-config=C:\Users\Ben\.kube\codex-tests-ams3-dev-kubeconfig.yaml", "--kube-namespace=testing-deployer", - "--nodes=3", + "--nodes=5", + "--validators=3", "--storage-quota=1024" }; @@ -41,6 +42,7 @@ public class Program kubeConfigFile: argOrVar.Get(ArgOrVar.KubeConfigFile), kubeNamespace: argOrVar.Get(ArgOrVar.KubeNamespace), numberOfCodexNodes: argOrVar.GetInt(ArgOrVar.NumberOfCodexNodes), + numberOfValidators: argOrVar.GetInt(ArgOrVar.NumberOfValidatorNodes), storageQuota: argOrVar.GetInt(ArgOrVar.StorageQuota), codexLogLevel: ParseEnum.Parse(argOrVar.Get(ArgOrVar.LogLevel, nameof(CodexLogLevel.Debug))), runnerLocation: location diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index 4cf4be1..b7c3b94 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -60,6 +60,11 @@ namespace DistTestCore.Codex AddEnvVar("ETH_ACCOUNT", companionNodeAccount.Account); AddEnvVar("ETH_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address); AddEnvVar("PERSISTENCE", "1"); + + if (config.MarketplaceConfig.IsValidator) + { + AddEnvVar("VALIDATOR", "1"); + } } } diff --git a/DistTestCore/CodexSetup.cs b/DistTestCore/CodexSetup.cs index 83c5b9b..8c1a73c 100644 --- a/DistTestCore/CodexSetup.cs +++ b/DistTestCore/CodexSetup.cs @@ -13,6 +13,7 @@ namespace DistTestCore ICodexSetup EnableMetrics(); ICodexSetup EnableMarketplace(TestToken initialBalance); ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther); + ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator); } public class CodexSetup : CodexStartupConfig, ICodexSetup @@ -62,7 +63,12 @@ namespace DistTestCore public ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther) { - MarketplaceConfig = new MarketplaceInitialConfig(initialEther, initialBalance); + return EnableMarketplace(initialBalance, initialEther, false); + } + + public ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator) + { + MarketplaceConfig = new MarketplaceInitialConfig(initialEther, initialBalance, isValidator); return this; } diff --git a/DistTestCore/Marketplace/MarketplaceInitialConfig.cs b/DistTestCore/Marketplace/MarketplaceInitialConfig.cs index b802f33..c51d79f 100644 --- a/DistTestCore/Marketplace/MarketplaceInitialConfig.cs +++ b/DistTestCore/Marketplace/MarketplaceInitialConfig.cs @@ -2,14 +2,16 @@ { public class MarketplaceInitialConfig { - public MarketplaceInitialConfig(Ether initialEth, TestToken initialTestTokens) + public MarketplaceInitialConfig(Ether initialEth, TestToken initialTestTokens, bool isValidator) { InitialEth = initialEth; InitialTestTokens = initialTestTokens; + IsValidator = isValidator; } public Ether InitialEth { get; } public TestToken InitialTestTokens { get; } + public bool IsValidator { get; } public int? AccountIndexOverride { get; set; } } }