Skip to content
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

In process RPC service #7395

Merged
merged 1 commit into from
Jul 31, 2024
Merged

Conversation

fab-10
Copy link
Contributor

@fab-10 fab-10 commented Jul 29, 2024

PR description

Expose a way to call RPC method in process, so they can be invoked by plugins without the overhead of the network (or native socket) and the json (de)serialization.

The interface is still fragile, because RPC method inputs and outputs are not typed, but just Object, so a next step will be to make them typed so plugins will discover at compile time that something is broken, but that will be address in another PR.

Do not be scared by the amount of file changed since many are due to the move of some classes in the plugin-api module.

This feature is disabled by default and can be enabled setting the new experimental flag Xin-process-rpc-enabled=true, and to enabled specific RPC namespaces use the new experimental option Xin-process-rpc-apis with a comma separated list of namespaces.

Fixed Issue(s)

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

@fab-10 fab-10 force-pushed the in-process-rpc-service-pre2 branch from 1c24c62 to 1c8b066 Compare July 30, 2024 09:47
@fab-10 fab-10 mentioned this pull request Jul 30, 2024
8 tasks
@fab-10 fab-10 marked this pull request as ready for review July 30, 2024 09:55
@fab-10 fab-10 self-assigned this Jul 30, 2024
Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

LGTM. Minor comments and suggestions which could be done in follow up PRs if you decide.

Appreciate the good PR description, test coverage and the way you've broken up the PR 👍

Great feature BTW, could be some interesting possibilities using this with the engine API.

@@ -108,6 +112,7 @@ public class Runner implements AutoCloseable {
final Optional<GraphQLHttpService> graphQLHttp,
final Optional<WebSocketService> webSocketRpc,
final Optional<JsonRpcIpcService> ipcJsonRpc,
final Map<String, JsonRpcMethod> inProcessRpcMethods,
Copy link
Contributor

@siladu siladu Jul 31, 2024

Choose a reason for hiding this comment

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

Comparing to JsonRpcHttpService, I think in-process is missing metrics, e.g. requestTimer.

Wonder If it's still useful to have separate metrics for these in-process RPC calls?

Also missing the opentelemetry tracing stuff, but not sure that if it makes sense to split the span in-process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good points, I think it is useful to have metrics, will review this in a separate PR

import java.util.function.Function;
import java.util.stream.Collectors;

/** The RPC endpoint service implementation. */
public class RpcEndpointServiceImpl implements RpcEndpointService {
private final Map<String, Function<PluginRpcRequest, ?>> rpcMethods = new HashMap<>();
private Map<String, JsonRpcMethod> inProcessRpcMethods;
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 compatible with RPCs added via plugins as well, as per #2754?

I'm not 100% sure if this scenario makes sense, but perhaps we'd want to call a plugin's RPC method via another plugin, i.e.

  • plugin1 registers rpc1 with besu
  • plugin2 calls rpc1 in-process

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This a quick test, and found that it is possible to call a method defined in another plugin, but only if the plugin namespace is enabled via rpc-http-api, that's not optimal, since should be enough to enable it only using Xin-process-rpc-apis, will improve that on a following PR with proper tests

@@ -48,6 +65,37 @@ public <T> void registerRPCEndpoint(
rpcMethods.put(namespace + "_" + functionName, function);
}

@Override
public PluginRpcResponse call(final String methodName, final Object[] params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we LOG.trace the methodName and params here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@fab-10 fab-10 force-pushed the in-process-rpc-service-pre2 branch from 1c8b066 to 26ba456 Compare July 31, 2024 08:48
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
@fab-10 fab-10 force-pushed the in-process-rpc-service-pre2 branch from 26ba456 to c9c0b39 Compare July 31, 2024 15:50
@fab-10 fab-10 enabled auto-merge (squash) July 31, 2024 15:50
@fab-10 fab-10 merged commit a7ab177 into hyperledger:main Jul 31, 2024
40 checks passed
gconnect pushed a commit to gconnect/besu that referenced this pull request Aug 26, 2024
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: gconnect <agatevureglory@gmail.com>
@fab-10 fab-10 deleted the in-process-rpc-service-pre2 branch November 8, 2024 16:36
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.

2 participants