Skip to content

Conversation

@MqllR
Copy link
Contributor

@MqllR MqllR commented Nov 27, 2025

Add eth_subscribe and eth_unsubscribe support to IPC service

Description

This PR adds subscription support (eth_subscribe and eth_unsubscribe) to the IPC service, enabling applications to subscribe to blockchain events over Unix domain sockets without requiring WebSocket connections.

Motivation

Currently, subscription methods are only available through the WebSocket service. Applications using IPC sockets cannot subscribe to events like new block headers, logs, pending transactions, or syncing status. This limitation forces applications to maintain both IPC and WebSocket connections when they prefer IPC for security and performance reasons.

Changes

Core Implementation

JsonRpcIpcService.java:

  • Added optional SubscriptionManager parameter (backward compatible)
  • Generate unique connection IDs for each IPC socket connection
  • Register Vert.x event bus consumers to receive subscription notifications
  • Convert JsonRpcRequest to WebSocketRpcRequest with connection ID for single requests
  • Send subscription notifications back through the IPC socket
  • Clean up subscriptions when socket closes
  • Note: Batch requests intentionally don't support subscriptions (they remain stateless)

RunnerBuilder.java:

  • Centralized subscription service registration for both WebSocket and IPC
  • Add subscription methods (eth_subscribe, eth_unsubscribe) to IPC using WebSocketMethodsFactory
  • Pass SubscriptionManager to IPC service when enabled
  • Added null check for jsonRpcIpcConfiguration

Testing

JsonRpcIpcServiceTest.java:

  • Added test for successful eth_subscribe requests
  • Added test for successful eth_unsubscribe requests
  • Added test verifying batch requests don't support subscriptions
  • All existing tests continue to pass

Usage Example

# Subscribe to new block headers
echo '{"jsonrpc":"2.0","method":"eth_subscribe","params":["newHeads"],"id":1}' | nc -U /path/to/besu.ipc
# Response: {"jsonrpc":"2.0","id":1,"result":"0x1"}

# Notifications will be sent automatically:
# {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x1","result":{...}}}

# Unsubscribe
echo '{"jsonrpc":"2.0","method":"eth_unsubscribe","params":["0x1"],"id":2}' | nc -U /path/to/besu.ipc
# Response: {"jsonrpc":"2.0","id":2,"result":true}

Benefits

  • ✅ Applications using IPC can subscribe to blockchain events
  • ✅ Maintains consistency between IPC and WebSocket APIs
  • ✅ No breaking changes to existing functionality
  • ✅ Backward compatible (optional parameter)
  • ✅ Reuses existing subscription infrastructure

Testing

  • All unit tests pass
  • Added comprehensive tests for IPC subscription functionality
  • Verified backward compatibility with existing IPC tests

Related Issues

Closes #9503

Copilot AI review requested due to automatic review settings November 27, 2025 13:05
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

@MqllR Thanks for the PR - can you add a changelog entry please, think this is worth including in the release notes

besuController.getProtocolManager().ethContext().getScheduler());

final WebSocketMethodsFactory ipcMethodsFactory =
new WebSocketMethodsFactory(subscriptionManager, ipcMethods);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this change necessary?

Copy link
Contributor Author

@MqllR MqllR Dec 1, 2025

Choose a reason for hiding this comment

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

Tried without, but it turns out that this is what:

So unless we want to manage it in another way, I'd answer yes, it's necessary !

Copy link
Contributor

Choose a reason for hiding this comment

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

tagging this as #techdebt for later investigation, you've found a code smell: reactive methods are bound to a transport type, which is excessive coupling.

@macfarla macfarla added the doc-change-required Indicates an issue or PR that requires doc to be updated label Dec 1, 2025
@MqllR MqllR force-pushed the feat/ipc-subscription-support branch from 56846d5 to 2cb9523 Compare December 1, 2025 09:05
Signed-off-by: Mael Regnery <mael@mqli.fr>
@MqllR MqllR force-pushed the feat/ipc-subscription-support branch from 3ee2f96 to bf58fa7 Compare December 1, 2025 09:09
@MqllR MqllR requested a review from macfarla December 1, 2025 14:42
@macfarla macfarla self-assigned this Dec 2, 2025
@macfarla macfarla merged commit 8f92c6a into hyperledger:main Dec 2, 2025
46 checks passed
@jflo jflo added the techdebt maintenance, cleanup, refactoring, documentation label Dec 2, 2025
AliZDev-v0 pushed a commit to AliZDev-v0/besu that referenced this pull request Dec 10, 2025
…yperledger#9504)

* feat: Add eth_subscribe and eth_unsubscribe support to IPC service

Signed-off-by: Mael Regnery <mael@mqli.fr>

* add changelog note for subscription over IPC

Signed-off-by: Mael Regnery <mael@mqli.fr>

---------

Signed-off-by: Mael Regnery <mael@mqli.fr>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Ali Zhagparov <alijakparov.kz@gmail.com>
pinges pushed a commit to pinges/besu that referenced this pull request Dec 15, 2025
…yperledger#9504)

* feat: Add eth_subscribe and eth_unsubscribe support to IPC service

Signed-off-by: Mael Regnery <mael@mqli.fr>

* add changelog note for subscription over IPC

Signed-off-by: Mael Regnery <mael@mqli.fr>

---------

Signed-off-by: Mael Regnery <mael@mqli.fr>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-change-required Indicates an issue or PR that requires doc to be updated techdebt maintenance, cleanup, refactoring, documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add eth_subscribe and eth_unsubscribe support to IPC service

3 participants