Merge pull request #58 from codex-storage/feature/marketplace-validator-sim-failures

[feature] Enable marketplace simulation of proof failures
This commit is contained in:
Ben Bierens 2023-09-21 11:00:27 +02:00 committed by GitHub
commit 002d3a6ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 12 deletions

View File

@ -7,7 +7,6 @@ namespace DistTestCore.Codex
public class CodexContainerRecipe : DefaultContainerRecipe public class CodexContainerRecipe : DefaultContainerRecipe
{ {
private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests"; private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests";
public const string MetricsPortTag = "metrics_port"; public const string MetricsPortTag = "metrics_port";
public const string DiscoveryPortTag = "discovery-port"; public const string DiscoveryPortTag = "discovery-port";
@ -38,7 +37,7 @@ namespace DistTestCore.Codex
AddVolume($"codex/{dataDir}", GetVolumeCapacity(config)); AddVolume($"codex/{dataDir}", GetVolumeCapacity(config));
AddInternalPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag); 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. // This makes the node announce itself to its local (pod) IP address.
AddEnvVar("NAT_IP_AUTO", "true"); AddEnvVar("NAT_IP_AUTO", "true");
@ -76,6 +75,11 @@ namespace DistTestCore.Codex
AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString()); AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString());
} }
if (config.SimulateProofFailures != null)
{
AddEnvVar("CODEX_SIMULATE_PROOF_FAILURES", config.SimulateProofFailures.ToString()!);
}
if (config.MarketplaceConfig != null) if (config.MarketplaceConfig != null)
{ {
var gethConfig = startupConfig.Get<GethStartResult>(); var gethConfig = startupConfig.Get<GethStartResult>();
@ -96,6 +100,10 @@ namespace DistTestCore.Codex
AddEnvVar("CODEX_VALIDATOR", "true"); AddEnvVar("CODEX_VALIDATOR", "true");
} }
} }
if(!string.IsNullOrEmpty(config.NameOverride)) {
AddEnvVar("CODEX_NODENAME", config.NameOverride);
}
} }
private ByteSize GetVolumeCapacity(CodexStartupConfig config) private ByteSize GetVolumeCapacity(CodexStartupConfig config)

View File

@ -12,14 +12,27 @@ namespace DistTestCore.Codex
LogLevel = logLevel; 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 string? NameOverride { get; set; }
public Location Location { 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 ByteSize? StorageQuota { get; set; }
public MetricsMode MetricsMode { get; set; } public MetricsMode MetricsMode { get; set; }
public MarketplaceInitialConfig? MarketplaceConfig { get; set; } public MarketplaceInitialConfig? MarketplaceConfig { get; set; }
public string? BootstrapSpr { get; set; } public string? BootstrapSpr { get; set; }
public int? BlockTTL { get; set; } public int? BlockTTL { get; set; }
public uint? SimulateProofFailures { get; set; }
public bool? EnableValidator { get; set; }
public TimeSpan? BlockMaintenanceInterval { get; set; } public TimeSpan? BlockMaintenanceInterval { get; set; }
public int? BlockMaintenanceNumber { get; set; } public int? BlockMaintenanceNumber { get; set; }
} }

View File

@ -9,6 +9,12 @@ namespace DistTestCore
{ {
ICodexSetup WithName(string name); ICodexSetup WithName(string name);
ICodexSetup At(Location location); ICodexSetup At(Location location);
ICodexSetup WithLogLevel(CodexLogLevel level);
/// <summary>
/// Sets the log level for codex. The default level is INFO and the
/// log level is applied only to the supplied topics.
/// </summary>
ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics);
ICodexSetup WithBootstrapNode(IOnlineCodexNode node); ICodexSetup WithBootstrapNode(IOnlineCodexNode node);
ICodexSetup WithStorageQuota(ByteSize storageQuota); ICodexSetup WithStorageQuota(ByteSize storageQuota);
ICodexSetup WithBlockTTL(TimeSpan duration); ICodexSetup WithBlockTTL(TimeSpan duration);
@ -18,6 +24,10 @@ namespace DistTestCore
ICodexSetup EnableMarketplace(TestToken initialBalance); ICodexSetup EnableMarketplace(TestToken initialBalance);
ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther); ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther);
ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator); ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator);
/// <summary>
/// Provides an invalid proof every N proofs
/// </summary>
ICodexSetup WithSimulateProofFailures(uint failEveryNProofs);
} }
public class CodexSetup : CodexStartupConfig, ICodexSetup public class CodexSetup : CodexStartupConfig, ICodexSetup
@ -48,6 +58,19 @@ namespace DistTestCore
return this; 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) public ICodexSetup WithStorageQuota(ByteSize storageQuota)
{ {
StorageQuota = storageQuota; StorageQuota = storageQuota;
@ -94,6 +117,12 @@ namespace DistTestCore
return this; return this;
} }
public ICodexSetup WithSimulateProofFailures(uint failEveryNProofs)
{
SimulateProofFailures = failEveryNProofs;
return this;
}
public string Describe() public string Describe()
{ {
var args = string.Join(',', DescribeArgs()); var args = string.Join(',', DescribeArgs());
@ -102,9 +131,11 @@ namespace DistTestCore
private IEnumerable<string> DescribeArgs() private IEnumerable<string> DescribeArgs()
{ {
yield return $"LogLevel={LogLevel}"; yield return $"LogLevel={LogLevelWithTopics()}";
if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}"; 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}";
} }
} }
} }

View File

@ -20,6 +20,7 @@ namespace DistTestCore
LogSeparator(); LogSeparator();
LogStart($"Starting {codexSetup.Describe()}..."); LogStart($"Starting {codexSetup.Describe()}...");
var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup); var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup);
gethStartResult = lifecycle.GethStarter.BringOnlineValidatorFor(codexSetup, gethStartResult);
var startupConfig = CreateStartupConfig(gethStartResult, codexSetup); var startupConfig = CreateStartupConfig(gethStartResult, codexSetup);

View File

@ -5,10 +5,6 @@
<RootNamespace>DistTestCore</RootNamespace> <RootNamespace>DistTestCore</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<IsArm64 Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">true</IsArm64>
</PropertyGroup>
<PropertyGroup Condition="'$(IsArm64)'=='true'">
<DefineConstants>Arm64</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="Metrics\dashboard.json" /> <None Remove="Metrics\dashboard.json" />

View File

@ -30,6 +30,17 @@ namespace DistTestCore
return CreateGethStartResult(marketplaceNetwork, companionNode); 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) private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo companionNode)
{ {
if (marketplaceConfig.InitialTestTokens.Amount == 0) return; if (marketplaceConfig.InitialTestTokens.Amount == 0) return;