2
0
mirror of synced 2025-02-27 23:40:33 +00:00

Merge branch 'feature/update-env-vars'

This commit is contained in:
benbierens 2023-07-12 14:53:44 +02:00
commit 66161e8d41
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
2 changed files with 41 additions and 33 deletions

View File

@ -1,15 +1,16 @@
using DistTestCore.Marketplace; using DistTestCore.Marketplace;
using KubernetesWorkflow; using KubernetesWorkflow;
using System.Net.Sockets;
namespace DistTestCore.Codex namespace DistTestCore.Codex
{ {
public class CodexContainerRecipe : ContainerRecipeFactory public class CodexContainerRecipe : ContainerRecipeFactory
{ {
#if Arm64 #if Arm64
public const string DockerImage = "codexstorage/nim-codex:sha-7b88ea0"; public const string DockerImage = "codexstorage/nim-codex:sha-f053135";
#else #else
public const string DockerImage = "thatbenbierens/nim-codex:dhting"; //public const string DockerImage = "thatbenbierens/nim-codex:dhting";
//public const string DockerImage = "codexstorage/nim-codex:sha-7b88ea0"; public const string DockerImage = "codexstorage/nim-codex:sha-f053135";
#endif #endif
public const string MetricsPortTag = "metrics_port"; public const string MetricsPortTag = "metrics_port";
public const string DiscoveryPortTag = "discovery-port"; public const string DiscoveryPortTag = "discovery-port";
@ -24,26 +25,32 @@ namespace DistTestCore.Codex
{ {
var config = startupConfig.Get<CodexStartupConfig>(); var config = startupConfig.Get<CodexStartupConfig>();
AddExposedPortAndVar("API_PORT"); AddExposedPortAndVar("CODEX_API_PORT");
AddEnvVar("DATA_DIR", $"datadir{ContainerNumber}"); AddEnvVar("CODEX_API_BINDADDR", "0.0.0.0");
AddInternalPortAndVar("DISC_PORT", DiscoveryPortTag);
AddEnvVar("LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant()); AddEnvVar("CODEX_DATA_DIR", $"datadir{ContainerNumber}");
AddInternalPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag);
AddEnvVar("CODEX_LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant());
// This makes the node announce itself to its local (pod) IP address.
AddEnvVar("CODEX_NAT_ADDR", "$(hostname --ip-address)");
var listenPort = AddInternalPort(); var listenPort = AddInternalPort();
AddEnvVar("LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{listenPort.Number}"); AddEnvVar("CODEX_LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{listenPort.Number}");
if (!string.IsNullOrEmpty(config.BootstrapSpr)) if (!string.IsNullOrEmpty(config.BootstrapSpr))
{ {
AddEnvVar("BOOTSTRAP_SPR", config.BootstrapSpr); AddEnvVar("CODEX_BOOTSTRAP_NODE", config.BootstrapSpr);
} }
if (config.StorageQuota != null) if (config.StorageQuota != null)
{ {
AddEnvVar("STORAGE_QUOTA", config.StorageQuota.SizeInBytes.ToString()!); AddEnvVar("CODEX_STORAGE_QUOTA", config.StorageQuota.SizeInBytes.ToString()!);
} }
if (config.MetricsEnabled) if (config.MetricsEnabled)
{ {
AddEnvVar("METRICS_ADDR", "0.0.0.0"); AddEnvVar("CODEX_METRICS", "true");
AddInternalPortAndVar("METRICS_PORT", tag: MetricsPortTag); AddEnvVar("CODEX_METRICS_ADDRESS", "0.0.0.0");
AddInternalPortAndVar("CODEX_METRICS_PORT", tag: MetricsPortTag);
} }
if (config.MarketplaceConfig != null) if (config.MarketplaceConfig != null)
@ -56,14 +63,14 @@ namespace DistTestCore.Codex
var ip = companionNode.RunningContainer.Pod.PodInfo.Ip; var ip = companionNode.RunningContainer.Pod.PodInfo.Ip;
var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag).Number; var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag).Number;
AddEnvVar("ETH_PROVIDER", $"ws://{ip}:{port}"); AddEnvVar("CODEX_ETH_PROVIDER", $"ws://{ip}:{port}");
AddEnvVar("ETH_ACCOUNT", companionNodeAccount.Account); AddEnvVar("CODEX_ETH_ACCOUNT", companionNodeAccount.Account);
AddEnvVar("ETH_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address); AddEnvVar("CODEX_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address);
AddEnvVar("PERSISTENCE", "1"); AddEnvVar("CODEX_PERSISTENCE", "true");
if (config.MarketplaceConfig.IsValidator) if (config.MarketplaceConfig.IsValidator)
{ {
AddEnvVar("VALIDATOR", "1"); AddEnvVar("CODEX_VALIDATOR", "true");
} }
} }
} }

View File

@ -34,10 +34,10 @@ namespace DistTestCore.Marketplace
{ {
var request = new CodexSalesRequestStorageRequest var request = new CodexSalesRequestStorageRequest
{ {
duration = ToHexBigInt(duration.TotalSeconds), duration = ToDecInt(duration.TotalSeconds),
proofProbability = ToHexBigInt(proofProbability), proofProbability = ToDecInt(proofProbability),
reward = ToHexBigInt(pricePerSlotPerSecond), reward = ToDecInt(pricePerSlotPerSecond),
collateral = ToHexBigInt(requiredCollateral), collateral = ToDecInt(requiredCollateral),
expiry = null, expiry = null,
nodes = minRequiredNumberOfNodes, nodes = minRequiredNumberOfNodes,
tolerance = null, tolerance = null,
@ -62,19 +62,19 @@ namespace DistTestCore.Marketplace
return response; return response;
} }
public string MakeStorageAvailable(ByteSize totalSpace, TestToken minPriceForTotalSpace, TestToken maxCollateral, TimeSpan maxDuration) public string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration)
{ {
var request = new CodexSalesAvailabilityRequest var request = new CodexSalesAvailabilityRequest
{ {
size = ToHexBigInt(totalSpace.SizeInBytes), size = ToDecInt(size.SizeInBytes),
duration = ToHexBigInt(maxDuration.TotalSeconds), duration = ToDecInt(maxDuration.TotalSeconds),
maxCollateral = ToHexBigInt(maxCollateral), maxCollateral = ToDecInt(maxCollateral),
minPrice = ToHexBigInt(minPriceForTotalSpace) minPrice = ToDecInt(minPricePerBytePerSecond)
}; };
Log($"Making storage available... (" + Log($"Making storage available... (" +
$"size: {totalSpace}, " + $"size: {size}, " +
$"minPricePerBytePerSecond: {minPriceForTotalSpace}, " + $"minPricePerBytePerSecond: {minPricePerBytePerSecond}, " +
$"maxCollateral: {maxCollateral}, " + $"maxCollateral: {maxCollateral}, " +
$"maxDuration: {Time.FormatDuration(maxDuration)})"); $"maxDuration: {Time.FormatDuration(maxDuration)})");
@ -85,15 +85,16 @@ namespace DistTestCore.Marketplace
return response.id; return response.id;
} }
private string ToHexBigInt(double d) private string ToDecInt(double d)
{ {
return "0x" + string.Format("{0:X}", Convert.ToInt64(d)); var i = new BigInteger(d);
return i.ToString("D");
} }
public string ToHexBigInt(TestToken t) public string ToDecInt(TestToken t)
{ {
var bigInt = new BigInteger(t.Amount); var i = new BigInteger(t.Amount);
return "0x" + bigInt.ToString("X"); return i.ToString("D");
} }
public void AssertThatBalance(IResolveConstraint constraint, string message = "") public void AssertThatBalance(IResolveConstraint constraint, string message = "")