Implement admin_addTrustedPeer rpc endpoint #7891
Open
+316
−9
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.
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.