diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index b9ae94b..60f1c64 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -7,7 +7,6 @@ namespace DistTestCore.Codex public class CodexContainerRecipe : DefaultContainerRecipe { private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests"; - public const string MetricsPortTag = "metrics_port"; public const string DiscoveryPortTag = "discovery-port"; @@ -17,7 +16,7 @@ namespace DistTestCore.Codex public override string AppName => "codex"; public override string Image { get; } - + public CodexContainerRecipe() { Image = GetDockerImage(); @@ -38,7 +37,7 @@ namespace DistTestCore.Codex AddVolume($"codex/{dataDir}", GetVolumeCapacity(config)); AddInternalPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag); - AddEnvVar("CODEX_LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant()); + AddEnvVar("CODEX_LOG_LEVEL", config.LogLevelWithTopics()); // This makes the node announce itself to its local (pod) IP address. AddEnvVar("NAT_IP_AUTO", "true"); @@ -76,6 +75,11 @@ namespace DistTestCore.Codex AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString()); } + if (config.SimulateProofFailures != null) + { + AddEnvVar("CODEX_SIMULATE_PROOF_FAILURES", config.SimulateProofFailures.ToString()!); + } + if (config.MarketplaceConfig != null) { var gethConfig = startupConfig.Get(); @@ -93,9 +97,13 @@ namespace DistTestCore.Codex if (config.MarketplaceConfig.IsValidator) { - AddEnvVar("CODEX_VALIDATOR", "true"); + AddEnvVar("CODEX_VALIDATOR", "true"); } } + + if(!string.IsNullOrEmpty(config.NameOverride)) { + AddEnvVar("CODEX_NODENAME", config.NameOverride); + } } private ByteSize GetVolumeCapacity(CodexStartupConfig config) diff --git a/DistTestCore/Codex/CodexStartupConfig.cs b/DistTestCore/Codex/CodexStartupConfig.cs index 36e4757..0ca738d 100644 --- a/DistTestCore/Codex/CodexStartupConfig.cs +++ b/DistTestCore/Codex/CodexStartupConfig.cs @@ -12,14 +12,27 @@ namespace DistTestCore.Codex LogLevel = logLevel; } + public string LogLevelWithTopics() + { + var level = LogLevel.ToString()!.ToUpperInvariant(); + if (LogTopics != null && LogTopics.Count() > 0) + { + level = $"INFO;{level}: {string.Join(",", LogTopics.Where(s => !string.IsNullOrEmpty(s)))}"; + } + return level; + } + public string? NameOverride { get; set; } public Location Location { get; set; } - public CodexLogLevel LogLevel { get; } + public CodexLogLevel LogLevel { get; set; } + public string[]? LogTopics { 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..e421aa9 100644 --- a/DistTestCore/CodexSetup.cs +++ b/DistTestCore/CodexSetup.cs @@ -9,6 +9,12 @@ namespace DistTestCore { ICodexSetup WithName(string name); ICodexSetup At(Location location); + ICodexSetup WithLogLevel(CodexLogLevel level); + /// + /// Sets the log level for codex. The default level is INFO and the + /// log level is applied only to the supplied topics. + /// + ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics); ICodexSetup WithBootstrapNode(IOnlineCodexNode node); ICodexSetup WithStorageQuota(ByteSize storageQuota); ICodexSetup WithBlockTTL(TimeSpan duration); @@ -18,8 +24,12 @@ 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); } - + public class CodexSetup : CodexStartupConfig, ICodexSetup { public int NumberOfNodes { get; } @@ -48,6 +58,19 @@ namespace DistTestCore return this; } + public ICodexSetup WithLogLevel(CodexLogLevel level) + { + LogLevel = level; + return this; + } + + public ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics) + { + LogLevel = level; + LogTopics = topics; + return this; + } + public ICodexSetup WithStorageQuota(ByteSize storageQuota) { StorageQuota = storageQuota; @@ -94,6 +117,12 @@ namespace DistTestCore return this; } + public ICodexSetup WithSimulateProofFailures(uint failEveryNProofs) + { + SimulateProofFailures = failEveryNProofs; + return this; + } + public string Describe() { var args = string.Join(',', DescribeArgs()); @@ -102,9 +131,11 @@ namespace DistTestCore private IEnumerable DescribeArgs() { - yield return $"LogLevel={LogLevel}"; + yield return $"LogLevel={LogLevelWithTopics()}"; 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 (MarketplaceConfig != null) yield return $"IsValidator={MarketplaceConfig.IsValidator}"; } } } 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/DistTestCore.csproj b/DistTestCore/DistTestCore.csproj index 94a2271..89d4b1f 100644 --- a/DistTestCore/DistTestCore.csproj +++ b/DistTestCore/DistTestCore.csproj @@ -5,10 +5,6 @@ DistTestCore enable enable - true - - - Arm64 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;