From 5f9371e95e8f35e9bf815dfda9a96237b7a48640 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:02:53 +1000 Subject: [PATCH] Add validator and simulation of proof failures --- DistTestCore/Codex/CodexContainerRecipe.cs | 35 +++++++++++++++++----- DistTestCore/Codex/CodexStartupConfig.cs | 4 ++- DistTestCore/CodexSetup.cs | 28 +++++++++++++++-- DistTestCore/CodexStarter.cs | 1 + DistTestCore/GethStarter.cs | 11 +++++++ 5 files changed, 67 insertions(+), 12 deletions(-) diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index c928b3e..d6e3e41 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -6,8 +6,7 @@ namespace DistTestCore.Codex { public class CodexContainerRecipe : DefaultContainerRecipe { - private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests"; - + public const string DockerImage = "codexstorage/nim-codex:sha-1d161d3"; public const string MetricsPortTag = "metrics_port"; public const string DiscoveryPortTag = "discovery-port"; @@ -38,7 +37,12 @@ namespace DistTestCore.Codex AddVolume($"codex/{dataDir}", GetVolumeCapacity(config)); AddInternalPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag); - AddEnvVar("CODEX_LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant()); + + var level = config.LogLevel.ToString()!.ToUpperInvariant(); + if (config.LogTopics != null && config.LogTopics.Count() > 0){ + level = $"INFO;{level}: {string.Join(",", config.LogTopics.Where(s => !string.IsNullOrEmpty(s)))}"; + } + AddEnvVar("CODEX_LOG_LEVEL", level); // This makes the node announce itself to its local (pod) IP address. AddEnvVar("NAT_IP_AUTO", "true"); @@ -76,7 +80,15 @@ namespace DistTestCore.Codex AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString()); } - if (config.MarketplaceConfig != null) + if (config.SimulateProofFailures != null) + { + AddEnvVar("CODEX_SIMULATE_PROOF_FAILURES", config.SimulateProofFailures.ToString()!); + } + if (config.EnableValidator == true) + { + AddEnvVar("CODEX_VALIDATOR", "true"); + } + if (config.MarketplaceConfig != null || config.EnableValidator == true) { var gethConfig = startupConfig.Get(); var companionNode = gethConfig.CompanionNode; @@ -91,10 +103,17 @@ namespace DistTestCore.Codex AddEnvVar("CODEX_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address); AddEnvVar("CODEX_PERSISTENCE", "true"); - if (config.MarketplaceConfig.IsValidator) - { - AddEnvVar("CODEX_VALIDATOR", "true"); - } + //if (config.MarketplaceConfig.IsValidator) + //{ + // AddEnvVar("CODEX_VALIDATOR", "true"); + //} + } + if (config.MarketplaceConfig != null) { + AddEnvVar("CODEX_PERSISTENCE", "true"); + } + + if(!string.IsNullOrEmpty(config.NameOverride)) { + AddEnvVar("CODEX_NODENAME", config.NameOverride); } } diff --git a/DistTestCore/Codex/CodexStartupConfig.cs b/DistTestCore/Codex/CodexStartupConfig.cs index 36e4757..a1170c6 100644 --- a/DistTestCore/Codex/CodexStartupConfig.cs +++ b/DistTestCore/Codex/CodexStartupConfig.cs @@ -14,12 +14,14 @@ namespace DistTestCore.Codex public string? NameOverride { get; set; } public Location Location { get; set; } - public CodexLogLevel LogLevel { get; } + public CodexLogLevel LogLevel { get; set; } public ByteSize? StorageQuota { get; set; } public MetricsMode MetricsMode { get; set; } public MarketplaceInitialConfig? MarketplaceConfig { get; set; } public string? BootstrapSpr { get; set; } public int? BlockTTL { get; set; } + public uint? SimulateProofFailures { get; set; } + public bool? EnableValidator { get; set; } public TimeSpan? BlockMaintenanceInterval { get; set; } public int? BlockMaintenanceNumber { get; set; } } diff --git a/DistTestCore/CodexSetup.cs b/DistTestCore/CodexSetup.cs index f2ec51e..c91b66f 100644 --- a/DistTestCore/CodexSetup.cs +++ b/DistTestCore/CodexSetup.cs @@ -18,8 +18,16 @@ namespace DistTestCore ICodexSetup EnableMarketplace(TestToken initialBalance); ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther); ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator); + /// + /// Provides an invalid proof every N proofs + /// + ICodexSetup WithSimulateProofFailures(uint failEveryNProofs); + /// + /// Enables the validation module in the node + /// + ICodexSetup WithValidator(); } - + public class CodexSetup : CodexStartupConfig, ICodexSetup { public int NumberOfNodes { get; } @@ -85,7 +93,7 @@ namespace DistTestCore public ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther) { - return EnableMarketplace(initialBalance, initialEther, false); + return EnableMarketplace(initialBalance, initialEther, false); } public ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator) @@ -94,6 +102,18 @@ namespace DistTestCore return this; } + public ICodexSetup WithSimulateProofFailures(uint failEveryNProofs) + { + SimulateProofFailures = failEveryNProofs; + return this; + } + + public ICodexSetup WithValidator() + { + EnableValidator = true; + return this; + } + public string Describe() { var args = string.Join(',', DescribeArgs()); @@ -104,7 +124,9 @@ namespace DistTestCore { yield return $"LogLevel={LogLevel}"; if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}"; - if (StorageQuota != null) yield return $"StorageQuote={StorageQuota}"; + if (StorageQuota != null) yield return $"StorageQuota={StorageQuota}"; + if (SimulateProofFailures != null) yield return $"SimulateProofFailures={SimulateProofFailures}"; + if (EnableValidator != null) yield return $"EnableValidator={EnableValidator}"; } } } diff --git a/DistTestCore/CodexStarter.cs b/DistTestCore/CodexStarter.cs index 86a839e..7a8947b 100644 --- a/DistTestCore/CodexStarter.cs +++ b/DistTestCore/CodexStarter.cs @@ -20,6 +20,7 @@ namespace DistTestCore LogSeparator(); LogStart($"Starting {codexSetup.Describe()}..."); var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup); + gethStartResult = lifecycle.GethStarter.BringOnlineValidatorFor(codexSetup, gethStartResult); var startupConfig = CreateStartupConfig(gethStartResult, codexSetup); diff --git a/DistTestCore/GethStarter.cs b/DistTestCore/GethStarter.cs index 578cc30..7df4ba4 100644 --- a/DistTestCore/GethStarter.cs +++ b/DistTestCore/GethStarter.cs @@ -30,6 +30,17 @@ namespace DistTestCore return CreateGethStartResult(marketplaceNetwork, companionNode); } + public GethStartResult BringOnlineValidatorFor(CodexSetup codexSetup, GethStartResult previousResult) + { + // allow marketplace and validator to be enabled on the same Codex node + if (previousResult.CompanionNode != null || (codexSetup.EnableValidator ?? false) == false) return previousResult; + + var marketplaceNetwork = marketplaceNetworkCache.Get(); + var companionNode = StartCompanionNode(codexSetup, marketplaceNetwork); + + return CreateGethStartResult(marketplaceNetwork, companionNode); + } + private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo companionNode) { if (marketplaceConfig.InitialTestTokens.Amount == 0) return;