diff --git a/Framework/Utils/ByteSize.cs b/Framework/Utils/ByteSize.cs index b069b044..170aaf7f 100644 --- a/Framework/Utils/ByteSize.cs +++ b/Framework/Utils/ByteSize.cs @@ -10,6 +10,8 @@ public long SizeInBytes { get; } + public const double DefaultSecondsPerMB = 10.0; + public long ToMB() { return SizeInBytes / (1024 * 1024); @@ -36,6 +38,12 @@ { return Formatter.FormatByteSize(SizeInBytes); } + + public TimeSpan ToTimeSpan(double secsPerMB = DefaultSecondsPerMB) + { + var filesizeInMb = SizeInBytes / (1024 * 1024); + return TimeSpan.FromSeconds(filesizeInMb * secsPerMB); + } } public static class ByteSizeIntExtensions @@ -91,5 +99,6 @@ { return Convert.ToInt64(i).TB(); } + } } diff --git a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs index 15e9ee14..3f230ba3 100644 --- a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs +++ b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs @@ -8,7 +8,6 @@ namespace CodexPlugin private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter(); private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests"; - public const string MetricsPortTag = "metrics_port"; public const string DiscoveryPortTag = "discovery-port"; @@ -18,7 +17,7 @@ namespace CodexPlugin public override string AppName => "codex"; public override string Image { get; } - + public CodexContainerRecipe() { Image = GetDockerImage(); @@ -26,8 +25,8 @@ namespace CodexPlugin protected override void Initialize(StartupConfig startupConfig) { - //SetResourcesRequest(milliCPUs: 1000, memory: 6.GB()); - //SetResourceLimits(milliCPUs: 4000, memory: 12.GB()); + SetResourcesRequest(milliCPUs: 100, memory: 100.MB()); + SetResourceLimits(milliCPUs: 4000, memory: 12.GB()); var config = startupConfig.Get(); @@ -39,7 +38,7 @@ namespace CodexPlugin 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"); @@ -77,6 +76,11 @@ namespace CodexPlugin AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString()); } + if (config.SimulateProofFailures != null) + { + AddEnvVar("CODEX_SIMULATE_PROOF_FAILURES", config.SimulateProofFailures.ToString()!); + } + if (config.MarketplaceConfig != null) { var mconfig = config.MarketplaceConfig; @@ -97,10 +101,15 @@ namespace CodexPlugin if (config.MarketplaceConfig.IsValidator) { - AddEnvVar("CODEX_VALIDATOR", "true"); + AddEnvVar("CODEX_VALIDATOR", "true"); } } + if(!string.IsNullOrEmpty(config.NameOverride)) + { + AddEnvVar("CODEX_NODENAME", config.NameOverride); + } + AddPodLabel("codexid", Image); } diff --git a/ProjectPlugins/CodexPlugin/CodexSetup.cs b/ProjectPlugins/CodexPlugin/CodexSetup.cs index 46289a90..d8b25ee5 100644 --- a/ProjectPlugins/CodexPlugin/CodexSetup.cs +++ b/ProjectPlugins/CodexPlugin/CodexSetup.cs @@ -7,18 +7,27 @@ namespace CodexPlugin { public interface ICodexSetup { - ICodexSetup WithLogLevel(CodexLogLevel logLevel); ICodexSetup WithName(string name); ICodexSetup At(Location location); ICodexSetup WithBootstrapNode(ICodexNode node); + 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 WithStorageQuota(ByteSize storageQuota); ICodexSetup WithBlockTTL(TimeSpan duration); ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration); ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks); ICodexSetup EnableMetrics(); ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, bool isValidator = false); + /// + /// Provides an invalid proof every N proofs + /// + ICodexSetup WithSimulateProofFailures(uint failEveryNProofs); } - + public class CodexSetup : CodexStartupConfig, ICodexSetup { public int NumberOfNodes { get; } @@ -28,12 +37,6 @@ namespace CodexPlugin NumberOfNodes = numberOfNodes; } - public ICodexSetup WithLogLevel(CodexLogLevel logLevel) - { - LogLevel = logLevel; - return this; - } - public ICodexSetup WithName(string name) { NameOverride = name; @@ -52,6 +55,19 @@ namespace CodexPlugin 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; @@ -88,6 +104,12 @@ namespace CodexPlugin return this; } + public ICodexSetup WithSimulateProofFailures(uint failEveryNProofs) + { + SimulateProofFailures = failEveryNProofs; + return this; + } + public string Describe() { var args = string.Join(',', DescribeArgs()); @@ -96,9 +118,11 @@ namespace CodexPlugin 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/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs index 0cabfaf2..07baec10 100644 --- a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs +++ b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs @@ -8,12 +8,25 @@ namespace CodexPlugin public string? NameOverride { get; set; } public Location Location { get; set; } public CodexLogLevel LogLevel { get; set; } + public string[]? LogTopics { get; set; } public ByteSize? StorageQuota { get; set; } public bool MetricsEnabled { 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; } + + 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; + } } } diff --git a/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs index e331b66f..3a40f1c9 100644 --- a/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs +++ b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs @@ -151,6 +151,18 @@ namespace CodexPlugin WaitForStorageContractState(timeout, "finished"); } + public void WaitForStorageContractFinished(ByteSize contractFileSize) + { + if (!contractStartUtc.HasValue) + { + WaitForStorageContractStarted(contractFileSize.ToTimeSpan()); + } + var gracePeriod = TimeSpan.FromSeconds(10); + var currentContractTime = DateTime.UtcNow - contractStartUtc!.Value; + var timeout = (ContractDuration - currentContractTime) + gracePeriod; + WaitForStorageContractState(timeout, "finished"); + } + /// /// Wait for contract to start. Max timeout depends on contract filesize. Allows more time for larger files. /// diff --git a/Tests/DistTestCore/DistTestCore.csproj b/Tests/DistTestCore/DistTestCore.csproj index 6a77277f..91d1fd09 100644 --- a/Tests/DistTestCore/DistTestCore.csproj +++ b/Tests/DistTestCore/DistTestCore.csproj @@ -5,10 +5,6 @@ DistTestCore enable enable - true - - - Arm64 diff --git a/Tests/DistTestCore/Helpers/AssertHelpers.cs b/Tests/DistTestCore/Helpers/AssertHelpers.cs index fdbffab6..efd0749c 100644 --- a/Tests/DistTestCore/Helpers/AssertHelpers.cs +++ b/Tests/DistTestCore/Helpers/AssertHelpers.cs @@ -10,8 +10,11 @@ namespace DistTestCore.Helpers { try { - var c = constraint.Resolve(); - Time.WaitUntil(() => c.ApplyTo(actual()).IsSuccess); + + Time.WaitUntil(() => { + var c = constraint.Resolve(); + return c.ApplyTo(actual()).IsSuccess; + }); } catch (TimeoutException) {