Add validator and simulation of proof failures
This commit is contained in:
parent
ef2c18c599
commit
5f9371e95e
|
@ -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<GethStartResult>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
@ -18,8 +18,16 @@ namespace DistTestCore
|
|||
ICodexSetup EnableMarketplace(TestToken initialBalance);
|
||||
ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther);
|
||||
ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator);
|
||||
/// <summary>
|
||||
/// Provides an invalid proof every N proofs
|
||||
/// </summary>
|
||||
ICodexSetup WithSimulateProofFailures(uint failEveryNProofs);
|
||||
/// <summary>
|
||||
/// Enables the validation module in the node
|
||||
/// </summary>
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue