-
Notifications
You must be signed in to change notification settings - Fork 473
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_peerEvents for rpc module #7999
base: master
Are you sure you want to change the base?
Implement admin_peerEvents for rpc module #7999
Conversation
Allow real time pub-sub through websocket on peer_added and peer_removed events.
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.
Potentially we also need msgsend
and msgrecv
subscriptions, but they will be a bit harder to add as I believe we don't expose events yet.
ResultWrapper<string> admin_subscribe(string subscriptionName, string? args = null); | ||
[JsonRpcMethod(Description = "Unsubscribes from a subscription.", IsImplemented = true, IsSharable = false, Availability = RpcEndpoint.All & ~RpcEndpoint.Http)] | ||
ResultWrapper<bool> admin_unsubscribe(string subscriptionId); |
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 those methods need to be moved to AdminModule
as we need to guarantee that they are available only when admin module is enabled? Or we can try adding that logic explicitly for subscriptions in RpcModuleProvider
?
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.
Thank you for your comments! I am still looking into msgsend
and msgrecv
subscriptions. For now, these commits only deals with subscriptions to peerAdded
and peerRemoved
events.
I have moved the admin_subscribe
and admin_unsubscribe
methods to AdminRpcModule
in the most recent commits. Previously, these methods are available when the Subscribe
module is enabled; now they are only available when the Admin
module is enabled.
src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/AdminSubscriptionType.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/DroppedPendingTransactionsSubscription.cs
Outdated
Show resolved
Hide resolved
[JsonPropertyName("type")] | ||
public string Type { get; set; } | ||
|
||
[JsonPropertyName("peer")] | ||
public string PeerId { get; set; } | ||
|
||
[JsonPropertyName("local")] | ||
public string LocalAddr { get; set; } | ||
|
||
[JsonPropertyName("remote")] | ||
public string RemoteAddr { get; set; } | ||
|
||
[JsonPropertyName("error")] | ||
public string? Err { get; set; } |
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.
Imo name properties as they should be in response and you can drop JsonPropertyName
attributes. Casing will be handled by default.
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.
Could you please explain the benefits of this? I haven't changed these codes for this reason: I think the content of a variable is clearer when the variable name is more explicit, e.g. LocalAddr
is less ambiguous than local
.
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.
simplicity
src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerAddDropResponse.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/NewHeadSubscription.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/peerEventsSubscription.cs
Outdated
Show resolved
Hide resolved
+ Move admin_subscribe and admin_unsubsribe methods into the AdminRpcModule. + Move relevant tests to AdminModuleTest + Deal with other comments in PR review.
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.
Almost done - what do you think about moving subscription registrations from SubscriptionManager
to be close to actual modules themselves?
@@ -38,7 +40,8 @@ public SubscriptionFactory(ILogManager? logManager, | |||
IFilterStore? filterStore, | |||
IEthSyncingInfo ethSyncingInfo, | |||
ISpecProvider specProvider, | |||
IJsonSerializer jsonSerializer) | |||
IJsonSerializer jsonSerializer, | |||
IPeerPool peerPool) |
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.
Maybe instead of passing IPeerPool
here and other specialized types from different modules, we should register subscriptions from the outside of this class?
[SubscriptionType.AdminSubscription.PeerEvents] = CreateSubscriptionType((jsonRpcDuplexClient) => | ||
new PeerEventsSubscription(jsonRpcDuplexClient, logManager, _peerPool)), |
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 mean this kind of registrations could be done when setting up AdminModule
and previous ones when setting up SubscribeModule
. Would make this class bit simpler to construct and use. We could use extension methods for those registrations.
These changes allow real time pub-sub through websocket on peer-related events (
peerEvents
), specifically,peerAdded
andpeerRemoved
events. Once a client subscribes forpeerEvents
, A JSON-RPC notification with event payload and subscription id is sent to this client for every event matching the subscription topic (peerAdded
orpeerRemoved
).Users subscribe to peerEvents by sending a request as such:
{"jsonrpc": "2.0", "id": 1, "method": "admin_subscribe", "params": ["peerEvents"]}
Resolves #7816
Changes
peerEvents
.IPeerPool.peerAdded
andIPeerPool.peerRemoved
events when requested.eth_subscribe
andadmin_subscribe
inJsonRpcSubscriptionResponse
class.Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?