Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Nethermind/Nethermind.Api/IInitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public interface IInitConfig : IConfig
[ConfigItem(Description = "The hash of the genesis block. If not specified, the genesis block validity is not checked which is useful in the case of ad hoc test/private networks.", DefaultValue = "null")]
string? GenesisHash { get; set; }

[ConfigItem(Description = "The path to the static nodes file.", DefaultValue = "Data/static-nodes.json")]
[ConfigItem(Description = "The path to the static nodes file.", DefaultValue = "static-nodes.json")]
string StaticNodesPath { get; set; }

[ConfigItem(Description = "The path to the trusted nodes file.", DefaultValue = "Data/trusted-nodes.json")]
[ConfigItem(Description = "The path to the trusted nodes file.", DefaultValue = "trusted-nodes.json")]
string TrustedNodesPath { get; set; }

[ConfigItem(Description = "The name of the log file.", DefaultValue = "log.txt")]
Expand All @@ -69,6 +69,9 @@ public interface IInitConfig : IConfig
[ConfigItem(Description = "The maximum number of bad blocks observed on the network that will be stored on disk.", DefaultValue = "100")]
long? BadBlocksStored { get; set; }

[ConfigItem(Description = "The path to the Nethermind data directory. Defaults to Nethermind's current directory.", DefaultValue = "null", HiddenFromDocs = true)]
string? DataDir { get; set; }

[ConfigItem(Description = "[TECHNICAL] Disable garbage collector on newPayload", DefaultValue = "true", HiddenFromDocs = true)]
bool DisableGcOnNewPayload { get; set; }

Expand Down
7 changes: 4 additions & 3 deletions src/Nethermind/Nethermind.Api/InitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class InitConfig : IInitConfig
public string BaseDbPath { get; set; } = "db";
public string LogFileName { get; set; } = "log.txt";
public string? GenesisHash { get; set; }
public string StaticNodesPath { get; set; } = "Data/static-nodes.json";
public string TrustedNodesPath { get; set; } = "Data/trusted-nodes.json";
public string StaticNodesPath { get; set; } = "static-nodes.json";
public string TrustedNodesPath { get; set; } = "trusted-nodes.json";
public string? KzgSetupPath { get; set; } = null;
public string LogDirectory { get; set; } = "logs";
public string? LogRules { get; set; } = null;
Expand All @@ -28,7 +28,7 @@ public class InitConfig : IInitConfig
public DiagnosticMode DiagnosticMode { get; set; } = DiagnosticMode.None;
public DumpOptions AutoDump { get; set; } = DumpOptions.Default;

public string RpcDbUrl { get; set; } = String.Empty;
public string RpcDbUrl { get; set; } = string.Empty;
public long? MemoryHint { get; set; }
public long? BadBlocksStored { get; set; } = 100;
public bool DisableGcOnNewPayload { get; set; } = true;
Expand All @@ -39,6 +39,7 @@ public class InitConfig : IInitConfig
public int BackgroundTaskConcurrency { get; set; } = 2;
public int BackgroundTaskMaxNumber { get; set; } = 1024;
public bool InRunnerTest { get; set; } = false;
public string? DataDir { get; set; }

[Obsolete("Use DiagnosticMode with MemDb instead")]
public bool UseMemDb
Expand Down
7 changes: 4 additions & 3 deletions src/Nethermind/Nethermind.Init/Modules/DiscoveryModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ protected override void Load(ContainerBuilder builder)
.AddKeyedSingleton<INodeSource>(NodeSourceToDiscV4Feeder.SourceKey, ctx => ctx.Resolve<EnrDiscovery>())

// Uses by RPC also.
.AddSingleton<IStaticNodesManager, ILogManager>((logManager) => new StaticNodesManager(initConfig.StaticNodesPath, logManager))
.AddSingleton<IStaticNodesManager, ILogManager>(logManager =>
new StaticNodesManager(initConfig.StaticNodesPath.GetApplicationResourcePath(initConfig.DataDir), logManager))
// This load from file.
.AddSingleton<NodesLoader>()

.AddSingleton<ITrustedNodesManager, ILogManager>((logManager) =>
new TrustedNodesManager(initConfig.TrustedNodesPath, logManager))
.AddSingleton<ITrustedNodesManager, ILogManager>(logManager =>
new TrustedNodesManager(initConfig.TrustedNodesPath.GetApplicationResourcePath(initConfig.DataDir), logManager))

.Bind<INodeSource, IStaticNodesManager>()

Expand Down
23 changes: 22 additions & 1 deletion src/Nethermind/Nethermind.Network/INodeSource.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Stats.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading;
using Nethermind.Stats.Model;

namespace Nethermind.Network;

public interface INodeSource
{
private static readonly char[] separator = ['\r', '\n'];

IAsyncEnumerable<Node> DiscoverNodes(CancellationToken cancellationToken);

event EventHandler<NodeEventArgs> NodeRemoved;

static ISet<string> ParseNodes(string data)
{
ISet<string>? nodes;

try
{
nodes = JsonSerializer.Deserialize<HashSet<string>>(data);
}
catch (JsonException)
{
nodes = data.Split(separator, StringSplitOptions.RemoveEmptyEntries).ToHashSet();
}

return nodes;
}
}
17 changes: 8 additions & 9 deletions src/Nethermind/Nethermind.Network/IStaticNodesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
using System.Threading.Tasks;
using Nethermind.Config;

namespace Nethermind.Network
namespace Nethermind.Network;

public interface IStaticNodesManager : INodeSource
{
public interface IStaticNodesManager : INodeSource
{
IEnumerable<NetworkNode> Nodes { get; }
Task InitAsync();
Task<bool> AddAsync(string enode, bool updateFile = true);
Task<bool> RemoveAsync(string enode, bool updateFile = true);
bool IsStatic(string enode);
}
IEnumerable<NetworkNode> Nodes { get; }
Task InitAsync();
Task<bool> AddAsync(string enode, bool updateFile = true);
Task<bool> RemoveAsync(string enode, bool updateFile = true);
bool IsStatic(string enode);
}
19 changes: 9 additions & 10 deletions src/Nethermind/Nethermind.Network/ITrustedNodesManager.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Threading.Tasks;
using Nethermind.Config;

namespace Nethermind.Network
namespace Nethermind.Network;

public interface ITrustedNodesManager : INodeSource
{
public interface ITrustedNodesManager : INodeSource
{
IEnumerable<NetworkNode> Nodes { get; }
Task InitAsync();
Task<bool> AddAsync(Enode enode, bool updateFile = true);
Task<bool> RemoveAsync(Enode enode, bool updateFile = true);
bool IsTrusted(Enode enode);
}
IEnumerable<NetworkNode> Nodes { get; }
Task InitAsync();
Task<bool> AddAsync(Enode enode, bool updateFile = true);
Task<bool> RemoveAsync(Enode enode, bool updateFile = true);
bool IsTrusted(Enode enode);
}
13 changes: 3 additions & 10 deletions src/Nethermind/Nethermind.Network/Nethermind.Network.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,13 @@
</ItemGroup>
<ItemGroup>
<Compile Remove="Swarm\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="Swarm\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Swarm\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Whisper\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="Whisper\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Whisper\**" />
<EmbeddedResource Include="StaticNodes\static-nodes.json">
<LogicalName>static-nodes.json</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>
Loading