-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/end to end discovery test (#8098)
- Loading branch information
Showing
31 changed files
with
543 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
93 changes: 93 additions & 0 deletions
93
src/Nethermind/Nethermind.Core.Test/Modules/DiscoveryModule.cs
This file contains 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,93 @@ | ||
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Linq; | ||
using Autofac; | ||
using Nethermind.Api; | ||
using Nethermind.Crypto; | ||
using Nethermind.Logging; | ||
using Nethermind.Network; | ||
using Nethermind.Network.Config; | ||
using Nethermind.Network.Discovery; | ||
using Nethermind.Network.Dns; | ||
using Nethermind.Network.Enr; | ||
using Nethermind.Network.StaticNodes; | ||
using Nethermind.Specs.ChainSpecStyle; | ||
|
||
namespace Nethermind.Core.Test.Modules; | ||
|
||
public class DiscoveryModule(IInitConfig initConfig, INetworkConfig networkConfig) : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder | ||
// Enr discovery uses DNS to get some bootnodes. | ||
// TODO: Node source to discovery 4 feeder. | ||
.AddSingleton<EnrDiscovery, IEthereumEcdsa, ILogManager>((ethereumEcdsa, logManager) => | ||
{ | ||
// I do not use the key here -> API is broken - no sense to use the node signer here | ||
NodeRecordSigner nodeRecordSigner = new(ethereumEcdsa, new PrivateKeyGenerator().Generate()); | ||
EnrRecordParser enrRecordParser = new(nodeRecordSigner); | ||
return new EnrDiscovery(enrRecordParser, networkConfig, logManager); // initialize with a proper network | ||
}) | ||
|
||
// Uses by RPC also. | ||
.AddSingleton<IStaticNodesManager, ILogManager>((logManager) => new StaticNodesManager(initConfig.StaticNodesPath, logManager)) | ||
// This load from file. | ||
.AddSingleton<NodesLoader>() | ||
|
||
.Bind<INodeSource, IStaticNodesManager>() | ||
.Bind<INodeSource, NodesLoader>() | ||
.AddComposite<INodeSource, CompositeNodeSource>() | ||
|
||
// The actual thing that uses the INodeSource(s) | ||
.AddSingleton<IPeerPool, PeerPool>() | ||
.AddSingleton<IPeerManager, PeerManager>() | ||
|
||
// Some config migration | ||
.AddDecorator<INetworkConfig>((ctx, networkConfig) => | ||
{ | ||
ChainSpec chainSpec = ctx.Resolve<ChainSpec>(); | ||
IDiscoveryConfig discoveryConfig = ctx.Resolve<IDiscoveryConfig>(); | ||
|
||
// Was in `UpdateDiscoveryConfig` step. | ||
if (discoveryConfig.Bootnodes != string.Empty) | ||
{ | ||
if (chainSpec.Bootnodes.Length != 0) | ||
{ | ||
discoveryConfig.Bootnodes += "," + string.Join(",", chainSpec.Bootnodes.Select(static bn => bn.ToString())); | ||
} | ||
} | ||
else if (chainSpec.Bootnodes is not null) | ||
{ | ||
discoveryConfig.Bootnodes = string.Join(",", chainSpec.Bootnodes.Select(static bn => bn.ToString())); | ||
} | ||
|
||
if (networkConfig.DiscoveryDns == null) | ||
{ | ||
string chainName = BlockchainIds.GetBlockchainName(chainSpec!.NetworkId).ToLowerInvariant(); | ||
networkConfig.DiscoveryDns = $"all.{chainName}.ethdisco.net"; | ||
} | ||
networkConfig.Bootnodes = discoveryConfig.Bootnodes; | ||
return networkConfig; | ||
}) | ||
; | ||
|
||
|
||
// Discovery app | ||
// Needed regardless if used or not because of StopAsync in runner. | ||
// The DiscV4/5 is in CompositeDiscoveryApp. | ||
if (!initConfig.DiscoveryEnabled) | ||
builder.AddSingleton<IDiscoveryApp, NullDiscoveryApp>(); | ||
else | ||
builder.AddSingleton<IDiscoveryApp, CompositeDiscoveryApp>(); | ||
|
||
if (!networkConfig.OnlyStaticPeers) | ||
{ | ||
// These are INodeSource only if `OnlyStaticPeers` is false. | ||
builder | ||
.Bind<INodeSource, IDiscoveryApp>() | ||
.Bind<INodeSource, EnrDiscovery>(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Nethermind/Nethermind.Core.Test/Modules/FixedIpResolver.cs
This file contains 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,19 @@ | ||
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Nethermind.Network; | ||
using Nethermind.Network.Config; | ||
|
||
namespace Nethermind.Core.Test.Modules; | ||
|
||
public class FixedIpResolver(INetworkConfig networkConfig) : IIPResolver | ||
{ | ||
public IPAddress LocalIp => IPAddress.Parse(networkConfig.LocalIp!); | ||
public IPAddress ExternalIp => IPAddress.Parse(networkConfig.ExternalIp!); | ||
public Task Initialize() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Nethermind/Nethermind.Core.Test/Modules/InsecureProtectedPrivateKey.cs
This file contains 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,17 @@ | ||
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Crypto; | ||
using Nethermind.Crypto; | ||
|
||
namespace Nethermind.Core.Test.Modules; | ||
|
||
public class InsecureProtectedPrivateKey(PrivateKey privateKey) : IProtectedPrivateKey | ||
{ | ||
public PublicKey PublicKey => privateKey.PublicKey; | ||
public CompressedPublicKey CompressedPublicKey => privateKey.CompressedPublicKey; | ||
public PrivateKey Unprotect() | ||
{ | ||
return privateKey; | ||
} | ||
} |
This file contains 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.