-
Notifications
You must be signed in to change notification settings - Fork 690
XDC Discovery #11527
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
Merged
Merged
XDC Discovery #11527
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
659c481
feat: implement XDC discovery application and related handlers
batrr b349f84
feat: update message serialization and discovery handlers for XDC com…
batrr 59c8028
fix: revert newline at end of packages.lock.json
batrr 79f90cb
feat: update copyright year to 2026 and add XDC discovery tests
batrr 3adf017
Merge branch 'master' into feat/xdc-discovery
ak88 d333ab2
remove removed capabilities
ak88 e2f5ace
remove ENR from XDC
ak88 f79c9e0
feat: enhance XDC discovery configuration and update mainnet bootnodes
batrr 8ce1e95
Merge branch 'master' into feat/xdc-discovery
batrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/Nethermind/Nethermind.Xdc.Test/Discovery/XdcDiscoveryTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using System.Net; | ||
| using DotNetty.Buffers; | ||
| using Nethermind.Core; | ||
| using Nethermind.Core.Test.Builders; | ||
| using Nethermind.Crypto; | ||
| using Nethermind.Network; | ||
| using Nethermind.Network.Discovery; | ||
| using Nethermind.Network.Discovery.Messages; | ||
| using Nethermind.Network.Test; | ||
| using Nethermind.Xdc.Discovery; | ||
| using NSubstitute; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Nethermind.Xdc.Test.Discovery; | ||
|
|
||
| [TestFixture, Parallelizable(ParallelScope.All)] | ||
| public class XdcDiscoveryTests | ||
| { | ||
| [Test] | ||
| public void XdcPingMsgSerializer_WritesXdcTypeByte() | ||
| { | ||
| // Packet layout: 32-byte MDC + 64-byte sig + 1-byte recovery id + 1-byte type = type at index 97 | ||
| Ecdsa ecdsa = new(); | ||
| XdcPingMsgSerializer serializer = new(ecdsa, new SameKeyGenerator(TestItem.PrivateKeyA), new NodeIdResolver(ecdsa)); | ||
| PingMsg msg = new( | ||
| TestItem.PublicKeyA, | ||
| Timestamper.Default.UnixTime.SecondsLong + 1200, | ||
| new(IPAddress.Loopback, 30303), | ||
| new(IPAddress.Loopback, 30304), | ||
| new byte[32] | ||
| ); | ||
|
|
||
| using DisposableByteBuffer buffer = Unpooled.Buffer().AsDisposable(); | ||
| serializer.Serialize(buffer, msg); | ||
| Assert.That(buffer.GetByte(97), Is.EqualTo((byte)5)); | ||
| } | ||
|
|
||
| private sealed class ExposedXdcNettyDiscoveryHandler : XdcNettyDiscoveryHandler | ||
| { | ||
| public ExposedXdcNettyDiscoveryHandler() | ||
| : base( | ||
| Substitute.For<IDiscoveryMsgListener>(), | ||
| Substitute.For<DotNetty.Transport.Channels.IChannel>(), | ||
| Substitute.For<IMessageSerializationService>(), | ||
| Timestamper.Default, | ||
| Nethermind.Logging.LimboLogs.Instance) | ||
| { | ||
| } | ||
|
|
||
| public MsgType? ExposedFromMsgTypeByte(byte b) => FromMsgTypeByte(b); | ||
| } | ||
|
|
||
| [TestCase((byte)5, MsgType.Ping)] | ||
| [TestCase((byte)1, null)] | ||
| public void XdcNettyDiscoveryHandler_FromMsgTypeByte(byte input, MsgType? expected) | ||
| { | ||
| ExposedXdcNettyDiscoveryHandler handler = new(); | ||
| Assert.That(handler.ExposedFromMsgTypeByte(input), Is.EqualTo(expected)); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
src/Nethermind/Nethermind.Xdc/Discovery/XdcDiscoveryApp.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using Autofac.Features.AttributeFilters; | ||
| using DotNetty.Transport.Channels; | ||
| using Nethermind.Config; | ||
| using Nethermind.Core; | ||
| using Nethermind.Crypto; | ||
| using Nethermind.Db; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Network; | ||
| using Nethermind.Network.Config; | ||
| using Nethermind.Network.Discovery; | ||
| using Nethermind.Network.Discovery.RoutingTable; | ||
|
|
||
| namespace Nethermind.Xdc.Discovery; | ||
|
|
||
| // Parameters mirror DiscoveryApp so Autofac resolves [KeyFilter] attributes via WithAttributeFiltering(). | ||
| public class XdcDiscoveryApp( | ||
| [KeyFilter(IProtectedPrivateKey.NodeKey)] IProtectedPrivateKey nodeKey, | ||
| INodesLocator nodesLocator, | ||
| IDiscoveryManager? discoveryManager, | ||
| INodeTable? nodeTable, | ||
| IMessageSerializationService? msgSerializationService, | ||
| ICryptoRandom? cryptoRandom, | ||
| [KeyFilter(DbNames.DiscoveryNodes)] INetworkStorage? discoveryStorage, | ||
| DiscoveryPersistenceManager discoveryPersistenceManager, | ||
| IProcessExitSource processExitSource, | ||
| INetworkConfig? networkConfig, | ||
| IDiscoveryConfig? discoveryConfig, | ||
| ITimestamper? timestamper, | ||
| ILogManager? logManager, | ||
| NodeFilter? inboundMessageFilter = null) | ||
| : DiscoveryApp(nodeKey, nodesLocator, discoveryManager, nodeTable, msgSerializationService, cryptoRandom, | ||
| discoveryStorage, discoveryPersistenceManager, processExitSource, networkConfig, discoveryConfig, | ||
| timestamper, logManager, inboundMessageFilter) | ||
| { | ||
| protected override NettyDiscoveryHandler CreateDiscoveryHandler(IChannel channel) => | ||
| new XdcNettyDiscoveryHandler(_discoveryManager, channel, _messageSerializationService, _timestamper, _logManager, _inboundMessageFilter); | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
src/Nethermind/Nethermind.Xdc/Discovery/XdcNettyDiscoveryHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using DotNetty.Transport.Channels; | ||
| using Nethermind.Core; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Network; | ||
| using Nethermind.Network.Discovery; | ||
| using Nethermind.Network.Discovery.Messages; | ||
|
|
||
| namespace Nethermind.Xdc.Discovery; | ||
|
|
||
| public class XdcNettyDiscoveryHandler( | ||
| IDiscoveryMsgListener? discoveryManager, | ||
| IChannel? channel, | ||
| IMessageSerializationService? msgSerializationService, | ||
| ITimestamper? timestamper, | ||
| ILogManager? logManager, | ||
| NodeFilter? inboundMessageFilter = null) | ||
| : NettyDiscoveryHandler(discoveryManager, channel, msgSerializationService, timestamper, logManager, inboundMessageFilter) | ||
| { | ||
| // XDC remapped the standard disc-v4 type bytes: byte 1 (standard Ping) is unused; | ||
| // byte 5 is XDC's pingXDC. ENR (bytes 5/6 in standard geth) is not supported by XDC | ||
| protected override MsgType? FromMsgTypeByte(byte b) => b switch | ||
|
batrr marked this conversation as resolved.
|
||
| { | ||
| 2 => MsgType.Pong, | ||
| 3 => MsgType.FindNode, | ||
| 4 => MsgType.Neighbors, | ||
| 5 => MsgType.Ping, | ||
| _ => null | ||
| }; | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
src/Nethermind/Nethermind.Xdc/Discovery/XdcNodeLifecycleManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using Nethermind.Core; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Network.Discovery; | ||
| using Nethermind.Network.Discovery.Lifecycle; | ||
| using Nethermind.Network.Discovery.RoutingTable; | ||
| using Nethermind.Network.Enr; | ||
| using Nethermind.Stats; | ||
| using Nethermind.Stats.Model; | ||
|
|
||
| namespace Nethermind.Xdc.Discovery; | ||
|
|
||
| /// <summary>XDC-aware lifecycle manager that suppresses ENR requests.</summary> | ||
| /// <remarks> | ||
| /// XDC does not support ENR (disc-v4 bytes 5/6). XDC remaps byte 5 to its own pingXDC type, | ||
| /// so a standard ENR request would be misread as a Ping by XDC peers. | ||
| /// </remarks> | ||
| public class XdcNodeLifecycleManager( | ||
| Node node, | ||
| IDiscoveryManager discoveryManager, | ||
| INodeTable nodeTable, | ||
| IEvictionManager evictionManager, | ||
| INodeStats nodeStats, | ||
| NodeRecord nodeRecord, | ||
| IDiscoveryConfig discoveryConfig, | ||
| ITimestamper timestamper, | ||
| ILogger logger) | ||
| : NodeLifecycleManager(node, discoveryManager, nodeTable, evictionManager, nodeStats, nodeRecord, discoveryConfig, timestamper, logger) | ||
| { | ||
| protected override void SendEnrRequest() { } | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/Nethermind/Nethermind.Xdc/Discovery/XdcNodeLifecycleManagerFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using System; | ||
| using Nethermind.Core; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Network.Discovery; | ||
| using Nethermind.Network.Discovery.Lifecycle; | ||
| using Nethermind.Network.Discovery.RoutingTable; | ||
| using Nethermind.Network.Enr; | ||
| using Nethermind.Stats; | ||
| using Nethermind.Stats.Model; | ||
|
|
||
| namespace Nethermind.Xdc.Discovery; | ||
|
|
||
| public class XdcNodeLifecycleManagerFactory( | ||
| INodeTable nodeTable, | ||
| IEvictionManager evictionManager, | ||
| INodeStatsManager nodeStatsManager, | ||
| INodeRecordProvider nodeRecordProvider, | ||
| IDiscoveryConfig discoveryConfig, | ||
| ITimestamper timestamper, | ||
| ILogManager? logManager) : INodeLifecycleManagerFactory | ||
| { | ||
| private readonly INodeTable _nodeTable = nodeTable ?? throw new ArgumentNullException(nameof(nodeTable)); | ||
| private readonly ILogger _logger = logManager?.GetClassLogger<XdcNodeLifecycleManagerFactory>() ?? throw new ArgumentNullException(nameof(logManager)); | ||
| private readonly IDiscoveryConfig _discoveryConfig = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig)); | ||
| private readonly ITimestamper _timestamper = timestamper ?? throw new ArgumentNullException(nameof(timestamper)); | ||
| private readonly IEvictionManager _evictionManager = evictionManager ?? throw new ArgumentNullException(nameof(evictionManager)); | ||
| private readonly INodeStatsManager _nodeStatsManager = nodeStatsManager ?? throw new ArgumentNullException(nameof(nodeStatsManager)); | ||
| private readonly NodeRecord _selfNodeRecord = (nodeRecordProvider ?? throw new ArgumentNullException(nameof(nodeRecordProvider))).Current; | ||
|
|
||
| public IDiscoveryManager? DiscoveryManager { private get; set; } | ||
| public NodeRecord SelfNodeRecord => _selfNodeRecord; | ||
|
|
||
| public INodeLifecycleManager CreateNodeLifecycleManager(Node node) | ||
| { | ||
| if (DiscoveryManager is null) | ||
| throw new Exception($"{nameof(DiscoveryManager)} has to be set"); | ||
|
|
||
| return new XdcNodeLifecycleManager( | ||
| node, | ||
| DiscoveryManager, | ||
| _nodeTable, | ||
| _evictionManager, | ||
| _nodeStatsManager.GetOrAdd(node), | ||
| _selfNodeRecord, | ||
| _discoveryConfig, | ||
| _timestamper, | ||
| _logger); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/Nethermind/Nethermind.Xdc/Discovery/XdcPingMsgSerializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using Autofac.Features.AttributeFilters; | ||
| using Nethermind.Crypto; | ||
| using Nethermind.Network.Discovery.Messages; | ||
| using Nethermind.Network.Discovery.Serializers; | ||
|
|
||
| namespace Nethermind.Xdc.Discovery; | ||
|
|
||
| public class XdcPingMsgSerializer(IEcdsa ecdsa, [KeyFilter(IProtectedPrivateKey.NodeKey)] IPrivateKeyGenerator nodeKey, INodeIdResolver nodeIdResolver) | ||
| : PingMsgSerializer(ecdsa, nodeKey, nodeIdResolver) | ||
| { | ||
| protected override byte MsgTypeByte => 5; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.