2023-09-19 08:24:43 +00:00
|
|
|
|
using CodexContractsPlugin;
|
|
|
|
|
using GethPlugin;
|
|
|
|
|
using KubernetesWorkflow;
|
2023-09-08 08:21:40 +00:00
|
|
|
|
using Utils;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
2023-09-11 09:59:33 +00:00
|
|
|
|
namespace CodexPlugin
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public interface ICodexSetup
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
2023-04-30 08:56:19 +00:00
|
|
|
|
ICodexSetup WithName(string name);
|
2023-09-25 06:47:19 +00:00
|
|
|
|
ICodexSetup At(ILocation location);
|
2023-09-19 09:51:59 +00:00
|
|
|
|
ICodexSetup WithBootstrapNode(ICodexNode node);
|
2023-09-14 05:03:09 +00:00
|
|
|
|
ICodexSetup WithLogLevel(CodexLogLevel level);
|
2023-10-07 07:48:12 +00:00
|
|
|
|
ICodexSetup WithLogLevel(CodexLogLevel level, CodexLogCustomTopics customTopics);
|
2023-04-13 07:33:10 +00:00
|
|
|
|
ICodexSetup WithStorageQuota(ByteSize storageQuota);
|
2023-08-10 07:44:23 +00:00
|
|
|
|
ICodexSetup WithBlockTTL(TimeSpan duration);
|
2023-08-14 13:51:03 +00:00
|
|
|
|
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
2023-08-14 14:37:31 +00:00
|
|
|
|
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
2023-09-13 09:59:21 +00:00
|
|
|
|
ICodexSetup EnableMetrics();
|
2024-03-26 14:35:26 +00:00
|
|
|
|
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Action<IMarketplaceSetup> marketplaceSetup);
|
2023-09-14 05:17:30 +00:00
|
|
|
|
/// <summary>
|
2023-09-14 05:02:53 +00:00
|
|
|
|
/// Provides an invalid proof every N proofs
|
|
|
|
|
/// </summary>
|
|
|
|
|
ICodexSetup WithSimulateProofFailures(uint failEveryNProofs);
|
2023-10-23 10:33:48 +00:00
|
|
|
|
ICodexSetup AsPublicTestNet(CodexTestNetConfig testNetConfig);
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
2023-09-14 05:02:53 +00:00
|
|
|
|
|
2024-03-13 09:14:11 +00:00
|
|
|
|
public interface IMarketplaceSetup
|
|
|
|
|
{
|
2024-03-26 14:35:26 +00:00
|
|
|
|
IMarketplaceSetup WithInitial(Ether eth, TestToken tokens);
|
|
|
|
|
IMarketplaceSetup WithAccount(EthAccount account);
|
2024-03-13 09:14:11 +00:00
|
|
|
|
IMarketplaceSetup AsStorageNode();
|
|
|
|
|
IMarketplaceSetup AsValidator();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 07:48:12 +00:00
|
|
|
|
public class CodexLogCustomTopics
|
|
|
|
|
{
|
2024-01-18 08:55:07 +00:00
|
|
|
|
public CodexLogCustomTopics(CodexLogLevel discV5, CodexLogLevel libp2p, CodexLogLevel blockExchange)
|
|
|
|
|
{
|
|
|
|
|
DiscV5 = discV5;
|
|
|
|
|
Libp2p = libp2p;
|
|
|
|
|
BlockExchange = blockExchange;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 07:48:12 +00:00
|
|
|
|
public CodexLogCustomTopics(CodexLogLevel discV5, CodexLogLevel libp2p)
|
|
|
|
|
{
|
|
|
|
|
DiscV5 = discV5;
|
|
|
|
|
Libp2p = libp2p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CodexLogLevel DiscV5 { get; set; }
|
|
|
|
|
public CodexLogLevel Libp2p { get; set; }
|
2024-01-18 08:55:07 +00:00
|
|
|
|
public CodexLogLevel? BlockExchange { get; }
|
2023-10-07 07:48:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public class CodexSetup : CodexStartupConfig, ICodexSetup
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
public int NumberOfNodes { get; }
|
|
|
|
|
|
2023-09-13 12:37:53 +00:00
|
|
|
|
public CodexSetup(int numberOfNodes)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
NumberOfNodes = numberOfNodes;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-30 08:56:19 +00:00
|
|
|
|
public ICodexSetup WithName(string name)
|
|
|
|
|
{
|
|
|
|
|
NameOverride = name;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 06:47:19 +00:00
|
|
|
|
public ICodexSetup At(ILocation location)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
Location = location;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 09:51:59 +00:00
|
|
|
|
public ICodexSetup WithBootstrapNode(ICodexNode node)
|
2023-04-19 12:57:00 +00:00
|
|
|
|
{
|
2023-04-24 12:09:23 +00:00
|
|
|
|
BootstrapSpr = node.GetDebugInfo().spr;
|
2023-04-19 12:57:00 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
2023-09-14 05:03:09 +00:00
|
|
|
|
public ICodexSetup WithLogLevel(CodexLogLevel level)
|
|
|
|
|
{
|
|
|
|
|
LogLevel = level;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 07:48:12 +00:00
|
|
|
|
public ICodexSetup WithLogLevel(CodexLogLevel level, CodexLogCustomTopics customTopics)
|
2023-09-14 05:03:09 +00:00
|
|
|
|
{
|
|
|
|
|
LogLevel = level;
|
2023-10-07 07:48:12 +00:00
|
|
|
|
CustomTopics = customTopics;
|
2023-09-14 05:03:09 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public ICodexSetup WithStorageQuota(ByteSize storageQuota)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
StorageQuota = storageQuota;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 07:44:23 +00:00
|
|
|
|
public ICodexSetup WithBlockTTL(TimeSpan duration)
|
|
|
|
|
{
|
|
|
|
|
BlockTTL = Convert.ToInt32(duration.TotalSeconds);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 13:51:03 +00:00
|
|
|
|
public ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration)
|
|
|
|
|
{
|
|
|
|
|
BlockMaintenanceInterval = duration;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 14:37:31 +00:00
|
|
|
|
public ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks)
|
|
|
|
|
{
|
|
|
|
|
BlockMaintenanceNumber = numberOfBlocks;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 09:59:21 +00:00
|
|
|
|
public ICodexSetup EnableMetrics()
|
|
|
|
|
{
|
|
|
|
|
MetricsEnabled = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
2024-03-26 14:35:26 +00:00
|
|
|
|
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Action<IMarketplaceSetup> marketplaceSetup)
|
2023-09-19 08:24:43 +00:00
|
|
|
|
{
|
2024-03-13 09:14:11 +00:00
|
|
|
|
var ms = new MarketplaceSetup();
|
|
|
|
|
marketplaceSetup(ms);
|
|
|
|
|
|
2024-03-26 14:35:26 +00:00
|
|
|
|
MarketplaceConfig = new MarketplaceInitialConfig(ms, gethNode, codexContracts);
|
2023-09-19 08:24:43 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 05:02:53 +00:00
|
|
|
|
public ICodexSetup WithSimulateProofFailures(uint failEveryNProofs)
|
|
|
|
|
{
|
|
|
|
|
SimulateProofFailures = failEveryNProofs;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 10:33:48 +00:00
|
|
|
|
public ICodexSetup AsPublicTestNet(CodexTestNetConfig testNetConfig)
|
2023-10-23 09:30:54 +00:00
|
|
|
|
{
|
2023-10-23 10:33:48 +00:00
|
|
|
|
PublicTestNet = testNetConfig;
|
2023-10-23 09:30:54 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 14:06:04 +00:00
|
|
|
|
public string Describe()
|
|
|
|
|
{
|
|
|
|
|
var args = string.Join(',', DescribeArgs());
|
2023-04-19 12:57:00 +00:00
|
|
|
|
return $"({NumberOfNodes} CodexNodes with args:[{args}])";
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> DescribeArgs()
|
|
|
|
|
{
|
2023-11-15 13:53:25 +00:00
|
|
|
|
if (PublicTestNet != null) yield return $"<!>Public TestNet with listenPort: {PublicTestNet.PublicListenPort}<!>";
|
2023-09-14 05:04:37 +00:00
|
|
|
|
yield return $"LogLevel={LogLevelWithTopics()}";
|
2023-04-24 12:09:23 +00:00
|
|
|
|
if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}";
|
2023-09-14 05:02:53 +00:00
|
|
|
|
if (StorageQuota != null) yield return $"StorageQuota={StorageQuota}";
|
|
|
|
|
if (SimulateProofFailures != null) yield return $"SimulateProofFailures={SimulateProofFailures}";
|
2024-03-13 09:14:11 +00:00
|
|
|
|
if (MarketplaceConfig != null) yield return $"MarketplaceSetup={MarketplaceConfig.MarketplaceSetup}";
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-13 09:14:11 +00:00
|
|
|
|
|
|
|
|
|
public class MarketplaceSetup : IMarketplaceSetup
|
|
|
|
|
{
|
|
|
|
|
public bool IsStorageNode { get; private set; }
|
|
|
|
|
public bool IsValidator { get; private set; }
|
2024-03-26 14:35:26 +00:00
|
|
|
|
public Ether InitialEth { get; private set; } = 0.Eth();
|
|
|
|
|
public TestToken InitialTestTokens { get; private set; } = 0.TestTokens();
|
|
|
|
|
public EthAccount EthAccount { get; private set; } = EthAccount.GenerateNew();
|
2024-03-13 09:14:11 +00:00
|
|
|
|
|
|
|
|
|
public IMarketplaceSetup AsStorageNode()
|
|
|
|
|
{
|
|
|
|
|
IsStorageNode = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IMarketplaceSetup AsValidator()
|
|
|
|
|
{
|
|
|
|
|
IsValidator = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 14:35:26 +00:00
|
|
|
|
public IMarketplaceSetup WithAccount(EthAccount account)
|
|
|
|
|
{
|
|
|
|
|
EthAccount = account;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IMarketplaceSetup WithInitial(Ether eth, TestToken tokens)
|
|
|
|
|
{
|
|
|
|
|
InitialEth = eth;
|
|
|
|
|
InitialTestTokens = tokens;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 09:14:11 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2024-03-13 09:29:26 +00:00
|
|
|
|
var result = "[(clientNode)"; // When marketplace is enabled, being a clientNode is implicit.
|
2024-03-13 09:14:11 +00:00
|
|
|
|
result += IsStorageNode ? "(storageNode)" : "()";
|
2024-03-26 14:35:26 +00:00
|
|
|
|
result += IsValidator ? "(validator)" : "() ";
|
|
|
|
|
result += $"Address: '{EthAccount.EthAddress}' ";
|
|
|
|
|
result += $"InitialEth/TT({InitialEth.Eth}/{InitialTestTokens.Amount})";
|
|
|
|
|
result += "] ";
|
2024-03-13 09:14:11 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|