-
Notifications
You must be signed in to change notification settings - Fork 478
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/end to end discovery test #8098
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4a0f76f
Can run, but fail to pass
asdacap 9556cc7
Cleanup
asdacap 61900dc
Disable discv5
asdacap 85cbca2
Rlpx shutdown timeout
asdacap bc58662
Use chainspec bootnodes
asdacap 3fadf08
Whitespace
asdacap d4cb527
Fix test
asdacap 2440b3b
Mistake in config order
asdacap 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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotProtetedPriveteKey :D