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

Enable plugins to expose custom JSON RPC / GraphQL / WebSocket methods #1317

Closed
aldoborrero opened this issue Aug 17, 2020 · 1 comment · Fixed by #2754
Closed

Enable plugins to expose custom JSON RPC / GraphQL / WebSocket methods #1317

aldoborrero opened this issue Aug 17, 2020 · 1 comment · Fixed by #2754
Assignees
Labels

Comments

@aldoborrero
Copy link

Description

As a plugin writer, I would like to have the possibility of exposing custom JSON RPC / GraphQL / WebSocket methods (I'll focus only on JSON RPC for the rest of the issue but it should apply to all of those).

Currently, the plugin API is limited by how we can interact with the outside world. Having the possibility of custom JSON RPC commands is immensely useful when you want to extend the capabilities of Besu beyond the default set of exposed methods.

In terms of the API, we can add the following to BesuPlugin interface:

...

/** Called when the plugin wants to expose custom JSON RPC methods.
* If not overridden, this method does nothing for convenience.
**/
default Map<String, JsonRpcMethod> createJsonRpcMethods() {
    return Collections.emptyMap();
}

This method would be called once at the Registering phase. The format for each method name could be the following:

<plugin-name-id>_<api-method>

Like this:

plugin-besu-exflo_retrieveTokenBalances

Each plugin is responsible of generating a custom response that can be serialized by Jackson.

We can reuse part of the work that has been done already in the class PluginsJsonRpcMethods. That class receives the list of Plugins, so apart of registering the reload configuration, we can iterate for each plugin and see if they have defined a map of JsonRpcMethods.

Currently, neither of JsonRpcMethod, JsonRpcMethods, JsonRpcRequestContext... are exposed to plugin-api module. So a worthwhile discussion would be what is the best approach to expose those relevant entities to plugins.

Also, probably, I might be forgetting anything that could be crucial to take into account before any attempt of implementation.

Acceptance Criteria

  • It should not override existing JSON RPC commands (throw an error if the id of the method is one of the native ones).
  • It should expose custom JSON RPC methods.
  • It should expose custom GraphQL mutations/queries.
  • It should allow custom WebSocket subscriptions/methods.

Maybe we can start with just only supporting JSON RPC and later on adding support to GraphQL and WebSockets.

Additional Information

Quorum has implemented a similar feature already.

If an approach is agreed upon, I would be happy to implement it.

@antonydenyer
Copy link
Member

Reference to previous discussions about design and prototype:

https://github.com/PegaSysEng/pantheon/pull/1909/files

https://wiki.hyperledger.org/display/BESU/RPC+Endpoint+Service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants