Bootstrapping waku nodes

This commit is contained in:
benbierens 2023-09-25 15:14:51 +02:00
parent 30ba382db7
commit 12f6710a56
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
8 changed files with 128 additions and 46 deletions

View File

@ -5,45 +5,26 @@ namespace WakuPlugin
{
public static class CoreInterfaceExtensions
{
public static RunningContainers[] DeployWakuNodes(this CoreInterface ci, int number)
public static RunningContainers[] DeployWakuNodes(this CoreInterface ci, int number, Action<IWakuSetup> setup)
{
return Plugin(ci).DeployWakuNodes(number);
return Plugin(ci).DeployWakuNodes(number, setup);
}
//public static ICodexNodeGroup WrapCodexContainers(this CoreInterface ci, RunningContainer[] containers)
//{
// // ew, clean this up.
// var rcs = new RunningContainers(null!, containers.First().Pod, containers);
// return WrapCodexContainers(ci, new[] { rcs });
//}
public static IWakuNode WrapWakuContainer(this CoreInterface ci, RunningContainer container)
{
return Plugin(ci).WrapWakuContainer(container);
}
//public static ICodexNodeGroup WrapCodexContainers(this CoreInterface ci, RunningContainers[] containers)
//{
// return Plugin(ci).WrapCodexContainers(ci, containers);
//}
public static IWakuNode StartWakuNode(this CoreInterface ci)
{
return ci.StartWakuNode(s => { });
}
//public static ICodexNode StartCodexNode(this CoreInterface ci)
//{
// return ci.StartCodexNodes(1)[0];
//}
//public static ICodexNode StartCodexNode(this CoreInterface ci, Action<ICodexSetup> setup)
//{
// return ci.StartCodexNodes(1, setup)[0];
//}
//public static ICodexNodeGroup StartCodexNodes(this CoreInterface ci, int number, Action<ICodexSetup> setup)
//{
// var rc = ci.DeployCodexNodes(number, setup);
// var result = ci.WrapCodexContainers(rc);
// Plugin(ci).WireUpMarketplace(result, setup);
// return result;
//}
//public static ICodexNodeGroup StartCodexNodes(this CoreInterface ci, int number)
//{
// return ci.StartCodexNodes(number, s => { });
//}
public static IWakuNode StartWakuNode(this CoreInterface ci, Action<IWakuSetup> setup)
{
var rc = ci.DeployWakuNodes(1, setup);
return ci.WrapWakuContainer(rc.First().Containers.First());
}
private static WakuPlugin Plugin(CoreInterface ci)
{

View File

@ -0,0 +1,8 @@
namespace WakuPlugin
{
public class DebugInfoResponse
{
public string[] listenAddresses { get; set; }
public string enrUri { get; set; }
}
}

View File

@ -11,22 +11,28 @@ namespace WakuPlugin
protected override void Initialize(StartupConfig startupConfig)
{
var config = startupConfig.Get<WakuSetup>();
SetResourcesRequest(milliCPUs: 100, memory: 100.MB());
SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
AddInternalPortAndVar("WAKUNODE2_TCP_PORT");
AddEnvVar("WAKUNODE2_RPC_ADDRESS", "0.0.0.0");
AddEnvVar("WAKUNODE2_LOG_LEVEL", "TRACE");
AddEnvVar("WAKUNODE2_REST", "1");
AddEnvVar("WAKUNODE2_REST_ADDRESS", "0.0.0.0");
AddExposedPortAndVar("WAKUNODE2_REST_PORT", "restport");
AddEnvVar("WAKUNODE2_REST_ADDRESS", "0.0.0.0");
AddInternalPortAndVar("WAKUNODE2_TCP_PORT");
AddEnvVar("WAKUNODE2_RPC_ADDRESS", "0.0.0.0");
AddEnvVar("WAKUNODE2_DISCV5_DISCOVERY", "1");
AddInternalPortAndVar("WAKUNODE2_DISCV5_UDP_PORT");
//AddEnvVar("WAKUNODE2_DISCV5_BOOTSTRAP_NODE", "________<---- enr here");
AddEnvVar("WAKUNODE2_DISCV5_ENR_AUTO_UPDATEY", "1");
if (!string.IsNullOrEmpty(config.BootstrapEnr))
{
AddEnvVar("WAKUNODE2_DISCV5_BOOTSTRAP_NODE", config.BootstrapEnr);
}
AddEnvVar("WAKUNODE2_TOPICS", "test_topics_plz");
}
}

View File

@ -0,0 +1,33 @@
using Core;
using KubernetesWorkflow;
namespace WakuPlugin
{
public interface IWakuNode : IHasContainer
{
DebugInfoResponse DebugInfo();
}
public class WakuNode : IWakuNode
{
private readonly IPluginTools tools;
public WakuNode(IPluginTools tools, RunningContainer container)
{
this.tools = tools;
Container = container;
}
public RunningContainer Container { get; }
public DebugInfoResponse DebugInfo()
{
return Http().HttpGetJson<DebugInfoResponse>("debug/v1/info");
}
private IHttp Http()
{
return tools.CreateHttp(Container.Address, "");
}
}
}

View File

@ -30,9 +30,15 @@ namespace WakuPlugin
{
}
public RunningContainers[] DeployWakuNodes(int numberOfNodes)
public RunningContainers[] DeployWakuNodes(int numberOfNodes, Action<IWakuSetup> setup)
{
return starter.Start(numberOfNodes);
return starter.Start(numberOfNodes, setup);
}
public IWakuNode WrapWakuContainer(RunningContainer container)
{
container = SerializeGate.Gate(container);
return starter.Wrap(container);
}
//public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningContainers[] containers)

View File

@ -0,0 +1,25 @@
namespace WakuPlugin
{
public interface IWakuSetup
{
IWakuSetup WithBootstrapNode(IWakuNode node);
}
public class WakuSetup : IWakuSetup
{
internal string? Name { get; private set; }
internal string? BootstrapEnr { get; private set; }
public IWakuSetup WithName(string name)
{
Name = name;
return this;
}
public IWakuSetup WithBootstrapNode(IWakuNode node)
{
BootstrapEnr = node.DebugInfo().enrUri;
return this;
}
}
}

View File

@ -12,17 +12,33 @@ namespace WakuPlugin
this.tools = tools;
}
public RunningContainers[] Start(int numberOfNodes)
public RunningContainers[] Start(int numberOfNodes, Action<IWakuSetup> setup)
{
var result = new List<RunningContainers>();
var workflow = tools.CreateWorkflow();
var startupConfig = CreateStartupConfig(setup);
for (var i = 0; i < numberOfNodes; i++)
{
result.Add(workflow.Start(1, new WakuPluginContainerRecipe(), new StartupConfig()));
result.Add(workflow.Start(1, new WakuPluginContainerRecipe(), startupConfig));
}
return result.ToArray();
}
public IWakuNode Wrap(RunningContainer container)
{
return new WakuNode(tools, container);
}
private StartupConfig CreateStartupConfig(Action<IWakuSetup> setup)
{
var config = new WakuSetup();
setup(config);
var startupConfig = new StartupConfig();
startupConfig.Add(config);
startupConfig.NameOverride = config.Name;
return startupConfig;
}
}
}

View File

@ -8,9 +8,16 @@ namespace WakuTests
[Test]
public void Hi()
{
var rc = Ci.DeployWakuNodes(1);
var node1 = Ci.StartWakuNode();
var info1 = node1.DebugInfo();
Assert.That(info1.enrUri, Is.Not.Empty);
var node2 = Ci.StartWakuNode(s => s.WithBootstrapNode(node1));
var info2 = node2.DebugInfo();
Assert.That(info2.enrUri, Is.Not.Empty);
var i = 0;
}
}
}