-
Notifications
You must be signed in to change notification settings - Fork 487
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
Implement admin_addTrustedPeer rpc endpoint #7891
Implement admin_addTrustedPeer rpc endpoint #7891
Conversation
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.
Very good starting point. I do have some questions and comments before we finalize it.
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
ae99897
to
6423863
Compare
Merge conflicts fixed 🙂 |
A gentle reminder @LukaszRozmej. If there are no more notes, I can resolve the conflict, and it should be ready to be merged |
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.
Sorry, missed it, still few things to polish
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
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.
Few more details, but really close!
src/Nethermind/Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Network/TrustedNodes/TrustedNodesManager.cs
Outdated
Show resolved
Hide resolved
7aaf7b1
to
fe2ed13
Compare
public NetworkNode(Enode enode) | ||
{ | ||
_enode = enode; | ||
} |
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.
Can you put constructor next to the other?
Should we have admin_removeTrustedPeer? Not necessary in this pr. |
@@ -23,6 +24,7 @@ public class TrustedNodesManager : ITrustedNodesManager | |||
private ConcurrentDictionary<PublicKey, NetworkNode> _nodes = new(); | |||
private readonly string _trustedNodesPath; | |||
private readonly ILogger _logger; | |||
private readonly Channel<Node> _nodeChannel = Channel.CreateUnbounded<Node>(); |
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.
I think we need bounded channel, otherwise potential spam could take down the node? 2^16 limit looks ok to me.
6755983
to
b1515f9
Compare
b1515f9
to
7b7650c
Compare
some tests are failing |
} | ||
|
||
// continuously yield new nodes as they are added via the channel. | ||
while (await _nodeChannel.Reader.WaitToReadAsync(cancellationToken)) |
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.
Instead of doing two while
s, could you just _nodeChannel.Reader.ReadAllAsync
in one await foreach
Hi, @LukaszRozmej, could you please give me pointers on tackling the failing tests? 😅 |
That one is definitely about incorrect setup in test.
This is similar, probably need some changes on the autofac module (dependency injection). |
Also please update to newest master and resolve conflicts |
6fdca67
to
251c554
Compare
Caused regression, that was fixed in #8211 |
I'm a little sad that my implementation wasn't impeccable. I am glad the error was quickly caught and fixed. I'll learn from it 🙏 |
Fixes #7811
Changes
Added ITrustedNodesManager Interface:
Created a new ITrustedNodesManager interface to handle trusted nodes. This interface is similar to IStaticNodesManager but for trusted nodes. It provides methods InitAsync(), AddAsync(), RemoveAsync(), IsTrusted(), and exposes Nodes.
Implemented TrustedNodesManager Class:
Implemented TrustedNodesManager, which reads/writes a trusted nodes file and manages a list of trusted nodes. It also implements INodeSource (or inherits from ITrustedNodesManager : INodeSource) so it can be used by CompositeNodeSource.
Added IsTrusted Property to Node:
Modified the Node class used by the networking code to include a public bool IsTrusted { get; set; } property. This allows peers to reflect if they originate from trusted nodes.
Integrated TrustedNodesManager into PeerPool:
Passed an ITrustedNodesManager instance into the PeerPool constructor and updated the peer creation logic (CreateNew methods) to mark nodes as trusted if they come from the trusted nodes manager.
Updated InitializeNetwork to Include TrustedNodesManager:
Created and initialized TrustedNodesManager inside InitializeNetwork.cs, added it to CompositeNodeSource so that trusted nodes are considered in the node discovery pipeline, and passed it to PeerPool.
Updated IApiWithNetwork and IInitConfig:
Extended IApiWithNetwork interface to have a ITrustedNodesManager? TrustedNodesManager { get; set; } property (if needed).
Added a TrustedNodesPath property to IInitConfig and InitConfig to define the file path for trusted nodes.
Modified AdminRpcModule Constructor:
Updated the AdminRpcModule constructor to require an ITrustedNodesManager and implemented the admin_addTrustedPeer method using the trusted nodes manager and peer pool.
Adjusted existing tests to provide an ITrustedNodesManager mock where needed. Added a new test (Test_admin_addTrustedPeer) to ensure admin_addTrustedPeer works correctly.
Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Documentation
Requires documentation update
If yes, link the PR to the docs update or the issue with the details labeled
docs
. Remove if not applicable.Requires explanation in Release Notes
If yes, fill in the details here. Remove if not applicable.
Remarks
Optional. Remove if not applicable.