Skip to content

Implement admin_peerEvents for rpc module#7999

Merged
damian-orzechowski merged 29 commits intomasterfrom
7816_implement_admin_peerevents_for_rpc_module
Feb 11, 2025
Merged

Implement admin_peerEvents for rpc module#7999
damian-orzechowski merged 29 commits intomasterfrom
7816_implement_admin_peerevents_for_rpc_module

Conversation

@StevenChongHuo
Copy link
Copy Markdown
Contributor

These changes allow real time pub-sub through websocket on peer-related events (peerEvents), specifically, peerAdded and peerRemoved events. Once a client subscribes for peerEvents, A JSON-RPC notification with event payload and subscription id is sent to this client for every event matching the subscription topic (peerAdded or peerRemoved).

Users subscribe to peerEvents by sending a request as such:
{"jsonrpc": "2.0", "id": 1, "method": "admin_subscribe", "params": ["peerEvents"]}

Resolves #7816

Changes

  • Adds a new subscription type peerEvents.
  • Implements logic to create corresponding JsonRpc response.
  • Subscribes to IPeerPool.peerAdded and IPeerPool.peerRemoved events when requested.
  • Allows a differentiation between eth_subscribe and admin_subscribe in JsonRpcSubscriptionResponse class.

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

@StevenChongHuo StevenChongHuo self-assigned this Jan 3, 2025
Copy link
Copy Markdown
Member

@LukaszRozmej LukaszRozmej left a 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.

Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/ISubscribeRpcModule.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/AdminSubscriptionType.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerAddDropResponse.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerAddDropResponse.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/NewHeadSubscription.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/peerEventsSubscription.cs Outdated
Copy link
Copy Markdown
Member

@LukaszRozmej LukaszRozmej left a 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?

Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/SubscriptionFactory.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/SubscriptionFactory.cs Outdated
@StevenChongHuo StevenChongHuo force-pushed the 7816_implement_admin_peerevents_for_rpc_module branch from a433375 to 2c1ea99 Compare January 30, 2025 16:41
@StevenChongHuo StevenChongHuo marked this pull request as draft January 30, 2025 16:41
@StevenChongHuo StevenChongHuo marked this pull request as ready for review February 9, 2025 14:46
Copy link
Copy Markdown
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't update submodules!
src/bench_precompiles
src/tests

Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/peerEventsSubscription.cs Outdated
Comment thread src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs Outdated
Comment thread src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs Outdated
Comment thread src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerAddDropResponse.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerMsgSendRecvResponse.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs
@StevenChongHuo StevenChongHuo force-pushed the 7816_implement_admin_peerevents_for_rpc_module branch from a840b0d to db42c6a Compare February 10, 2025 14:00
Comment on lines +111 to +114
[JsonRpcMethod(Description = "Starts a subscription (on WebSockets/Sockets) to a particular event. For every event that matches the subscription a JSON-RPC notification with event details and subscription ID will be sent to a client.", IsImplemented = true, IsSharable = false, Availability = RpcEndpoint.All & ~RpcEndpoint.Http)]
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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubo can you check?

Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerAddDropResponse.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Admin/IAdminRpcModule.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/peerEventsSubscription.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerMsgSendRecvResponse.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerEventResponse.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Subscribe/PeerAddDropResponse.cs Outdated
LukaszRozmej and others added 7 commits February 11, 2025 14:58
…Subscription.cs

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
…e.cs

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
…dRecvResponse.cs

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
…esponse.cs

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
…pResponse.cs

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
@damian-orzechowski damian-orzechowski merged commit 10312b6 into master Feb 11, 2025
@damian-orzechowski damian-orzechowski deleted the 7816_implement_admin_peerevents_for_rpc_module branch February 11, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement admin_peerEvents for rpc module

4 participants