Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/disable nodedata on halfpath #7906

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Init/Steps/InitializeNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ private async Task InitPeer()
{
_api.ProtocolsManager!.AddSupportedCapability(new Capability(Protocol.Snap, 1));
}
if (!_api.WorldStateManager!.SupportHashLookup)
{
_api.ProtocolsManager!.RemoveSupportedCapability(new Capability(Protocol.NodeData, 1));
}

_api.ProtocolValidator = protocolValidator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,16 @@ public void On_init_sends_a_hello_message()
public void On_init_sends_a_hello_message_with_capabilities()
{
P2PProtocolHandler p2PProtocolHandler = CreateSession();
string[] expectedCapabilities = ["eth66", "eth67", "eth68", "nodedata1"];

// These are called by ProtocolsManager.
p2PProtocolHandler.AddSupportedCapability(new Capability(Protocol.Eth, 66));
p2PProtocolHandler.AddSupportedCapability(new Capability(Protocol.Eth, 67));
p2PProtocolHandler.AddSupportedCapability(new Capability(Protocol.Eth, 68));
p2PProtocolHandler.AddSupportedCapability(new Capability(Protocol.NodeData, 1));

p2PProtocolHandler.Init();

string[] expectedCapabilities = ["eth66", "eth67", "eth68", "nodedata1"];
_session.Received(1).DeliverMessage(
Arg.Is<HelloMessage>(m => m.Capabilities.Select(c => c.ToString()).SequenceEqual(expectedCapabilities)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class P2PProtocolInfoProvider
public static int GetHighestVersionOfEthProtocol()
{
int highestVersion = 0;
foreach (Capability ethProtocol in P2PProtocolHandler.DefaultCapabilities)
foreach (Capability ethProtocol in ProtocolsManager.DefaultCapabilities)
{
if (ethProtocol.ProtocolCode == Protocol.Eth && highestVersion < ethProtocol.Version)
highestVersion = ethProtocol.Version;
Expand All @@ -25,7 +25,7 @@ public static int GetHighestVersionOfEthProtocol()

public static string DefaultCapabilitiesToString()
{
IEnumerable<string> capabilities = P2PProtocolHandler.DefaultCapabilities
IEnumerable<string> capabilities = ProtocolsManager.DefaultCapabilities
.OrderBy(x => x.ProtocolCode).ThenByDescending(x => x.Version)
.Select(x => $"{x.ProtocolCode}/{x.Version}");
return string.Join(",", capabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ public class P2PProtocolHandler(

protected override TimeSpan InitTimeout => Timeouts.P2PHello;

public static readonly IEnumerable<Capability> DefaultCapabilities = new Capability[]
{
new(Protocol.Eth, 66),
new(Protocol.Eth, 67),
new(Protocol.Eth, 68),
new(Protocol.NodeData, 1)
};

public IReadOnlyList<Capability> AgreedCapabilities { get { return _agreedCapabilities; } }
public IReadOnlyList<Capability> AvailableCapabilities { get { return _availableCapabilities; } }
private readonly List<Capability> _supportedCapabilities = DefaultCapabilities.ToList();
private readonly List<Capability> _supportedCapabilities = new List<Capability>();

public int ListenPort { get; } = session.LocalPort;
public PublicKey LocalNodeId { get; } = localNodeId;
Expand Down
13 changes: 10 additions & 3 deletions src/Nethermind/Nethermind.Network/ProtocolsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;
using Nethermind.Config;
Expand Down Expand Up @@ -35,6 +36,14 @@ namespace Nethermind.Network
{
public class ProtocolsManager : IProtocolsManager
{
public static readonly IEnumerable<Capability> DefaultCapabilities = new Capability[]
{
new(Protocol.Eth, 66),
new(Protocol.Eth, 67),
new(Protocol.Eth, 68),
new(Protocol.NodeData, 1)
};

private readonly ConcurrentDictionary<Guid, SyncPeerProtocolHandlerBase> _syncPeers = new();

private readonly ConcurrentDictionary<Node, ConcurrentDictionary<Guid, ProtocolHandlerBase>> _hangingSatelliteProtocols =
Expand All @@ -54,11 +63,10 @@ public class ProtocolsManager : IProtocolsManager
private readonly ForkInfo _forkInfo;
private readonly IGossipPolicy _gossipPolicy;
private readonly ITxGossipPolicy _txGossipPolicy;
private readonly INetworkConfig _networkConfig;
private readonly ILogManager _logManager;
private readonly ILogger _logger;
private readonly IDictionary<string, Func<ISession, int, IProtocolHandler>> _protocolFactories;
private readonly HashSet<Capability> _capabilities = new();
private readonly HashSet<Capability> _capabilities = DefaultCapabilities.ToHashSet();
private readonly Regex? _clientIdPattern;
private readonly IBackgroundTaskScheduler _backgroundTaskScheduler;
private readonly ISnapServer? _snapServer;
Expand Down Expand Up @@ -98,7 +106,6 @@ public ProtocolsManager(
_gossipPolicy = gossipPolicy ?? throw new ArgumentNullException(nameof(gossipPolicy));
_txGossipPolicy = transactionsGossipPolicy ?? ShouldGossip.Instance;
_logManager = logManager ?? throw new ArgumentNullException(nameof(logManager));
_networkConfig = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
_snapServer = snapServer;
_logger = _logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

Expand Down
15 changes: 15 additions & 0 deletions src/Nethermind/Nethermind.State.Test/WorldStateManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@ public void ShouldProxyReorgBoundaryEvent()

gotEvent.Should().BeTrue();
}

[TestCase(INodeStorage.KeyScheme.Hash, true)]
[TestCase(INodeStorage.KeyScheme.HalfPath, false)]
public void ShouldNotSupportHashLookupOnHalfpath(INodeStorage.KeyScheme keyScheme, bool hashSupported)
{
IWorldState worldState = Substitute.For<IWorldState>();
ITrieStore trieStore = Substitute.For<ITrieStore>();
IReadOnlyTrieStore readOnlyTrieStore = Substitute.For<IReadOnlyTrieStore>();
trieStore.AsReadOnly().Returns(readOnlyTrieStore);
readOnlyTrieStore.Scheme.Returns(keyScheme);
IDbProvider dbProvider = TestMemDbProvider.Init();
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, LimboLogs.Instance);

worldStateManager.SupportHashLookup.Should().Be(hashSupported);
}
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.State/IWorldStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IWorldStateManager
IWorldState GlobalWorldState { get; }
IStateReader GlobalStateReader { get; }
IReadOnlyTrieStore TrieStore { get; }
bool SupportHashLookup { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if needed as we already expose TrieStore and it already kind-of exposes Scheme, so maybe extension method would suffice? Or default implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should not expose triestore at all. Its just a bit.. un-nice at the moment.


/// <summary>
/// Used by read only tasks that need to execute blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class OverlayWorldStateManager(
public IStateReader GlobalStateReader => _reader;

public IReadOnlyTrieStore TrieStore { get; } = overlayTrieStore.AsReadOnly();
public bool SupportHashLookup => overlayTrieStore.Scheme == INodeStorage.KeyScheme.Hash;

public IWorldState CreateResettableWorldState(IWorldState? forWarmup = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public OverridableWorldStateManager(IDbProvider dbProvider, IReadOnlyTrieStore t
public IWorldState GlobalWorldState => _state;
public IStateReader GlobalStateReader => _reader;
public IReadOnlyTrieStore TrieStore => _overlayTrieStore.AsReadOnly();
public bool SupportHashLookup => _overlayTrieStore.Scheme == INodeStorage.KeyScheme.Hash;

public IWorldState CreateResettableWorldState(IWorldState? forWarmup = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ILogManager logManager
public IStateReader GlobalStateReader { get; }

public IReadOnlyTrieStore TrieStore => _readOnlyTrieStore;
public bool SupportHashLookup => _readOnlyTrieStore.Scheme == INodeStorage.KeyScheme.Hash;

public IWorldState CreateResettableWorldState(IWorldState? forWarmup = null)
{
Expand Down
Loading