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

Option to run Discovery V4 and V5 on the same port #7213

Merged
merged 115 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
c886f9d
Override RLP decoders with ones from plugins (tx receipt only for now…
flcl42 May 2, 2024
9e18fe7
Init decoder in a method; default impl
flcl42 May 2, 2024
d21cae5
fix
deffrian May 2, 2024
28f10e5
Pass the fork timestamp
flcl42 May 3, 2024
0cfb439
Fix params extraction
flcl42 May 3, 2024
df0c9dc
Merge branch 'master' into receipt-decoder-di
flcl42 May 6, 2024
9aa23e4
Fix test
flcl42 May 6, 2024
30fe6dd
Fix typo
flcl42 May 6, 2024
e72a784
Change DI for receipt decoders
flcl42 May 8, 2024
e07a890
Merge master into receipt-decoder-di
flcl42 May 8, 2024
19f6fe8
Fix whitespace
flcl42 May 8, 2024
c458e58
Fix decoders discovery
flcl42 May 8, 2024
4e16b1c
Fix ctor
flcl42 May 8, 2024
ea51ea9
Improve a trace
flcl42 May 8, 2024
74b9c45
x16
flcl42 May 10, 2024
d92ec7a
Merge branch 'master' into fix/ecotone-fee
deffrian May 13, 2024
5c666cb
Improve decoders instantiation
flcl42 May 13, 2024
7862a9d
Improve RegisterDecoder
flcl42 May 13, 2024
06b0007
Refactor rpc modules initialization
deffrian May 13, 2024
8966716
Fix AA
flcl42 May 13, 2024
9482a82
Clean up
flcl42 May 13, 2024
fee4d1e
Merge branch 'receipt-decoder-di' into op-2
flcl42 May 13, 2024
398a037
Merge remote-tracking branch 'origin/fix/ecotone-fee' into op-2
flcl42 May 13, 2024
c88c88d
sendRawTransaction
deffrian May 13, 2024
cac3915
Add discv5
flcl42 May 13, 2024
52bff34
Logs
flcl42 May 14, 2024
8e37997
Hide debug logs
flcl42 May 14, 2024
c861a42
Merge remote-tracking branch 'origin/fix/optimism-send-tx' into op-2
flcl42 May 14, 2024
ba34eab
Fix configs
flcl42 May 15, 2024
1b10a36
Revert "Hide debug logs"
flcl42 May 15, 2024
c5036fb
Enable v4; add more distances
flcl42 May 15, 2024
71acc59
Custom random walk
flcl42 May 15, 2024
849ecda
Fixes
flcl42 May 21, 2024
e3271de
Custom random walk
flcl42 May 22, 2024
682ba62
Merge master into op-2
flcl42 May 22, 2024
6c3f4fe
Fixes
flcl42 May 22, 2024
402a1ad
Refactor interface
deffrian May 23, 2024
bd6a882
Compute fields; fix spec
flcl42 May 28, 2024
183daf2
Deduplicate via generics and inheritence
flcl42 May 29, 2024
8155b96
Merge fix/op-receipts-rpc into discv5
flcl42 May 29, 2024
f89e700
Use custom distances during discovery
flcl42 May 29, 2024
64ae02d
Refactor DiscoveryReport a bit
flcl42 Jun 6, 2024
fd765d4
Merge master into discv5
flcl42 Jun 10, 2024
d01b8ca
Fix merge; remove redundant project fixes; update discv5
flcl42 Jun 12, 2024
f70bbb0
Merge remote-tracking branch 'origin/master' into discv5
flcl42 Jun 12, 2024
c0db854
Temporary fix bouncy castle dep hell
flcl42 Jun 12, 2024
4a32ff2
Fix discv5
flcl42 Jun 12, 2024
d94e7f5
Improve logging
flcl42 Jun 13, 2024
230eba5
Remove redundant pieces
flcl42 Jun 14, 2024
a722376
Merge master into discv5
flcl42 Jun 14, 2024
6a15d4a
Fix build
alexb5dh Jun 19, 2024
d469569
[WIP] Try to delegate messages from Discv5 implementation to `NettyDi…
alexb5dh Jun 19, 2024
d1873e4
[WIP] Use single DotNetty channel for both v4 and v5
alexb5dh Jun 20, 2024
e2e7bdc
Fix discv5
flcl42 Jun 20, 2024
280638e
Compilation fix
flcl42 Jun 20, 2024
5af29a7
Merge remote-tracking branch 'origin/discv5' into discv5-v4-same-port
alexb5dh Jun 20, 2024
cb3ec2e
[WIP] Added multi-version handler
alexb5dh Jun 21, 2024
2a02a22
[WIP] Switch to implementation via Netty handlers
alexb5dh Jun 23, 2024
88f8f87
[WIP] Remove unused classes
alexb5dh Jun 23, 2024
650d494
Formatting fix
alexb5dh Jun 23, 2024
aadfefd
Remove broken `NoVersionMatchDiscoveryHandler`
alexb5dh Jun 24, 2024
239d162
Fix v5 handler dependencies
alexb5dh Jun 24, 2024
88cdb8f
Fix Discovery initialization
alexb5dh Jun 24, 2024
6adc025
Fix v5 configuration
alexb5dh Jun 24, 2024
8eda321
Fixed v5 port reuse
alexb5dh Jun 24, 2024
803cd33
Fix handlers flow
alexb5dh Jun 24, 2024
bc22b5f
Code cleanup
alexb5dh Jun 24, 2024
006bc48
Remove submodule
flcl42 Jun 24, 2024
22a6c20
Fixed packet release
alexb5dh Jun 24, 2024
61c0fa7
Use prod nuget
flcl42 Jun 25, 2024
bea21fa
Merge master into discv5
flcl42 Jun 25, 2024
47a1577
Fix a whitespace
flcl42 Jun 25, 2024
48741b7
Temporary add alias
flcl42 Jun 25, 2024
ca53b05
Remove submodule traces
flcl42 Jun 25, 2024
9e42610
Roll back log change
flcl42 Jun 25, 2024
9b835cf
Merge master into discv5
flcl42 Jun 25, 2024
e3ebf35
Updated services registration
alexb5dh Jun 27, 2024
58695bd
Fixed packet sending
alexb5dh Jun 27, 2024
c7fd532
Fixed Discovery protocol starting
alexb5dh Jun 27, 2024
d3f798c
Fixed empty packet forwarded to V5
alexb5dh Jun 27, 2024
04e1d86
Merge remote-tracking branch 'origin/discv5' into discv5-v4-same-port
alexb5dh Jun 27, 2024
e0b5a27
Update PierTwo.Lantern.Discv5.WireProtocol to preview 4
alexb5dh Jun 27, 2024
6cfa9ed
Configuration update
alexb5dh Jun 28, 2024
7dbc402
Code cleanup
alexb5dh Jun 28, 2024
2425bac
Basic tests
alexb5dh Jul 8, 2024
e318a4d
Remove irrelevant packet-size validation
alexb5dh Jul 8, 2024
6575a65
Simplify `NettyDiscoveryV5Handler` packet-building
alexb5dh Jul 8, 2024
b503432
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Jul 8, 2024
93ccc60
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Jul 11, 2024
e05d8d6
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Jul 15, 2024
43cc437
Refactor discovery initialization code to a separate class
alexb5dh Jul 17, 2024
9ee6e8f
Invoke `NodeAdded`/`NodeRemoved` for v5 also
alexb5dh Jul 18, 2024
ac84438
Enable only v4 by default
alexb5dh Jul 18, 2024
aeb5c7f
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Jul 18, 2024
a068329
Code cleanup
alexb5dh Jul 18, 2024
2ab9329
Do not include externally-added nodes to v5
alexb5dh Jul 18, 2024
d153140
Code cleanup
alexb5dh Jul 18, 2024
f83e0b9
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Jul 25, 2024
a0861aa
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Jul 27, 2024
56102ee
Allow to add nodes to Discovery V5 from external sources
alexb5dh Jul 28, 2024
c95158e
Simplify getting ENR from a node
alexb5dh Jul 28, 2024
3b32c79
Test fix
alexb5dh Jul 31, 2024
51678ed
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Jul 31, 2024
8a53957
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Aug 4, 2024
d8049ff
Use interfaces to simplify testing
alexb5dh Aug 5, 2024
1adf764
Adjust `ActivePeers` check
alexb5dh Aug 5, 2024
ae96529
Added `NettyDiscoveryBaseHandler` and packet size validation
alexb5dh Aug 5, 2024
9366326
v5 tests for messages of invalid size
alexb5dh Aug 6, 2024
700e3c4
Code cleanup
alexb5dh Aug 6, 2024
1107984
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Aug 8, 2024
b29df82
Simplify `IFullDb` dependency
alexb5dh Aug 8, 2024
82bc93e
Limit `NettyDiscoveryV5Handler` inbound buffer
alexb5dh Aug 8, 2024
5de9c47
Replace `IApiWithNetwork` with direct dependencies
alexb5dh Aug 8, 2024
9c971c1
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
alexb5dh Aug 12, 2024
25d2e11
Code cleanup
alexb5dh Aug 12, 2024
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
Prev Previous commit
Next Next commit
[WIP] Added multi-version handler
  • Loading branch information
alexb5dh committed Jun 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit cb3ec2e2361027c9db0fad94991ca9590d9de0e4
9 changes: 6 additions & 3 deletions src/Nethermind/Nethermind.Network.Discovery/DiscoveryApp.cs
Original file line number Diff line number Diff line change
@@ -31,14 +31,13 @@ public class DiscoveryApp : IDiscoveryApp
private readonly IDiscoveryManager _discoveryManager;
private readonly INodeTable _nodeTable;
private readonly ILogManager _logManager;
private readonly MultiVersionDiscoveryHandler _multiVersionDiscoveryHandler;
private readonly ILogger _logger;
private readonly IMessageSerializationService _messageSerializationService;
private readonly ICryptoRandom _cryptoRandom;
private readonly INetworkStorage _discoveryStorage;
private readonly INetworkConfig _networkConfig;

private Task? _discoveryTimerTask;

private IChannel? _channel;
private MultithreadEventLoopGroup? _group;
private NettyDiscoveryHandler? _discoveryHandler;
@@ -53,9 +52,11 @@ public DiscoveryApp(INodesLocator nodesLocator,
INetworkConfig? networkConfig,
IDiscoveryConfig? discoveryConfig,
ITimestamper? timestamper,
ILogManager? logManager)
ILogManager? logManager,
MultiVersionDiscoveryHandler multiVersionDiscoveryHandler)
{
_logManager = logManager ?? throw new ArgumentNullException(nameof(logManager));
_multiVersionDiscoveryHandler = multiVersionDiscoveryHandler;
_logger = _logManager.GetClassLogger();
_discoveryConfig = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
_timestamper = timestamper ?? throw new ArgumentNullException(nameof(timestamper));
@@ -169,6 +170,8 @@ private void InitializeChannel(IDatagramChannel channel)
_discoveryManager.MsgSender = _discoveryHandler;
_discoveryHandler.OnChannelActivated += OnChannelActivated;

_multiVersionDiscoveryHandler.AddHandlerV4(_discoveryHandler);

channel.Pipeline
.AddLast(new LoggingHandler(LogLevel.INFO))
.AddLast(_discoveryHandler);
Original file line number Diff line number Diff line change
@@ -190,10 +190,9 @@ public void Initialize(PublicKey masterPublicKey)
{
}

public Task StartAsync()
public void Start()
{
_ = DiscoverViaCustomRandomWalk();
return Task.CompletedTask;
}

private async Task DiscoverViaCustomRandomWalk()
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Net;
using System.Net.Sockets;
using DotNetty.Transport.Channels;
using DotNetty.Transport.Channels.Sockets;
using Lantern.Discv5.WireProtocol.Packet;
using Nethermind.Serialization.Rlp;

namespace Nethermind.Network.Discovery;

public class NettyDiscoveryV5Handler : SimpleChannelInboundHandler<DatagramPacket>
{
private readonly IPacketManager _packetManager;

public NettyDiscoveryV5Handler(IPacketManager packetManager)
{
_packetManager = packetManager;
}

protected override void ChannelRead0(IChannelHandlerContext ctx, DatagramPacket msg)
{
var udpPacket = new UdpReceiveResult(msg.Content.ReadAllBytesAsArray(), (IPEndPoint) msg.Sender);

// Explicitly run it on the default scheduler to prevent something down the line hanging netty task scheduler.
Task.Factory.StartNew(
() => _packetManager.HandleReceivedPacket(udpPacket),
CancellationToken.None,
TaskCreationOptions.RunContinuationsAsynchronously,
TaskScheduler.Default
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using DotNetty.Transport.Channels.Sockets;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Serialization.Rlp;

namespace Nethermind.Network.Discovery;

public class MultiVersionDiscoveryHandler : SimpleChannelInboundHandler<DatagramPacket>
{
private IChannelHandler? _handlerV4;
private IChannelHandler? _handlerV5;

public void AddHandlerV4(IChannelHandler handler) => _handlerV4 = handler;
public void AddHandlerV5(IChannelHandler handler) => _handlerV5 = handler;

protected override void ChannelRead0(IChannelHandlerContext ctx, DatagramPacket msg)
{
IChannelHandler? handler = _handlerV4 != null && IsDiscoveryV4Packet(msg)
? _handlerV4
: _handlerV5;

handler?.ChannelRead(ctx, msg);
}

// TODO find a faster/simpler/more-reliable way
private bool IsDiscoveryV4Packet(DatagramPacket packet)
{
try
{
IByteBuffer msg = packet.Content;
if (msg.ReadableBytes < 98) return false;

Memory<byte> msgBytes = msg.ReadAllBytesAsMemory();
Memory<byte> mdc = msgBytes[..32];
Span<byte> sigAndData = msgBytes.Span[32..];
Span<byte> computedMdc = ValueKeccak.Compute(sigAndData).BytesAsSpan;

return Bytes.AreEqual(mdc.Span, computedMdc);
}
catch (Exception)
{
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -172,20 +172,6 @@ protected override void ChannelRead0(IChannelHandlerContext ctx, DatagramPacket
}
}

// TODO find a faster/simpler/more-reliable way
private bool IsDiscoveryV5Packet(UdpReceiveResult packet)
{
try
{
//return Enum.IsDefined((PacketType) _packetProcessor.GetStaticHeader(packet.Buffer).Flag);
return false;
}
catch (Exception)
{
return false;
}
}

private DiscoveryMsg Deserialize(MsgType type, byte[] msg)
{
return type switch